1.第一种方式是使用脚本的方式,开机自启动添加IP。如果不开机自启动,那就是临时添加IP,重启linux之后就消失了。
在/etc/rc.local文件里加入下面代码,达到开机自启动
/sbin/ifconfig eth0:1 192.168.1.100 broadcast 192.168.1.255 netmask 255.255.255.0 up
/sbin/route add -host 192.168.1.100 dev eth0:1
/sbin/ifconfig eth0:2 192.168.1.101 broadcast 192.168.1.255 netmask 255.255.255.0 up
/sbin/route add -host 192.168.1.101 dev eth0:2
重启linux,使生效
2.
cd /etc/sysconfig/network-scripts
cp ifcfg-eth0 ifcfg-eth0:0
cp ifcfg-eth0 ifcfg-eth0:1
ifcfg-eth0:0的配置文件如下:
DEVICE=”eth0:0″
NM_CONTROLLED=”yes”
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DNS1=202.102.192.68
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME=”System eth0:0″
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
HWADDR=00:0C:29:8D:9E:D5
ifcfg-eth0:1的配置文件如下:
DEVICE=”eth0:1″
NM_CONTROLLED=”yes”
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.1.101
PREFIX=24
GATEWAY=192.168.1.1
DNS1=202.102.192.68
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME=”System eth0:1″
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
HWADDR=00:0C:29:8D:9E:D5
重启linux或者/etc/init.d/network reload