Auto configure multiple IPs under Linux

Generally, if you want to configure multiple IPs to the same network card, you need to write the configuration files one by one. It’s ideally to run a script and it will auto configure everything. Here is a sample script.

1. Create the range script under /etc/sysconfig/network-scripts

# vi /etc/sysconfig/network-scripts/ifcfg-eth0-range0

DEVICE=eth0
BOOTPROTO=static
IPADDR_START=192.168.1.113  
IPADDR_END=192.168.1.123
CLONENUM_START=1
NETMASK=255.255.255.0
ONBOOT=yes

2. Quit and restart the network service, the system will auto configure each IP started from eth0:1

# service network restart

Some NETMASK reference.

/29 (5 usable) NETMASK = 255.255.255.248
/28 (13 usable) NETMASK = 255.255.255.240
/27 (29 usable) NETMASK = 255.255.255.224
/26 (61 usable) NETMASK = 255.255.255.192
/25 (125 usable) NETMASK = 255.255.255.128
/24 (253 usable) NETMASK = 255.255.255.0

The first two IPs (network & gateway) and the last IP (broadcast) in your assignment are unusable for you.

Share

- has written 121 posts.


Leave a Reply

You must be logged in to post a comment.