10

Currently my dhcp-log displays my Raspberry Pi with the name xbmc-e0cb. Can I change this to a more sensible name?

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
towi
  • 535
  • 2
  • 5
  • 8

4 Answers4

11

Update the host name in the following files

/etc/hostname
/etc/hosts

Change the name, and it will change on network-restart (or full reboot, of course).

Updating /etc/hosts is necessary to avoid the following error

sudo: unable to resolve host <new-hostname>
Praetorian
  • 103
  • 4
René Wolferink
  • 273
  • 3
  • 10
  • 2
    Thanks. I found out that my dhcp would need to be reconfigured if I wanted the Pi also be getting this as a name in my net. – towi Dec 10 '12 at 10:58
  • When I changed the file's contents, and attempted to overwrite the file, I was told that the Pi Can't open file to write. How can I fix this? – xxmbabanexx Mar 25 '13 at 18:22
  • Did you edit it as root or as normal user? Try putting sudo in front of your edit-command. – René Wolferink Mar 26 '13 at 08:53
  • I did that, and now every time I use sudo it says sudo: unable to resolve host and the new name, before it runs the command. – Patrick Apr 19 '14 at 23:29
  • 2
    Ah, found it. Needed to update /etc/hosts as well. – Patrick Apr 19 '14 at 23:36
  • The contents of my hostname file isn't appearing on the network. But I just fixed my ip as per these instructions, which is probably why. Any advice? – geotheory Sep 06 '14 at 12:32
  • 1
    No matter what I do, my hostname won't change:

    /etc/hostname = raspbmc /etc/hosts = 127.0.0.1 raspbmc $ hostname raspbmc

    But my router still picks it up as xbmc-7164. Any ideas?

    – andersonvom Oct 04 '14 at 22:17
  • Many sources also point to run sudo /etc/init.d/hostname.sh , e.g. https://www.howtogeek.com/167195/how-to-change-your-raspberry-pi-or-other-linux-devices-hostname/ or https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=125373 – Grzegorz Wierzowiecki Aug 27 '17 at 11:23
3

I did this, adapted from http://forum.stmlabs.com/showthread.php?tid=7180

sudo nano /scripts/nm_util.py

Almost at the bottom of the file, uid is set. Comment out all of the if clause, and change it to

uid = "MyHostname"
DJJo14
  • 31
  • 1
  • This doesn't tally with my file. I have uuid = params['nm.uuid'] at the start of def deactivate_connection. Is that what you refer to? – geotheory Sep 06 '14 at 12:29
  • 1
    @geotheory: he refers to the lines near "uid = "xbmc-"+mac_list[4].lower()+mac_list[5].lower()", but it is a confusing answer (for instance, "almost at the bottom of the file" is actually only 80% down in the file). – Peter Mortensen Jan 04 '15 at 16:33
2

Additionally you can change the hostname on the fly by issuing the commang sysctl kernel.hostname=NEW_HOSTNAME. But that is no permanent solution. @René Wolferink already posted the only permanent way.

hth

ortang
  • 496
  • 3
  • 5
1

With the introduction of systemd (Raspbian Jessie and newer), the prescribed method is finally a single command (reference):

sudo hostnamectl set-hostname <mymachine>

Changes take effect immediately and persist after reboot.

patricktokeeffe
  • 547
  • 2
  • 5
  • 11