Changing Your Hostname
- 0
- Add a Comment
I’ll admit it: I like to run a themed shop. When I worked for the high school and managed upwards of a hundred machines, I named systems after elements of Norse mythology and culture. For example, I had servers named Odin, Thor, and Loki (okay, the latter was my workstation), and labs full of valkyries and berserkers. These days I have seven servers, and they’re all characters from one of my favorite flicks, Pulp Fiction. At home, I’ve got characters and other elements from Roger Zelazny’s Chronicles of Amber novel series.
You get the idea.
There comes a time, however, when you have to change the hostnames. Maybe you’re bored of your current theme, or your boss has a beef with your selections, or maybe you want to rub out every remnant of a previous administrator (grr). Even after you make the changes in DNS, you have to change the hostname on the individual system. Unfortunately this is one of those things that’s not quite as easy as it sounds.
If your change is only temporary, or you want to make it without rebooting, you just need to use the hostname command, which can be found at /bin/hostname. Running it without arguments just outputs the current hostname. To change it, su to root and run hostname newhostname.
The tricky part comes into play when you want to make the change persist through a reboot. Why? Because different distributions store the hostname in different places. As I’ve run into the problem on both Fedora and Slackware, those are the systems I’ll cover here.
For Fedora (and, presumably, Red Hat), you need to edit the file /etc/sysconfig/network. An example is as follows:
NETWORKING=yes
HOSTNAME=myhostname.example.com
“myhostname” is the machine’s name and “example.com” is the domain name, just like in DNS. If your shell is set to display the hostname, this system would display myhostname.
Slackware, on the other hand, initializes the hostname during execution of the rc.M script at boot. It looks for a hostname in the file /etc/HOSTNAME and, if that file’s not available or readable, places a default hostname of darkstar (which, IMHO, is a little more inspired than Fedora’s bland default of localhost.localdomain). /etc/HOSTNAME only needs a one-line entry:
myhostname.example.com
The rc.M script breaks the line up to extract the host name from the domain name.
So, while the two files have the same function, the difficulty lies in tracking down the file. I’ve seen people reinstall entire systems just to change hostnames, or because they entered a typo during the initial install. Don’t go through all of that! If the files above aren’t on your system, don’t fret! With a little digging you should be able to track it down.
