> CentOS > CentOS入门 >

CentOS增加新IP/单网卡绑定多IP

因为公网线路需要更换IP地址,在过渡期间可以二个IP地址同时使用,为此需要为单个网卡绑定二个IP地址。
(1)增加新IP地址。为了以后删除旧IP地址方便,直接将eth1的IP改为新IP,并重新将eth1:1接口为旧IP地址。

[root@web network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@web network-scripts]# cp ifcfg-eth1 ifcfg-eth1:1
[root@web network-scripts]# vi ifcfg-eth1:1
DEVICE=eth1:1
###GATEWAY=211.151.92.17
[root@web network-scripts]# vi ifcfg-eth1
IPADDR=121.52.160.29
GATEWAY=121.52.160.17

(2)重新启动网络,并查看新网络配置

[root@web network-scripts]# /etc/init.d/network restart
[root@web network-scripts]# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:1E:4F:37:40:6F  
          inet addr:121.52.160.29  Bcast:121.52.160.31  Mask:255.255.255.240
          inet6 addr: fe80::21e:4fff:fe37:406f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11468 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17259 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1037939 (1013.6 KiB)  TX bytes:19258257 (18.3 MiB)
          Interrupt:16 Memory:f4000000-f4012100 
[root@web network-scripts]# ifconfig eth1:1
eth1:1    Link encap:Ethernet  HWaddr 00:1E:4F:37:40:6F  
          inet addr:211.151.92.29  Bcast:211.151.92.31  Mask:255.255.255.240
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:16 Memory:f4000000-f4012100 
[root@web network-scripts]# netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
211.151.92.16   0.0.0.0         255.255.255.240 U         0 0          0 eth1
121.52.160.16   0.0.0.0         255.255.255.240 U         0 0          0 eth1
166.111.120.0   0.0.0.0         255.255.255.0   U         0 0          0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U         0 0          0 virbr0
166.111.0.0     166.111.120.1   255.255.0.0     UG        0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth1
0.0.0.0         121.52.160.17   0.0.0.0         UG        0 0          0 eth1

(3)修改策略路由脚本。

/sbin/ip route add 0/0 via 121.52.160.17 table 120
/sbin/ip rule add from 121.52.160.29 table 120 pref 100



 



(责任编辑:IT)