Apr 9, 2018

HOW TO ADD Multiple / Ranges OF IP ADDRESSES TO CentOS / RHEL / Oracle Linux NIC

Go to the /etc/sysconfig/network-scripts directory.

Verify which interface you will use to add IP addresses. Typically, this will be em1, em2 or eth0, eth1 for public IP addresses.

Make a copy of ifcfg-eth0 for each IP you wish to add and name them as ifcfg-eth0:0, ifcfg-eth0:1 etc.
#      cp ifcfg-eth0 ifcfg-eth0:0
#      cp ifcfg-eth0 ifcfg-eth0:1
#      cp ifcfg-eth0 ifcfg-eth0:2
#      cp ifcfg-eth0 ifcfg-eth0:3
#      cp ifcfg-eth0 ifcfg-eth0:4
Open each of them and change the fields DEVICE, .IPADDR and NETMASK accordingly.
A sample entry would look like this:
NAME="eth0:0"
BOOTPROTO="static"
IPADDR0="192.168.0.2"
PREFIX0="23"
ONBOOT=yes 
GATEWAY0="192.168.1.1"
Restart the network:
#    systemctl restart network
OR
#    service network restart

To add a lot of IP addresses ( range(s) ) at once:

First, you need to make sure to append the following text to the end of the NIC configuration file ( such as /etc/sysconfig/network-scripts/ifcfg-em2 ) and save it: NM_CONTROLLED=NO

This configuration change is required on Redhat/CentOS 7.x for enabling range files. It simply allows us to utilize range files by having the interface no longer be controlled by the Network Manager system. Once you’ve made the aforementioned change and saved the file, we can then proceed with creating our range file.

In this folder /etc/sysconfig/network-scripts/, create a file named "ifcfg-emX-rangeY", without the quotes, and replacing X with the ID of the physical interface, Y with the ID of the IP range. For example, to add range0 to em1, you would use the file name:     ifcfg-em1-range0

In the file, enter the following information, modifying the entries as necessary.
IPADDR_START=192.168.0.6
IPADDR_END=192.168.0.18
CLONENUM_START=0
NETMASK=255.255.254.0
  • IPADDR_START means the start of the IP address range
  • IPADDR_END means the end of the IP address range
  • CLONENUM_START means the number assigned to the first virtual interface, for example em2:8 or em2:88.
After you have created the file, save and quit, and then restart the network service.