Changing the Host Name in Linux



After purchasing another dedicated cent OS server last week and experiencing some issues with DirectAdmin i pinpointed the problem. The host name was completely wrong, although not a huge deal it was causing DA to throw a tantrum.

This is so simple to put right but i couldn’t for the life of me remember how to. After an hour or so of Googling i still couldn’t find the answer. In the end i picked up some old college notes and found what i need.

It is such a common task and being the nice chap that i am i put together this little how to guide. As you will see it really is easy once you know how to do it.

Start by popping open a terminal, in my case putty over ssh, and login to the root account.

You will need to edit /etc/sysconfig/network in your favourite editor. I’m using nano

# nano /etc/sysconfig/network

Edit the line beginning HOSTNAME= with your new host name e.g. HOSTNAME=gopalmer.co.uk

Next edit the /etc/hosts file in the same manner, again replacing the HOSTNAME value with your new host name.

Now type the following into the shell (replace gopalmer.co.uk with your host name)

# hostname=gopalmer.co.uk

Finally we need to restart the xinetd service

# service xinetd restart

Thats it! Easy wasn’t it?

One Response to “Changing the Host Name in Linux”

  1. xentie says:

    Changing the Host Name in FreeBSD:

    1. edit config file
    #nano /etc/rc.conf
    edit the line:
    hostname=”oldhostname.domain” to
    hostname=”newhostname.domain”

    2. enter command in shell
    #hostname newhostname.domain

    Nice site you got here :)

Leave a Reply




We're Listed in the e internet directory .co.uk Under: Website Design | Web Design Company - UK Web Designers & Developers