Tuesday, 20 September 2016

Configuring Network Alias IP in centos


1.What is IP Alias:

     IP alias / IP aliasing is associating more than one IP address to a physical network interface. With this, one node on a network can have multiple connections to a network, each serving a different purpose.Alias network interface is configured on top of existing physical network interface.

2.What needs to IP alias:
Physical Network Interface Connectivity in server.
Available Multiple IP Addresses

Limitations of IP alias:
Subnet Aliasing (alias network interface IP address is preffered to be in the same network subnet as physical network interface below – if not proper network infrastructure configuration is needed)
DHCP (alias interfaces do not support DHCP)
Example: If physical network interface is named eth0, alias interfaces on top of this one are named eth0:0, eth0:1, … and if physical network interface is named eth1, alias interfaces on top of this one are names eth1:0, eth1:1 … and so on.


IP Alias Network Interface

2. Non-Persistent IP Alias Configuration

Non-persistent IP aliases do not survive linux server reboot. This means IP alias is only configured for the time the server is up and running and will dissapear if our linux server is rebooted. The following is the linux command line syntax to configure non-persistent alias network interface where X numbers the configured physical network interface, Y numbers the desired alias interface starting with 0 and IPADDRESS is the IP address we want to assign to our alias network interface:

[root@foo1 ~]# ifconfig ethX:Y IPADDRESS up


We can check if alias network interface is up and running with the following linux command (look for the ethX:Y interface):

[root@foo1 ~]# ifconfig


Example: In the following example a physical interface eth0 is properly configured with tested network connectivity and has an IP address 192.168.1.100. We can configure an alias network interface called eth0:0 and IP address 192.168.1.101 with the following command:

[root@foo1 ~]# ifconfig eth0:0 192.168.1.101 up


We can check if alias network interface is up with ifconfig, looking for the eth0:0 and IP address 192.168.1.101:

[root@foo1 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:A9:01:61
          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fea9:161/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4726 errors:0 dropped:0 overruns:0 frame:0
          TX packets:732 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:542695 (529.9 KiB)  TX bytes:115702 (112.9 KiB)

eth0:0    Link encap:Ethernet  HWaddr 08:00:27:A9:01:61
          inet addr:192.168.1.101  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:140 errors:0 dropped:0 overruns:0 frame:0
          TX packets:140 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:11760 (11.4 KiB)  TX bytes:11760 (11.4 KiB)

3. Persistent IP Alias Configuration

Persistent IP aliases survive linux server reboot and are configured in alias network configuration file. Network configuration files are stored in /etc/sysconfig/network-scripts/ directory and are named ifcfg-ethX, where X is a number of the physical network interface. Alias network configuration files are named ifcfg-ethX:Y, where X is the number of the physical network interface and Y is the number of the alias network interface.



The quickest and easiest way to create alias network interface configuration file is to copy an existing physical network interface configuration file with working network connectivity by running the following command:

[root@foo1 ~]# cp /etc/sysconfig/network-scripts/ifcfg-ethX /etc/sysconfig/network-scripts/ifcfg-ethX:Y


…where X is the number of the physical network interface and Y is the number of the alias network interface.

Next we need to edit the newly created file /etc/sysconfig/network-scripts/ifcfg-ethX:Y with the preferred file editor and replace the following physical network interface (ethX) entries with the desired new alias network interface (ethX:Y) entries.

Replace:

DEVICE=ethX
With:

DEVICE=ethX:Y
Find the IPADDR line of your ethX physical network interface:

IPADDR=XXX.XXX.XXX.XXX
And replace it with the desired alias network interface IP address:

IPADDR=YYY.YYY.YYY.YYY
When alias network interface configuration file is configured, we can bring the alias network interface up by running the following command:

[root@foo1 ~]# ifup ethX:Y


We can check if alias network interface is up with ifconfig command (look for the ethX:Y interface):

[root@foo1 ~]# ifconfig


Example: This is a working example of the physical network interface configuration file (eth0:0):

/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1


And a working example of the alias network interface (eth0:0) on top of physical network interface (eth0):

/etc/sysconfig/network-scripts/ifcfg-eth0:0

DEVICE=eth0:0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.1.149
NETMASK=255.255.255.0
GATEWAY=192.168.1.1


By running ifup command, we bring alias network interface up and running:

[root@foo1 ~]# ifup eth0:0


Checking for alias network interface eth0:0 with the IP address 192.168.1.101 with ifconfig command:

[root@foo1 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:A9:01:61
          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fea9:161/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4726 errors:0 dropped:0 overruns:0 frame:0
          TX packets:732 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:542695 (529.9 KiB)  TX bytes:115702 (112.9 KiB)

eth0:0    Link encap:Ethernet  HWaddr 08:00:27:A9:01:61
          inet addr:192.168.1.101  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:140 errors:0 dropped:0 overruns:0 frame:0
          TX packets:140 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:11760 (11.4 KiB)  TX bytes:11760 (11.4 KiB)

No comments:

Post a Comment