Saturday, January 30, 2010

Change hostname in Linux without rebooting server

Change hostname in Linux without rebooting server

First you need to find out your hostname, you can do this with

$ hostname
localhost.localdomain
$

Edit /etc/hosts

You need to edit /etc/hosts and add a line for your host name

$ cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
$

My new server IP is 192.168.1.1, i need to assign it hostname fedora.redhat.com, to do this, i have edited /etc/hosts as follows.

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.1.1 fedora.redhat.com fedora

Edit /etc/sysconfig/network

First lets see what is in the file

$ cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
$

To change servers hostname to fedora.redhat.com, change the file as follows.

$ cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=fedora.redhat.com
$

$/bin/hostname fedora.redhat.com

$service syslog restart

after you can logout and login back

1 comment:

esb.b4u said...

very slick, very simple and very much appreciated!!!