Technical Recipes

How to configure multiple static IP addresses on centOS

If you need to configure multiple static IP addresses on the same host of the hosting site, you can do it via the virtual interface setting as below. The IP addresses to be used must be valid IP addresses assigned by the hosting provider.

1. Find the system default network setting which is using DHCP by default
	
    # ifconfig
    # vi /etc/sysconfig/network
    # vi /etc/resolv.conf
    # vi /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE="eth0"
    BOOTPROTO="dhcp"
    HWADDR="00:0C:29:55:52:41"
    IPV6INIT="yes"
    NM_CONTROLLED="yes"
    ONBOOT="yes"
    TYPE="Ethernet"
    UUID="67ffccb8-2408-4ecb-bdd9-baf81f4911af"
	
2. Choose one Ethernet network card, say eth0, and keep the loopback and other network interface unchanged
	
    # cd /etc/sysconfig/network-scripts
    # chattr +i ifcfg-eth1
    # chattr +i ifcfg-lo
	
3. Create or modify /etc/sysconfig/network-scripts/ifcfg-eth0
	
    # vi ifcfg-eth0
    DEVICE="eth0"
    BOOTPROTO="static"
    NM_CONTROLLED=no
    TYPE=Ethernet
    ONBOOT="yes"
    IPADDR=192.168.1.220
    NETMASK=255.255.255.0
    GATEWAY=192.168.1.1
    IPV6INIT=no
    USERCTL=no
	
4. Copy ifcfg-eth0 to ifcfg-eth0:0 and modify
	
    # cp ifcfg-eth0 ifcfg-eth0:0
    # vi ifcfg-eth0:0
    DEVICE="eth0:0"
    IPADDR=192.168.1.221
	
5. Copy ifcfg-eth0:0 to ifcfg-eth0:1 and modify
	
    # cp ifcfg-eth0 ifcfg-eth0:1
    # vi ifcfg-eth0:1
    DEVICE="eth0:1"
    IPADDR=192.168.1.222
	
6. Restart network
	
    # chattr +i /etc/services
    # service network restart