首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

Linux 上 网卡绑定ip

2012-11-14 
Linux 下 网卡绑定ip一、多网卡绑定1个ip1. 新建ifcfg-bond0[root@dex network-scripts]# cd /etc/sysconfi

Linux 下 网卡绑定ip

一、多网卡绑定1个ip

1. 新建ifcfg-bond0

[root@dex network-scripts]# cd /etc/sysconfig/network-scripts/
[root@dex network-scripts]# cp ifcfg-eth0 ifcfg-bond0
[root@dex network-scripts]# vi ifcfg-bond0 
加入如下内容
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=bond0
BOOTPROTO=none
BROADCAST=192.168.100.255
IPADDR=192.168.100.12
NETMASK=255.255.255.0
NETWORK=192.168.100.0
ONBOOT=yes
2. 修改ifcfg-eth0 ifcfg-eth1
[root@dex network-scripts]# vi ifcfg-eth0
修改为如下内容
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
[root@dex network-scripts]# cp ifcfg-eth0 ifcfg-eth1
[root@dex network-scripts]# vi ifcfg-eth1
修改为如下内容
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
3. 修改/etc/modprobe.conf文件
[root@dex network-scripts]# vi /etc/modprobe.conf
加入如下两行
alias bond0 bonding
options bond0 miimon=100 mode=1




mode=0 表示两块网卡同时工作,提供负载均衡
mode=1 表示提供冗余功能(主备模式)


4. 重启服务
[root@dex network-scripts]# service network restart
查看一下
[root@dex network-scripts]# ifconfig -a
bond0     Link encap:Ethernet  HWaddr 00:0C:29:AE:CF:7F  
          inet addr:192.168.100.12  Bcast:192.168.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:3396 errors:0 dropped:0 overruns:0 frame:0
          TX packets:753 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:237786 (232.2 KiB)  TX bytes:86115 (84.0 KiB)


eth0      Link encap:Ethernet  HWaddr 00:0C:29:AE:CF:7F  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:1201 errors:0 dropped:0 overruns:0 frame:0
          TX packets:694 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:76776 (74.9 KiB)  TX bytes:79243 (77.3 KiB)


eth1      Link encap:Ethernet  HWaddr 00:0C:29:AE:CF:7F  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:2195 errors:0 dropped:0 overruns:0 frame:0
          TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:161010 (157.2 KiB)  TX bytes:6872 (6.7 KiB)


lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2045 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2045 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:3201608 (3.0 MiB)  TX bytes:3201608 (3.0 MiB)
绑定结束




尝试着拔掉一个网线,看看结果怎样。



VM中只能做mode=1



二、单网卡绑定多个ip



这一步很简单,只要添加一个配置文件即可

[root@james-test ~]# cd /etc/sysconfig/network-scripts

[root@james-test network-scripts]# cp ifcfg-eth0 ifcfg-eth0:3

[root@james-test network-scripts]# vi ifcfg-eth0:3

# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0:3
BOOTPROTO=static
BROADCAST=192.168.100.255
HWADDR=00:0C:29:90:B5:80
IPADDR=192.168.100.7
IPV6INIT=yes
IPV6_AUTOCONF=yes
NETMASK=255.255.255.0
NETWORK=192.168.100.0
ONBOOT=yes

[root@james-test network-scripts]# service network restart
Shutting down interface eth0:  [  OK  ]
Shutting down loopback interface:  [  OK  ]
Bringing up loopback interface:  [  OK  ]
Bringing up interface eth0:  [  OK  ]

[root@james-test network-scripts]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0C:29:90:B5:80  
          inet addr:192.168.100.1  Bcast:192.168.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4080254 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2391945 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:604068660 (576.0 MiB)  TX bytes:3276087314 (3.0 GiB)
eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:90:B5:80  
          inet addr:192.168.100.8  Bcast:192.168.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
eth0:3    Link encap:Ethernet  HWaddr 00:0C:29:90:B5:80  
          inet addr:192.168.100.7  Bcast:192.168.100.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
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1357158 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1357158 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:126429892 (120.5 MiB)  TX bytes:126429892 (120.5 MiB)

或者直接使用ifconfig命令也可以

[root@james-test network-scripts]# ifconfig eth0:2 192.168.100.9
[root@james-test network-scripts]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0C:29:90:B5:80  
          inet addr:192.168.100.1  Bcast:192.168.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4080397 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2392060 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:604083446 (576.0 MiB)  TX bytes:3276102542 (3.0 GiB)
eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:90:B5:80  
          inet addr:192.168.100.8  Bcast:192.168.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
eth0:2    Link encap:Ethernet  HWaddr 00:0C:29:90:B5:80  
          inet addr:192.168.100.9  Bcast:192.168.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
eth0:3    Link encap:Ethernet  HWaddr 00:0C:29:90:B5:80  
          inet addr:192.168.100.7  Bcast:192.168.100.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
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1357194 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1357194 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:126433632 (120.5 MiB)  TX bytes:126433632 (120.5 MiB)




热点排行