Linux下网卡绑定 bond

查看网卡信息

[root@test ~]# nmcli dev
DEVICE     TYPE              STATE       
eth0       802-3-ethernet    connected   
eth1       802-3-ethernet    connected   -- IP 192.168.2.100
eth2       802-3-ethernet    connecting (getting IP configuration)

目的: 正在使用的网卡 eth1 eth2 .将eth1 the2 绑定为bond0

关闭NetworkManager服务

[root@test network-scripts]# chkconfig --list | grep NetworkManager
NetworkManager 	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@test network-scripts]# service NetworkManager stop
Stopping NetworkManager daemon:                            [  OK  ]
[root@test network-scripts]# chkconfig NetworkManager off
[root@test network-scripts]# chkconfig --list | grep NetworkManager
NetworkManager 	0:off	1:off	2:off	3:off	4:off	5:off	6:off
[root@test network-scripts]# 

进入/etc/modprobe.d 目录 。创建一个bonded设备 

echo "alias bond0 bonding" > /etc/modprobe.d/bonding.conf

备份原来的网卡配置文件,备份ifcfg-eth0 、ifcfg-eth1 。创建ifcfg-bond0 文件。并编辑ifcfg-eth0 ifcfg-eth1文件

[root@test network-scripts]# cp ifcfg-eth0 ifcfg-eth0_bak20180423
[root@test network-scripts]# cp ifcfg-eth1 ifcfg-eth1_bak20180423
[root@test network-scripts]# cp ifcfg-eth2 ifcfg-eth2_bak20180423

ifcfg-bond0文件的内容

# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE="bond0"
BONDING_OPTS="mode=1 miimon=100 primary=eth1"
NM_CONTROLLED="no"
IPADDR="192.168.2.100"
NETMASK="255.255.255.0"
GATEWAY="192.168.2.1"
ONBOOT="yes"

ifcfg-eth1 文件的内容

[root@test network-scripts]# cat ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
UUID=0578ea57-3027-43f3-a070-e3bd523e2810
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPV6INIT=no
HWADDR=08:00:27:3D:6D:C4
SLAVE=yes
MASTER=bond0
[root@test network-scripts]# 

ifcfg-eth2 文件的内容

[root@test network-scripts]# cat ifcfg-eth2
DEVICE=eth2
TYPE=Ethernet
UUID=291cc332-f718-4e56-9986-4fcbf5c7f66b
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
HWADDR=08:00:27:6A:01:30
IPV6INIT=no
SLAVE=yes
MASTER=bond0
[root@test network-scripts]# 

重启网络服务

[root@test network-scripts]# service network restart
Shutting down interface bond0:                             [  OK  ]
Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface bond0:  Determining if ip address 192.168.2.100 is already in use for device bond0...
                                                           [  OK  ]
Bringing up interface eth0:  
Determining IP information for eth0... done.
                                                           [  OK  ]
[root@test network-scripts]# 

查看IP地址

[root@test network-scripts]# ifconfig
bond0     Link encap:Ethernet  HWaddr 08:00:27:3D:6D:C4  
          inet addr:192.168.2.100  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe3d:6dc4/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:448 errors:0 dropped:29 overruns:0 frame:0
          TX packets:348 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:38157 (37.2 KiB)  TX bytes:44557 (43.5 KiB)

eth0      Link encap:Ethernet  HWaddr 08:00:27:6E:6D:78  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe6e:6d78/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:248 errors:0 dropped:0 overruns:0 frame:0
          TX packets:417 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:27391 (26.7 KiB)  TX bytes:37846 (36.9 KiB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:3D:6D:C4  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:2723 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1854 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:245368 (239.6 KiB)  TX bytes:232118 (226.6 KiB)

eth2      Link encap:Ethernet  HWaddr 08:00:27:3D:6D:C4  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:129 errors:0 dropped:29 overruns:0 frame:0
          TX packets:114 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:9081 (8.8 KiB)  TX bytes:26200 (25.5 KiB)

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:65536  Metric:1
          RX packets:86 errors:0 dropped:0 overruns:0 frame:0
          TX packets:86 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:8328 (8.1 KiB)  TX bytes:8328 (8.1 KiB)

[root@test network-scripts]# 

查看Mac地址 

[root@test ~]# ifconfig | grep HWaddr
bond0     Link encap:Ethernet  HWaddr 08:00:27:3D:6D:C4  
eth0      Link encap:Ethernet  HWaddr 08:00:27:6E:6D:78  
eth1      Link encap:Ethernet  HWaddr 08:00:27:3D:6D:C4  
eth2      Link encap:Ethernet  HWaddr 08:00:27:3D:6D:C4  
[root@test ~]# 

END

猜你喜欢

转载自blog.csdn.net/xxzhaobb/article/details/80047256