chleo
Posts: 21
Joined: Wed Jun 04, 2014 3:05 am

failed to change RPi hostname

Wed Jan 27, 2016 2:52 pm

Hi,

when i try to change the host name of a new RPi, i meet a strange issue, can anyone help me on this?
this happens on new RPi which installed the latest NOOBS (ver:1.5.0), for my old one, no such issue:

1. sudo nano /etc/hostname

Code: Select all

rpi_new_name
2. sudo nano /etc/hosts

Code: Select all

...
127.0.1.1 rpi_new_name
3. sudo reboot

after rebooting, i see the prompt is changed to
,
but above two config files have been changed back, that means my modifications are lost.
then, i noticed RPi will automatically reboot and back to
.

thanks in advance,
Leo

klricks
Posts: 6624
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: failed to change RPi hostname

Wed Jan 27, 2016 3:05 pm

Your hostname is not valid. It can't have _ or any other punctuation except for a '-'
raspi-confg does warn you about that but will not stop you from entering an invalid hostnarme.
When you have entered an invalid hostname and then attempt to change it, then raspi-config gets confused and does not parse correctly.
You will need to edit the 2 hostfiles and manually put in a valid hostname to fix it
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

asandford
Posts: 1997
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: failed to change RPi hostname

Wed Jan 27, 2016 11:04 pm

To change the hostname involves more than just editing that file.

To change the hostaname properly use

Code: Select all

sudo raspi-config
select option 8 (advanced options), then option A2 hostname.

chleo
Posts: 21
Joined: Wed Jun 04, 2014 3:05 am

Re: failed to change RPi hostname

Thu Jan 28, 2016 5:16 am

thanks for all replies.
i know it is convenient to use

Code: Select all

sudo raspi-config
, but i am looking for another solution so that i can use python script automatically config RPi's name...

chleo
Posts: 21
Joined: Wed Jun 04, 2014 3:05 am

Re: failed to change RPi hostname

Thu Jan 28, 2016 5:20 am

klricks wrote:Your hostname is not valid. It can't have _ or any other punctuation except for a '-'
raspi-confg does warn you about that but will not stop you from entering an invalid hostnarme.
When you have entered an invalid hostname and then attempt to change it, then raspi-config gets confused and does not parse correctly.
You will need to edit the 2 hostfiles and manually put in a valid hostname to fix it
sorry for misunderstanding, here i use "rpi_old_name" just for an example.

chleo
Posts: 21
Joined: Wed Jun 04, 2014 3:05 am

Re: failed to change RPi hostname

Thu Jan 28, 2016 5:49 am

asandford wrote:To change the hostname involves more than just editing that file.

To change the hostaname properly use

Code: Select all

sudo raspi-config
select option 8 (advanced options), then option A2 hostname.
and i have to say i find this issue too when using

Code: Select all

sudo raspi-config
to change the host name.

klricks
Posts: 6624
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: failed to change RPi hostname

Thu Jan 28, 2016 6:37 am

chleo wrote:...
and i have to say i find this issue too when using

Code: Select all

sudo raspi-config
to change the host name.
I am running Raspbian Jessie (not installed with NOOBS)
I just changed my hostname manually by editing /etc/hosts and /etc/hostname and I also tried sudo raspi-config and did not have any problem changing the hostname with either method.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

User avatar
rpdom
Posts: 15601
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: failed to change RPi hostname

Thu Jan 28, 2016 6:54 am

You should be able to change the name, either by editing those files, or by using raspi-config. I did it yesterday on a new Raspbian Jessie install.

Are you using a standard Raspbian setup (perhaps from NOOBS), or something else?

chleo
Posts: 21
Joined: Wed Jun 04, 2014 3:05 am

Re: failed to change RPi hostname

Thu Jan 28, 2016 7:44 am

:( this new RPi uses the latest NOOBS (ver:1.5.0)

User avatar
rpdom
Posts: 15601
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: failed to change RPi hostname

Thu Jan 28, 2016 7:47 am

Yes, I understand that you have the NOOBS installer. But which OS did you install from the first menu?

chleo
Posts: 21
Joined: Wed Jun 04, 2014 3:05 am

Re: failed to change RPi hostname

Thu Jan 28, 2016 8:42 am

one more thing:
after modifying host files, and run "sudo reboot", i saw the first message scrolling over screen is:

Code: Select all

sudo: unabale to resolve host rpi-old-name

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: failed to change RPi hostname

Thu Jan 28, 2016 12:10 pm

chleo wrote:one more thing:
after modifying host files, and run "sudo reboot", i saw the first message scrolling over screen is:

Code: Select all

sudo: unabale to resolve host rpi-old-name
That's because you've removed the entry from the /etc/hosts file, so there's no way the resolver can find a valid IP address for your old name.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

chleo
Posts: 21
Joined: Wed Jun 04, 2014 3:05 am

Re: failed to change RPi hostname

Thu Jan 28, 2016 12:42 pm

rpdom wrote:Yes, I understand that you have the NOOBS installer. But which OS did you install from the first menu?

Code: Select all

$ uname -a
Linux CNb827eb3686f6-Cactus 4.1.13+ #826 PREEMPT Fri Nov 13 20:13:22 GMT 2015 armv6l GNU/Linux
"CNb827eb3686f6-Cactus" is rpi-old-name, e.g. i plan to change it to be "CNb827eb3686f6-Leo", but failed :(

chleo
Posts: 21
Joined: Wed Jun 04, 2014 3:05 am

Re: failed to change RPi hostname

Thu Jan 28, 2016 12:47 pm

DougieLawson wrote: That's because you've removed the entry from the /etc/hosts file, so there's no way the resolver can find a valid IP address for your old name.
thanks for your answer.
i am sure "rpi-new-name" in /etc/hosts and /etc/hostname are exactly same, so what could be the reason?

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: failed to change RPi hostname

Thu Jan 28, 2016 12:56 pm

Whenever you change hostname you need to reboot.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

chleo
Posts: 21
Joined: Wed Jun 04, 2014 3:05 am

Re: failed to change RPi hostname

Thu Jan 28, 2016 3:02 pm

DougieLawson wrote:Whenever you change hostname you need to reboot.
yes, i do reboot up rpi.
actually after booting up, the prompt uses the NEW name.
but when i nano /etc/hosts and /etc/hostname files, they still contain OLD name.
then, after a while, rpi will reboot automatically, and change back to OLD name.

might this relate with DNS resolve setting?

chleo
Posts: 21
Joined: Wed Jun 04, 2014 3:05 am

Re: failed to change RPi hostname

Fri Feb 19, 2016 6:49 am

post a solution here:
besides modify above 2 host files, i run

Code: Select all

sudo hostnamectl set-hostname xxx 

fsr
Posts: 88
Joined: Wed Jan 13, 2016 2:29 am

Re: failed to change RPi hostname

Fri Feb 19, 2016 9:20 am

Code: Select all

sudo hostname new-hostname
changes the hosts name immediately (but not permanently). Couple it with the appropriate changes to /etc files to change the hostname without a reboot.

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: failed to change RPi hostname

Sat Feb 20, 2016 1:32 am

Not sure if this is part of the problem, or just the way it's written, but chleo wrote above:
but when i nano /etc/hosts and /etc/hostname files, they still contain OLD name
/etc/hosts and /etc/hostsname are owned by root, so if you don't use 'sudo nano', the changes won't get written out to the files on the SD card, and so they will appear to revert back to the old name by themselves.

Dave.

janpihlgren
Posts: 61
Joined: Thu Jul 26, 2012 4:00 am

Re: failed to change RPi hostname

Wed Jan 31, 2018 6:42 am

I also have failed to change hostname.
Oldname = Caecilius
Newname = Caracall
I tried to do : sudo nano /etc/hostname and change the name. Then I did: sudo nano /etc/host and change the name for 127.0.0.1
I also tried sudo hostnamectl set-hostname Caracall
After that I did sudo reboot
The Oldname still there, no change done.
uname -a gives: Linux Caecilius 4.4.34+ #930 Wed Nov 23 15:12:30 GMT 2016 armv6l GNU/Linux

When i logged in again I get the followng message:
Permissions 0744 for '/home/jan/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/jan/.ssh/id_rsa": bad permissions
[email protected]_wifi's password:
...........
For me it looks like that the oldname is save somewhere else and then used at logg in.
Is there anyone that know where to look for this odd behavieour?

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: failed to change RPi hostname

Wed Jan 31, 2018 6:57 pm

Post the output of:

Code: Select all

cat /etc/hostname
cat /etc/hosts
Dave.

janpihlgren
Posts: 61
Joined: Thu Jul 26, 2012 4:00 am

Re: failed to change RPi hostname

Thu Feb 01, 2018 5:21 am

[email protected]:~ $ cat /etc/hostname
Caecilius
[email protected]:~ $ cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

127.0.0.1 Caecilius
10.0.0.6 Bubba
10.0.0.38 Commodus_wifi
10.0.0.100 Zebbie

[email protected]:~ $
This is the result after changed the name to Caracalla and rebooted.

dgordon42
Posts: 764
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: failed to change RPi hostname

Thu Feb 01, 2018 8:41 am

It appears that the changes you make to the '/etc/hosts' and '/etc/hostname' files are not being written to your SD Card, and so when you reboot the old values return.
This could indicate that your SD Card has gone "Read Only", one of the signs of an SD Card failure.

Burn a fresh copy of Raspbian onto a genuine good quality SD Card, and try again.

Hope this helps,
Dave.

janpihlgren
Posts: 61
Joined: Thu Jul 26, 2012 4:00 am

Re: failed to change RPi hostname

Thu Feb 01, 2018 8:59 am

When I chaqnge the hostname, save the change and then read /etc/hostname the change is as supposed.
I then write a textfile and saved it and the reboot the file is gone.
So it looks like that you are right.
To use a new SD-card isn't the option.
How do I do to get the card writeable again?

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: failed to change RPi hostname

Thu Feb 01, 2018 9:46 am

janpihlgren wrote:
Thu Feb 01, 2018 8:59 am
How do I do to get the card writeable again?
You can't it's reached end-of-life and is just trash now.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Troubleshooting”