Currently my dhcp-log displays my Raspberry Pi with the name xbmc-e0cb
. Can I change this to a more sensible name?
Asked
Active
Viewed 1.1k times
10

Peter Mortensen
- 2,004
- 2
- 15
- 18

towi
- 535
- 2
- 5
- 8
4 Answers
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
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"
-
This doesn't tally with my file. I have
uuid = params['nm.uuid']
at the start ofdef 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
-
Nonetheless, thank you for completing the picture and not requiring a reboot. Useful tip way beyond just raspbmc. – Fergal Moran Sep 21 '13 at 22:48
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
-
1I may have posted too soon... this seems to leave
/etc/hosts
in a dismal state – patricktokeeffe Dec 15 '16 at 04:40
Can't open file to write
. How can I fix this? – xxmbabanexx Mar 25 '13 at 18:22sudo
in front of your edit-command. – René Wolferink Mar 26 '13 at 08:53sudo: unable to resolve host
and the new name, before it runs the command. – Patrick Apr 19 '14 at 23:29hostname
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/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:17sudo /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