Info
Content

Configuring multiple IPv4 addresses in Linux


Debian Based (Debian & Ubuntu)

Use your favourite text editor to edit the network interfaces file

nano /etc/network/interfaces

An alias will have to be created based on your primary interface by appending a number by using a colon. (e.g. :0)
An example of this would be as follows, assuming the primary interface is eth0,

auto eth0
iface eth0 inet static
 address 192.168.1.2
 netmask 255.255.255.0
 gateway 192.168.1.254
 dns-nameservers 77.247.176.114 77.247.176.115 85.159.238.17

auto eth0:0
iface eth0:0 inet static
 address 192.168.1.3
 netmask 255.255.255.0

auto eth0:1
iface eth0:1 inet static
 address 192.168.1.4
 netmask 255.255.255.0

RHEL Based (CentOS)

Individual IP addresses:


An alias will have to be created based on your primary interface by appending a number by using a colon. (e.g. :0)
An example of this would be as shown below, assuming the primary interface is 'eth0'.

Use your favourite text editor to create a new network interface file. A new file would have to be created for each alias / IP address

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

 

DEVICE=eth0
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.3
NETMASK=255.255.255.0

A range of IP addresses:

CentOS supports a 'range' file, which creates multiple aliases for you at once, making the configuration of subsequent IP addresses much quicker.

Use your favourite text editor to create a new range file, assuming your primary network interface is 'eth0'.

nano /etc/sysconfig/network-scripts/ifcfg-eth0-range0
IPADDR_START=192.168.0.3
IPADDR_END=192.168.0.30
CLONENUM_START=0
NM_CONTROLLED=no
ARPCHECK=no

The first and second option would be the first and last IP address you wish to assign - whilst assigning everything in between.
CLONENUM_START is the first number/name of the alias, which would be 0 in most cases. If you already have an alias you would select the first available number.
ARPCHECK disables the system from checking whether or not the IP address is already in use somewhere else, making starting the interfaces a much quicker progress.

Ensure 'NM_CONTROLLED=no' is added to your main interface file as well, as without it this method will not work.

No Comments
Back to top