linux系统单网卡绑定多个IP地址


linux系统单网卡绑定多个IP地址
 
说明:
单网卡绑定两个IP地址,电信和联通,目的:是为了当电信出故障联通正常使用。
 
系 统
IP地址
子网掩码
网关
 
CentOS 6.3_64bit
eth0:116.18.176.19
255.255.255.0
192.168.1.1
eth0:0:172.188.174.20
255.255.255.0
192.168.1.1
 
1、linux的网络设备的存储路径是/etc/sysconfig/network-scripts进入目录:
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ll
total 196
-rw-r--r--. 1 root root   212 Mar 20 22:15 ifcfg-eth0
 
2、在/etc/sysconfig/network-scripts 目录上创建一个ifcfg-eth0:x(x可以为0,1,2.......)。
为了简便我们可以讲ifcfg-eth0,复制一份命名为ifcfg-eth0:0即可,然后修改配置文件。  
[root@localhost network-scripts]# cp ifcfg-eth0.0 ifcfg-eth0:0
  
3、编辑ifcfg-eth0:0 虚拟IP
[root@localhost network-scripts]# vim ifcfg-eth0:0
 
DEVICE="eth0:0"            //修改设备的名称
BOOTPROTO="static"       //[none|static|bootp|dhcp](引导时不使用协议|静态分
配|BOOTP协议|DHCP协议)
IPADDR=172.188.174.20         //修改IP地址
NETMASK=255.255.255.0      //子网掩码
GATEWAY=192.168.1.1        //网关
BROADCAST='192.168.1.255'    //广播地址
HWADDR="00:0C:29:C9:6D:11"  //MAC地址
NM_CONTROLLED="yes"
ONBOOT="yes"               //开机激活
:wq
 
如果需要再绑定多一个IP地址,只需要把文件名和文件内的DEVICE中的eth0:x加一即可。 
 
4、配置网卡DNS(电信和联通)
配置文件在/etc/resolv.conf下面。
vim /etc/resolv.conf
nameserver 202.109.14.5           #主DNS
nameserver 219.141.136.10         #次DNS
 
保存退出,然后运行如下的命令,重启虚拟的网卡。
[root@localhost network-scripts]# service network restart或/etc/init.d/network restart
 
5、我们来查看我们虚拟的网卡是不是激活了,用ifconfig,也就是下面这样的。
[root@localhost network-scripts]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:C9:6D:18 
          inet addr:116.18.176.19  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fec9:6d18/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1622 errors:0 dropped:0 overruns:0 frame:0
          TX packets:702 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:170181 (166.1 KiB)  TX bytes:122357 (119.4 KiB)
 
eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:C9:6D:18 
          inet addr:172.188.174.20  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 
lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
  
6、下面测试一下,另外一台计算机使用ping来测试
C:\Users\Administrator>ping 116.18.176.19
正在 Ping 116.18.176.19 具有 32 字节的数据:
来自 116.18.176.19 的回复: 字节=32 时间=16ms TTL=64
来自 116.18.176.19 的回复: 字节=32 时间=8ms TTL=255
来自 116.18.176.19 的回复: 字节=32 时间=8ms TTL=255
来自 116.18.176.19 的回复: 字节=32 时间=8ms TTL=255
 
C:\Users\Administrator>ping 172.188.174.20
正在 Ping 172.188.174.20 具有 32 字节的数据:
来自 172.188.174.20 的回复: 字节=32 时间=16ms TTL=64
来自 172.188.174.20 的回复: 字节=32 时间=8ms TTL=255
来自 172.188.174.20 的回复: 字节=32 时间=8ms TTL=255
来自 172.188.174.20 的回复: 字节=32 时间=8ms TTL=255
 
测试成功!
 
7、测试当eth0 网络中断eth0:0是否正常使用
C:\Users\Administrator>ping 116.18.176.19
正在 Ping 116.18.176.19 具有 32 字节的数据:
请求超时。
请求超时。
请求超时。
来自 192.168.1.2 的回复: 无法访问目标主机。
 
C:\Users\Administrator>ping 172.188.174.20
正在 Ping 172.188.174.20 具有 32 字节的数据:
来自 172.188.174.20 的回复: 字节=32 时间=16ms TTL=64
来自 172.188.174.20 的回复: 字节=32 时间=8ms TTL=255
来自 172.188.174.20 的回复: 字节=32 时间=8ms TTL=255
来自 172.188.174.20 的回复: 字节=32 时间=8ms TTL=255
 
测试成功!

相关内容

    暂无相关文章