Thursday, March 16, 2017

Assign multiple IP addresses to one single network interface

Assign multiple IP addresses to one single network interface

Method 1:

# cd /etc/sysconfig/network-scripts/
# vim ifcfg-eno16777736

IPADDR0="192.168.6.60"
PREFIX0="24"

IPADDR1="192.168.6.61"
PREFIX1="24"

IPADDR2="10.0.0.2"
PREFIX2="24"
GATEWAY2="10.0.0.1"

Note: I am using a different subnet 10.0.0.0/24 here, too.

Note: If you run ifconfig command, these IP aliases would not show up. Because ifconfig is essentially deprecated. The replacement is the ip command.

# systemctl restart network.service
# ip addr

2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:40:a1:f2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.6.10/24 brd 192.168.6.255 scope global eno16777736
       valid_lft forever preferred_lft forever
    inet 10.0.0.2/24 brd 10.0.0.255 scope global eno16777736
       valid_lft forever preferred_lft forever
    inet 192.168.6.60/24 brd 192.168.6.255 scope global secondary eno16777736
       valid_lft forever preferred_lft forever
    inet 192.168.6.61/24 brd 192.168.6.255 scope global secondary eno16777736
       valid_lft forever preferred_lft forever

Method 2:

# cd /etc/sysconfig/network-scripts/
# cp ifcfg-eno16777736 ifcfg-eno16777736:0
# cp ifcfg-eno16777736 ifcfg-eno16777736:1

# vim ifcfg-eno16777736:0

DEVICE="eno16777736:0"
IPADDR="192.168.6.60"

# vim ifcfg-eno16777736:1

DEVICE="eno16777736:1"
IPADDR="192.168.6.61"

# systemctl restart network.service

Method 3:

If you would like to create a range of multiple IP addresses to a particular network interface:

# cd /etc/sysconfig/network-scripts/
# vim ifcfg-eno16777736

NM_CONTROLLED=NO

Note: This setting is required on Redhat/CentOS 7.x for enabling the range files, which allows us to utilize the range files by having the interface no longer be controlled by the Network Manager system.

# touch ifcfg-eno16777736-range0
# vim ifcfg-eno16777736-range0

IPADDR_START="192.168.6.63"
IPADDR_END="192.168.6.68"
PREFIX="24"
CLONENUM_START="0"

Note: CLONENUM_START is the number of virtual device the first IP address will be assigned to. If you have more than one range file, then you need to make sure that this number is set to the next available number.

# systemctl restart network.service

Reference:

http://www.tecmint.com/create-multiple-ip-addresses-to-one-single-network-interface/

https://www.ubiquityhosting.com/blog/configure-ip-ranges-on-centos-7-redhat-7/

http://askubuntu.com/questions/227457/ifconfig-not-showing-all-ips-bound-to-the-machine

No comments: