Mar
21
While the /etc/hosts file is generally the first to come to mind when you think about changing the name of a Unix system, modifying this file is only one step in the process. The other files that need to be changed depend on which particular version of “*nix” you are running.
The following is a list of UNIX flavors and methods of changing hostname permanently on each system.
1) Solaris
On Solaris, there are three files that you need to edit. These include /etc/hosts, /etc/hostname.<interface> and /etc/nodename.
- Edit /etc/hosts with vi and update to the new hostname.
- Similarly update /etc/nodename using an editor or “echo newhost > /etc/nodename”
- Lastly, edit /etc/hostname.<interface>. The <interface> should be replaced by the name of the particular network interface on your server. For example, a common name is /etc/hostname.hme0. If you’re not sure about the interface name, simply do an ‘ifconfig -a‘, this’ll display the network interface name.
Once you’ve updated the above 3 files, best thing is to reboot your system or if can’t reboot right away, you can execute ‘uname -S <new hostname>’ command to assign the new hostname immediately.
2) Redhat Linux (Fedora, Mandriva, PCLos)
On Redhat based Linux systems, the primary setting for the system hostname is included in the /etc/sysconfig/network file.
- Open this file in editor, you should see something like this:
—————————————————-
NETWORKING=yes
HOSTNAME=abc.example.com
—————————————————-
- and of course the /etc/hosts file.
3) Debian/Ubuntu Linux
Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh.
- Edit /etc/hostname and update to your new hostname, you can then run /etc/init.d/hostname.sh to activiate the change.
- Update your /etc/hosts file to refelect new hostname
You can also use sysctl to change the hostname:
- sysctl kernel.hostname (To read the current hostname)
- sysctl kernel.hostname=NEW_HOSTNAME (to change it)
To change in gui in Ubuntu you can click to:
- System > Administration > Networking > General tab > Host name field
4) Slackware Linux
Similar to Debian except the it is uppercase HOSTNAME.
- Edit /etc/HOSTNAME and update to new value
- Update /etc/hosts to new hostname value as well
5) SuSE Linux
To change hostname permanently on SuSE Linux
- Edit the file /etc/HOSTNAME and change the value in it, Save and exit
- Update /etc/hosts to new hostname value
6) Mac OSX
To change hostname on a Mac OSX server…
- Edit /etc/hostconfig and update to your new hostname
- And of course the /etc/hosts file needs to be adjusted to your new host
You can also execute the following command:
- sudo scutil –set HostName abc.example.com
7) OpenBSD
Very similar to Solaris operating system.
- Update to new hostname in /etc/hosts file
- Make appropriate change in /etc/myname
- Lastly, /etc/hostname.<interface>. Similar to Solaris, you’ll need to identify system interface and update this file appropriately.
8 ) HP-UX
The script /sbin/set_parms changes system parameters including hostname and IP address.
- /sbin/set_parms
9) Digital Unix
- Edit /etc/hostname.driver
- As well as /etc/hosts file
10) FreeBSD
To change hostname do:
- Edit /etc/rc.conf and update to new hostname value
- Edit /etc/hosts
11) AIX
AIX stores all its information in ODM (Object Database Manager) including hostname value. There are a couple ways of doing it:
- chdev -l inet0 -a hostname=thomas
Or you can use smitty as well.
12) NetBSD
- Edit /etc/myname
- And of course edit /etc/hosts file
13) SCO Unix
I don’t know who in their right mind would run SCO these days. But anyhow the way to change hostname permanently is:
- sys-unconfig
14) IRIX
I can understand why IRIX may still be used. To change hostname:
- Edit /etc/sys_id and update to new host value
- Edit /etc/hosts as well
Then reboot your workstation/server for changes to take affect.
Finally, some general facts about all Linux distros. The following are commands that are unique to all flavors of Linux:
To print current system hostname on the system:
- hostname
- uname -n
- cat /etc/hosts | grep 127.0.0.1
To print the fully qualified domain name of the system:
- hostname -fqd
To temporarily update the system to new hostname:
- hostname new_hostname
- echo “new hostname” > /proc/sys/kernel/hostname
On most Linux flavors, you can also execute the command:
- netconfig
In conclusion, please keep in mind that all UNIX flavors utilizes the /etc/hosts file to associate IP to hostname for your local server. So this file is global and you’ll need to make sure this file is not overlooked. Please add to the comments if I’ve missed other major flavors.
Comments
6 Comments so far







You missed DOS!
How do you change the hostname in DOS!!
Uhh… you’re an idiot Tone Dialer!
DOS is not UNIX. In fact DOS doesn’t even need a hostname. It doesn’t care if it does or not.
Why did you say something so stupid? I’m so frustrated thinking an idiot like you is roaming around the world right now.
[…] The following is a list of UNIX flavors and methods of changing hostname permanently on each system. […]
nothing
I’m sorry, ToneDialer is still phuking phunny =)
some confusion about whether hostname or HOSTNAME files should contain fully-qualified domain names or not…
some software apparently doesn’t function properly if entries here are not FQDN. true?
what is correct?