2011年8月18日木曜日

LINUX 连续多IP添加


在使用Linux系统网卡配置IP地址的时候,经常会遇到为某个网卡配置IP地址问题,普通的配置多IP的方法,经常会直接建立基本ifcfg-eth0:0 的方法来配置多IP,但在IP数量很多的时候很不方便,特别是如果这些IP需要更改的话,按照常规的办法去配置修改脚本,会非常繁琐。
针对这个问题,RedHat Linux 提供了下面的方法解决该问题:
配置脚本:
/etc/sysconfig/network-scripts/ifcfg-eth0-range0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR_START=192.168.0.10
IPADDR_END=192.168.0.100
CLONENUM_START=0
NETMASK=255.255.255.0
NO_ALIASROUTING=yes
脚本配置文件:
/etc/sysconfig/network-scripts/ifcfg-eth0-range1
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR_START=192.168.0.150
IPADDR_END=192.168.0.200
CLONENUM_START=100
NETMASK=255.255.255.0
NO_ALIASROUTING=yes

Note: CLONENUM_START defines where the alias will start. If this is the second range file, you will need to set CLONENUM_START to a value higher than the number of IP addresses assigned. To check what you currently have used, you can run ‘ifconfig –a | grep eth1’. This will list devices such as eth1:0, eth1:1, eth1:2, and so on. If you are currently using upto eth1:16, you will need to set CLONENUM_START to 17 to assign the IPs correctly.