Red Hat: Changing Hostname and IP
Changing hostname and IP is frequently required when a server is being moved from testing or development to production. The process is a fairly simple one, but steps must be performed in a certain order to avoid complications. Before making any changes you must confirm that the new IP is available and that your server – physical or VM – can access the new network. You will also need to have console access to the server.
For our example, we are changing hostname from srv-dev-01.krazyworks.com to srv-prd-01.krazyworks.com. The IP address is changing from 192.168.102.17 to 192.168.112.17 on interface eth0. The first step is to create backups of the files we are going to modify:
|
1 2 3 4 5 |
for i in /etc/hosts /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network do mkdir /etc/backups /bin/cp -p "${i}" /etc/backups/ done |
Now open the /etc/hosts file and modify/add a line with your server’s new IP, fully-qualified DNS name, and short hostname:
|
1 |
192.168.112.17 srv-prd-01.krazyworks.com srv-prd-01 |
The next step is to edit the configuration file for the eth0 network interface: /etc/sysconfig/network-scripts/ifcfg-eth0. At the very least, you will need to check the IP address, the netmask and the MAC address of the network interface card.
|
1 2 3 4 5 6 7 8 |
DEVICE=eth0 BOOTPROTO=static DHCPCLASS= HWADDR=00:50:56:AA:11:2C IPADDR=192.168.112.17 NETMASK=255.255.255.0 ONBOOT=yes <pre lang="text"> |
Now we need to modify /etc/sysconfig/network to change the hostname and default gateway information:
|
1 2 3 4 |
NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=srv-prd-01.krazyworks.com GATEWAY=192.168.112.1 |
As the final step, you may run the hostname command to set the hostname for the current session and restart network services:
|
1 2 |
hostname srv-prd-01.krazyworks.com /etc/init.d/network restart |
Make sure you can ping the default gateway, the DNS server and any other critical servers (NIS, LDAP, NFS, etc.) At this point it would be a good idea to reboot the server to make sure there are no unexpected issues with the hostname change.
-
mavis24
-
Victoria T
-
Alina Elliott
