Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Networking

Red Hat: Changing Hostname and IP

Submitted by on August 31, 2011 – 1:47 pm 3 Comments

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:

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:

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.

DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:50:56:AA:11:2C
IPADDR=192.168.112.17
NETMASK=255.255.255.0
ONBOOT=yes

Now we need to modify /etc/sysconfig/network to change the hostname and default gateway information:

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:

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.

Print Friendly, PDF & Email

3 Comments »

  • mavis24 says:

    I am working as a broadband internet field engineer. In windows 98 or xp i can easily put ip, subnett, dns, gateway in my network places>view network con.>local area connection>properties>TCP/IP.but i dont know where i put ip address in LINUX, please help me step by step to give u best answer.

  • Victoria T says:

    I have an internet connection with a dynamic ip address, and the usb modem is attached to my wifi router, i want to host my website from vmware, from linux servers, i have installed ubuntu server, centos, red hat and more, but how do i host the website from these? I have a dynamic ip address and I dont want to open port 80 for my whole computer, only for the virtual machine, most preferably i will use ubuntu server, please give me proper instructions, and my isp wont give me a static ip, and i cant change my isp as well.

  • Alina Elliott says:

    I am in college and wanted to know if my IP address on the school computers would be different than my own Macbook. I use the same log in info to connect to wi fi that I use to access a school computer, thanks!

Leave a Reply

%d bloggers like this: