March 14, 2014

IP Aliases in RHEL 6

Introduction

Assigning multiple IP addresses to a single interface is called IP aliasing. This can be handy if you want a single web server to serve multiple sites.

Prerequisite

It is advised to disable NetworkManager.

$ service NetworkManager stop; chkconfig NetworkManager off

Configuration

Show current configuration for eth0.

$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:22:d1:df brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.20/24 brd 192.168.122.255 scope global eth0
    inet6 fe80::5054:ff:fe22:d1df/64 scope link 
       valid_lft forever preferred_lft forever

Add IP alias.

$ ip addr add 192.168.122.250/24 dev eth0 label eth0:0

Show new configuration for eth0

$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:22:d1:df brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.20/24 brd 192.168.122.255 scope global eth0
    inet 192.168.122.250/24 scope global eth0:0
    inet6 fe80::5054:ff:fe22:d1df/64 scope link 
       valid_lft forever preferred_lft forever

To make it persistent edit the following

$ vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
IPADDR=192.168.122.250
PREFIX=24
ONPARENT=yes

Now restart network service.

$ service network restart

Test

Ping from another machine

$ ping 192.168.122.250
PING 192.168.122.250 (192.168.122.250) 56(84) bytes of data.
64 bytes from 192.168.122.250: icmp_seq=1 ttl=64 time=1.05 ms

Reference

/usr/share/doc/initscripts-*/sysconfig.txt

No comments: