How to set the hostname? (CentOS/DHCP)

This must be a FAQ, but I couldn't find anything.

How do I set the hostname on my Linode? I'm using the default (DHCP) configuration on CentOS 3.1.

I can set the hostname using hostname command, but it does back to the original (liXX-XXX.members.linode.com) on reboot.

Where in the tangle of network scripts and config files is the right place to change the hostname for this configuration?

I have DNS and reverse DNS working.

7 Replies

http://www.linode.com/forums/viewtopic.php?t=1027

-Chris

> http://www.linode.com/forums/viewtopic.php?t=1027

That is a good description of how to set up Webmin on CentOS, and I suppose Webmin knows how to set the hostname, but I would rather not run Webmin.

In most problems like this you can grep for hints, but since the default hostname comes from the DHCP server that approach doesn't work in this case :(

I think caker is referring to step 5 in that tutorial.

> Step Five

Update your hostname

 echo yourdomainnamehere >/etc/hostname  
 /bin/hostname -F /etc/hostname 

> Code:

echo yourdomainnamehere >/etc/hostname

Code:

/bin/hostname -F /etc/hostname

Ok, I see, Webmin not required I guess. I read too fast, please excuse me.

But this is what I already tried. The problem is on the next reboot I'm back to the original hostname assigned by Linode, I guess it is coming from the DHCP server. Should I invoke /bin/hostname in /etc/rc.local?

Doesn't seem right to set one hostname during startup and immediately switch every time.

I guess I could switch to a static IP configuration if I have to.

I'm using Gentoo myself, and it handles this without problems.

Just to double-check, what is the actual contents of your /etc/hostname file at the moment?

> Just to double-check, what is the actual contents of your /etc/hostname file at the moment?

It contains the fully qualified domain name (ending in ".com"). It's three levels: ..com. Resolves in DNS to the IP address of the Linode UML machine.

Just for the record: I fixed the "HOSTNAME=" line in /etc/sysconfig/network and it seems to be working for me now.

Finally found the right Google keywords and picked up on a discussion from 2003 at LinuxForums.org: http://www.linuxforums.org/forum/topic-350-0.html.

I still have /etc/hostname set but I'm not sure it is required for CentOS.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct