Adding multiple IP addresses on one Ethernet

If we have one network interface, eth0. And when you add IP addresses, you actually create virtual network interfaces named eth0:1, eth0:2, ...... eth0:n.


How to set it on temporary basis on all OS's:

#ifconfig eth0:1 up [IP address] netmask [chosen netmask, if unsure use 255.255.255.0].

You can add commands like this to your startup scripts to have them come up on reboot, but there is cleaner way which is maintioned below;


How to set it Permanently basis on RHEL / CentOS :


All interface configuration files are located in "/etc/sysconfig/network-scripts/". Each interface is represented by a file corresponding to ifcfg-eth<x> where <x> represents the unique interface number for that card (e.g. the first interface card is represented by ifcfg-eth0). To create an alias for that interface, you need to create a file in the format of ifcfg-eth0:<y> where <y> represents the alias number (e.g. the 2nd ip for the first card would be ifcfg-eth0:1). To set up two ip addresses on a ethernet edit/create the following files as noted (substituting your ip addresses where denoted by x's):



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

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=XXX.XXX.XXX.XXX
NETMASK=255.255.255.0
BROADCAST=XXX.XXX.XXX.255
GATEWAY=XXX.XXX.XXX.1



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

DEVICE=eth0:0
BOOTPROTO=none
ONPARENT=yes
IPADDR=XXX.XXX.XXX.XXX
NETMASK=255.255.255.0
BROADCAST=XXX.XXX.XXX.255

This assumes all ip addresses are in the same range. See the RedHat Enterprise Linux Reference Guide for details on the configurable parameters. Finally, running "service network restart" will restart the network interfaces (probably best to do this from lish). Hope it helps.

Comments

Popular posts from this blog

Recover or restore initramfs file in RHEL or CentOS 7

Space reclamation / UNMAP on RHEL or CentOS 7

How to recover /boot partition on RHEL or CentOS 7?