linux系統單網卡綁定多個IP地址 說明:單網卡綁定兩個IP地址,電信和聯通,目的:是為了當電信出故障聯通正常使用。 系 統IP地址子網路遮罩網關 CentOS 6.3_64biteth0:116.18.176.19255.255.255.0192.168.1.1eth0:0:172.188.174.20255.255.255.0192.168.1.1……… 1、linux的網路裝置的儲存路徑是/etc/sysconfig/network-scripts進入目錄:[root@localhost ~]# cd /etc/sysconfig/network-scripts/[root@localhost network-scripts]# lltotal 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.confnameserver 202.109.14.5 #主DNSnameserver 219.141.136.10 #次DNS 儲存退出,然後運行如下的命令,重啟虛擬網卡。[root@localhost network-scripts]# service network restart或/etc/init.d/network restart 5、我們來查看我們虛擬網卡是不是啟用了,用ifconfig,也就是下面這樣的。[root@localhost network-scripts]# ifconfigeth0 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 測試成功!