Home > linux > Changing hostname – The UNIX way!

Changing hostname – The UNIX way!

November 14th, 2009 Leave a comment Go to comments

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.

Solaris

On Solaris, there are three files that you need to edit. These include /etc/hosts, /etc/hostname. 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.. The 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 ‘ command to assign the new hostname immediately.

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.

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

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

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

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

OpenBSD

Very similar to Solaris operating system.

- Update to new hostname in /etc/hosts file
- Make appropriate change in /etc/myname
- Lastly, /etc/hostname.. Similar to Solaris, you’ll need to identify system interface and update this file appropriately.

HP-UX

The script /sbin/set_parms changes system parameters including hostname and IP address.

- /sbin/set_parms

Digital Unix

- Edit /etc/hostname.driver

- As well as /etc/hosts file

FreeBSD

To change hostname do:

- Edit /etc/rc.conf and update to new hostname value

- Edit /etc/hosts

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.

NetBSD

- Edit /etc/myname

- And of course edit /etc/hosts file :)

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

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.

Categories: linux Tags:
  1. December 11th, 2009 at 15:22 | #1

    Stunning, I didn’t heard about this topic until now. Thx!

  1. No trackbacks yet.