Bramley
Posts: 15
Joined: Wed Oct 02, 2013 10:08 am

How to change Hostname

Thu Oct 17, 2013 8:25 am

This is a very naive question.

I have just bought a second RPi, and I want to be able to communicate with both RPis in a home network via internet, using ssh and VNC on my Mac. When I run <hostname -I> on both Pi's I find that (by Murphy's law) they have the same hostname, so when I go from one RPi to the other (only one running at once) I have to delete the Mac's .ssh/known_hosts file.

Can anyone tell me the safest way to resolve this problem?

Many thanks!

User avatar
joan
Posts: 14999
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to change Hostname

Thu Oct 17, 2013 8:27 am

sudo vi /etc/hostname
sudo vi /etc/hosts

Changing the name in those two places should be sufficient.

Bramley
Posts: 15
Joined: Wed Oct 02, 2013 10:08 am

Re: How to change Hostname

Thu Oct 17, 2013 8:58 am

Thank you both for your kind and prompt replies, which are very helpful.
It's interesting to observe that there seem to be at least 2 ways of doing everything on the RPi (and a lot of ways of doing the wrong thing, which I seem to be discovering all on my own.)
Best wishes.

User avatar
RaTTuS
Posts: 10565
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: How to change Hostname

Thu Oct 17, 2013 9:01 am

in linux there are many way to skin a cat -
sometimes even skin a lion
there is not necessary a best way
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: How to change Hostname

Thu Oct 17, 2013 9:25 am

Bramley wrote:...
It's interesting to observe that there seem to be at least 2 ways of doing everything on the RPi (and a lot of ways of doing the wrong thing, which I seem to be discovering all on my own.)...
raspi-config is the lion-tamer for the /etc/hosts and /etc/hostname lion. raspi-config is easier and safer to play with, and it then it does the riskier bit for you under the covers.

In other words, it's hard to get it wrong with raspi-config, whereas a typo in editing hostname / hosts could lead to all sorts of odd behaviour.

Editing hosts / hostname directly needs a reboot for it to take effect. raspi-config may not as it might stop and restart the drivers instead (pure speculation though)
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

User avatar
joan
Posts: 14999
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to change Hostname

Thu Oct 17, 2013 9:35 am

raspi-config may be useful for Raspbian.

Changes to /etc/hosts take place immediately.

I don't know if that applies to /etc/hostname as well.

uherm
Posts: 11
Joined: Fri Jun 14, 2013 9:53 am

Re: How to change Hostname

Thu Oct 17, 2013 11:52 am

I did it using this checklist:

https://wiki.debian.org/HowTo/ChangeHostname

/etc/hostname isn't enough.
You might change at least also parts of your ssh keys.

regards

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: How to change Hostname

Thu Oct 17, 2013 6:31 pm

joan wrote:raspi-config may be useful for Raspbian.

Changes to /etc/hosts take place immediately.

I don't know if that applies to /etc/hostname as well.
Oops, I stand corrected :oops:
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

Return to “Troubleshooting”