View previous topic :: View next topic |
Author |
Message |
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Thu Aug 20, 2015 8:33 pm Post subject: [SOLVED] Can't Change Hostname |
|
|
Hello Gentoo forums,
About a year or so ago I needed to change my desktop computer's hostname and I did it by adding the following to the hostname file in the conf.d directory:
Code: |
# Set to the hostname of this machine
hostname "mybox"
|
But after a few system upgrades, that particular hostname is no longer recognized. Instead my new hostname is as follows, even though the hostname file shown above has not changed:
Code: |
14-da-e9-ca-30-72 royroy # hostname
14-da-e9-ca-30-72
|
My question would be, how can I change my hostname back to what it was before these upgrades? I will be glad to supply more info if needed.
Thanks much,
Roy
Last edited by roytheman on Sat Aug 22, 2015 7:53 pm; edited 1 time in total |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu Aug 20, 2015 8:40 pm Post subject: |
|
|
That still is the correct method, unless you're using systemd. Are you? If not, could you post the output of Code: | rc-update | grep hostname | please?
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters.
Last edited by John R. Graham on Thu Aug 20, 2015 8:43 pm; edited 1 time in total |
|
Back to top |
|
|
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Thu Aug 20, 2015 8:42 pm Post subject: |
|
|
Code: | 14-da-e9-ca-30-72 royroy # rc-update | grep hostname
hostname | boot |
|
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu Aug 20, 2015 8:44 pm Post subject: |
|
|
Thanks. Are you, by chance, using systemd now?
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Thu Aug 20, 2015 8:48 pm Post subject: |
|
|
I'm pretty sure I'm using openrc because during the boot process it shows the version number of openrc (POST). |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu Aug 20, 2015 8:54 pm Post subject: |
|
|
Okay, just checking. One more easy one. What's the output of Code: | /etc/init.d/hostname status | ?
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Thu Aug 20, 2015 8:56 pm Post subject: |
|
|
Code: | 14-da-e9-ca-30-72 royroy # /etc/init.d/hostname status
* status: started |
|
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu Aug 20, 2015 8:57 pm Post subject: |
|
|
Well, let's restart it & see what happens. Please run Code: | /etc/init.d/hostname restart | and report the output (code tags appreciated; added for you above).
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters.
Last edited by John R. Graham on Thu Aug 20, 2015 9:02 pm; edited 2 times in total |
|
Back to top |
|
|
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Thu Aug 20, 2015 9:00 pm Post subject: |
|
|
Code: |
14-da-e9-ca-30-72 royroy # /etc/init.d/hostname restart
* Setting hostname to mygentoo ... [ ok ]
|
It says "mygentoo" instead of "mybox because I changed it a while ago.
Last edited by roytheman on Thu Aug 20, 2015 9:02 pm; edited 1 time in total |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu Aug 20, 2015 9:02 pm Post subject: |
|
|
And what's your host name now?
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Thu Aug 20, 2015 9:04 pm Post subject: |
|
|
Code: |
14-da-e9-ca-30-72 royroy # hostname
mygentoo
|
But I don't think it will survive a reboot. It never did. |
|
Back to top |
|
|
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Thu Aug 20, 2015 9:17 pm Post subject: |
|
|
I just rebooted my computer and the hostname reverted back to the way it was:
Code: |
royroy@14-da-e9-ca-30-72 ~ $ hostname
14-da-e9-ca-30-72
|
|
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu Aug 20, 2015 9:28 pm Post subject: |
|
|
Okay. Post the exact /etc/conf.d/hostname file, please.
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Thu Aug 20, 2015 9:32 pm Post subject: |
|
|
Code: |
# Set to the hostname of this machine
hostname "mygentoo"
|
That is the entire file. |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu Aug 20, 2015 9:34 pm Post subject: |
|
|
Bingo. (Argh; missed it.) Okay, change Code: | hostname "mygentoo" | to Code: | hostname="mygentoo" | and let me know how you fare.
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Thu Aug 20, 2015 9:44 pm Post subject: |
|
|
/etc/conf.d/hostname
Code: |
# Set to the hostname of this machine
hostname="mygentoo"
|
Code: |
royroy@14-da-e9-ca-30-72 ~ $ hostname
14-da-e9-ca-30-72
|
I hate to be the bearer of bad news but after rebooting, the hostname did not change, shown above. |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10587 Location: Somewhere over Atlanta, Georgia
|
Posted: Thu Aug 20, 2015 10:00 pm Post subject: |
|
|
Could you reboot and carefully monitor the init scripts as they run? Report what the full "* Setting hostname to" line says, please.
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Thu Aug 20, 2015 10:08 pm Post subject: |
|
|
During the bootup process, one of the lines said:
Code: |
* setting hostname to mygentoo
|
But I get this from the terminal:
Code: |
royroy@14-da-e9-ca-30-72 ~ $ hostname
14-da-e9-ca-30-72
|
|
|
Back to top |
|
|
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Fri Aug 21, 2015 4:27 pm Post subject: |
|
|
I've done more experimenting and I discovered that the number shown below is the MAC address of my wired interface, eth0, or my Ethernet card, irregardless of what my hostname is in the hosts file:
Code: |
royroy@14-da-e9-ca-30-72 ~ $ hostname
14-da-e9-ca-30-72
|
I also discovered that if I connect to the Internet using wifi (not wired) the problem goes away, and eth0 becomes wlan0, as shown below:
Code: |
royroy@mygentoo ~ $ hostname
mygentoo
|
I also discovered that in my other two Linux operating systems, Kubuntu and OpenSuse (I have a multi-boot setup), the problem does not exist (wired connection or wifi).
I also discovered if I disconnect from Internet altogether, the problem goes away.
I have been using dhcpd for my client where the problem persists but if I switch over to ddclient instead, the problem still persists.
My wired connection comes from a Cradlepoint router with a Verizon USB modem plugged into it.
I'm hoping somebody would please give me some clues.
All the best,
Roy |
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54220 Location: 56N 3W
|
Posted: Fri Aug 21, 2015 8:27 pm Post subject: |
|
|
roytheman,
dhcpcd is whatever you use to get your network setup is providing your hostname.
There is a no... option to go in /etc/conf.d/net file to stop that. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
Tony0945 Watchman
Joined: 25 Jul 2006 Posts: 5127 Location: Illinois, USA
|
Posted: Fri Aug 21, 2015 8:45 pm Post subject: |
|
|
Quote: |
My wired connection comes from a Cradlepoint router with a Verizon USB modem plugged into it. |
I was surprised at NeddySeagoon's post, because I have no trouble with dhcpd on my network, However, My D-link router has a predefined table under DHCP that I use to always assign the same ipaddress to a given MAC address. That table has a hostname field, which I thought was only for my reference, but it is probably setting the hostname as well, per Neddyseagoon's comment. I never realized that because both hostnames are the same.
Does your router have a facility like DLink's? |
|
Back to top |
|
|
roytheman Tux's lil' helper
Joined: 08 Nov 2009 Posts: 102
|
Posted: Sat Aug 22, 2015 7:48 pm Post subject: |
|
|
I solved my problem but it raises more questions for me.
First off, I replaced dhcpcd with ddclient because the help I found on Google was for ddclient, not dhcpcd, but I'm sure there is a way to do the same thing with dhcpcd.
Apparently one does not have to change their hostname in /etc/conf.d/hostname (in Gentoo) because the config file in /etc/dhcp/dhclient.conf will override whatever your host name is in that location. To make this override, add the line
Code: |
send host-name "your-hostname";
|
to dhclient.conf. (Just make sure this line is in the same format as the rest of the file). Whatever you choose to be your hostname there, it will override any other hostname you may have configured. By doing that, now my hostname is "mygentoo", not my MAC address. For example, if your hostname is "mybox" in /etc/conf.d/hostname, and if your hostname is "mygentoo" in /etc/dhcp/dhclient, your machine will use "mygentoo", not "mybox" as long as you are connected to the Internet. If you disconnect, then your hostname will become "mybox", instead of "mygentoo". This problem only exists when you are connected to the Internet.
To answer Tony0945's question, my Cradlepoint router only lets you reserve leases in the dhcp section. There is no other setting that I could find. Besides, like I posted above, I do not have this problem in other Linux distributions on my multi-boot computer and of course those other distributions are using the very same hardware and router as the one I am currently in (Gentoo). So this problem seems to be specific to Gentoo, not other Linux OSes.
There are probably neater ways to solve this problem but this way is the only way I have found.
All the best,
Roy
UPDATE
I found a better way. Use this command:
Code: |
send host-name = gethostname();
|
in the /etc/dhcp/dhclient.
Now the system will only use the hostname in /etc/conf.d/hostname instead of dhcp assigning its own hostname, which is the MAC address of my Ethernet card. |
|
Back to top |
|
|
|