第十三节
网卡绑定
nmcli方式
1.创建出一个bond网卡
网卡绑定模式:
1.balance-rr为轮循模式,特点是会根据设备顺序依次传输数据包,提供负载均衡的效果,让带宽的性能更好一些;而且一旦某个网卡发生故障,会马上切换到另外一台网卡设备上,保证网络传输不被中断。
2.active-backup为主备模式,它的特点是平时只有一块网卡正常工作,另一个网卡随时待命,一旦工作中的网卡发生损坏,待命的网卡会自动顶替上去。
[root@superwu network-scripts]# nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=balance-rr" //创建类型为bond名称为bond0网卡名为bond0的网卡,模式为balance-rr
Connection 'bond0' (d86a9dd3-dc78-4d47-b5fb-c2755be0f270) successfully added.
[root@superwu network-scripts]# ll
total 12
-rw-r--r--. 1 root root 324 Feb 15 18:02 ifcfg-bond0 //会自动生成一个网卡绑定的配置文件
-rw-r--r--. 1 root root 281 Jan 11 16:39 ifcfg-ens160
-rw-r--r--. 1 root root 293 Feb 15 17:54 ifcfg-ens192
[root@superwu network-scripts]# cat ifcfg-bond0
BONDING_OPTS=mode=balance-rr
TYPE=Bond
BONDING_MASTER=yes
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=bond0
UUID=d86a9dd3-dc78-4d47-b5fb-c2755be0f270
DEVICE=bond0
ONBOOT=yes
2.向bond网卡中添加从属网卡
[root@superwu network-scripts]# nmcli connection add type ethernet slave-type bond con-name bond0-one ifname ens160 master bond0 //向名称为bond0的bond网卡中添加从属网卡ens160 Connection 'bond0-one' (a66babb3-491c-45aa-a9c0-ad96c2136414) successfully added. //con-name后面接的是从属网卡的名称(可以自行设置),ifname参数接的是网卡的名称(物理存在的网卡) [root@superwu network-scripts]# nmcli connection add type ethernet slave-type bond con-name bond0-two ifname ens192 master bond0 //向名称为bond0的bond网卡中添加从属网卡ens192 Connection 'bond0-two' (581e79ec-e045-44d5-bd02-dab08cf358a1) successfully added.
[root@superwu network-scripts]# ll total 20 -rw-r--r--. 1 root root 324 Feb 15 18:02 ifcfg-bond0 -rw-r--r--. 1 root root 119 Feb 15 18:40 ifcfg-bond0-one -rw-r--r--. 1 root root 119 Feb 15 18:41 ifcfg-bond0-two //会生成从属网卡配置文件 -rw-r--r--. 1 root root 281 Jan 11 16:39 ifcfg-ens160 -rw-r--r--. 1 root root 293 Feb 15 17:54 ifcfg-ens192 [root@superwu network-scripts]# cat ifcfg-bond0-one TYPE=Ethernet NAME=bond0-one UUID=a66babb3-491c-45aa-a9c0-ad96c2136414 DEVICE=ens160 ONBOOT=yes MASTER=bond0 //ens160网卡已经为bond0的从属网卡 SLAVE=yes
3.配置bond网卡信息
配置方式可以使用nmcli,nmtui,编辑配置文件等。
nmcli方式:
[root@superwu network-scripts]# nmcli connection modify bond0 ipv4.addresses 192.168.10.10/24 [root@superwu network-scripts]# nmcli connection modify bond0 ipv4.gateway 192.168.10.254 [root@superwu network-scripts]# nmcli connection modify bond0 ipv4.dns 192.168.10.254 [root@superwu network-scripts]# nmcli connection modify bond0 ipv4.method manual //模式为手动模式 [root@superwu network-scripts]# cat ifcfg-bond0 BONDING_OPTS=mode=balance-rr TYPE=Bond BONDING_MASTER=yes PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=bond0 UUID=d86a9dd3-dc78-4d47-b5fb-c2755be0f270 DEVICE=bond0 ONBOOT=yes IPADDR=192.168.10.10 PREFIX=24 GATEWAY=192.168.10.254 DNS1=192.168.10.254
4.启动bond网卡
[root@superwu network-scripts]# nmcli connection up bond0 Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6) [root@superwu network-scripts]# nmcli connection show NAME UUID TYPE DEVICE bond0 d86a9dd3-dc78-4d47-b5fb-c2755be0f270 bond bond0 ens160 9af34300-fc6a-494c-929d-f9037bf802af ethernet ens160 ens192 6dbbf7ec-1382-4d8c-83d2-61515e33fbd0 ethernet ens192 virbr0 932c9736-d139-4822-a5c1-8f8f907c27f5 bridge virbr0 bond0-one a66babb3-491c-45aa-a9c0-ad96c2136414 ethernet -- bond0-two 581e79ec-e045-44d5-bd02-dab08cf358a1 ethernet -- [root@superwu network-scripts]# nmcli device status DEVICE TYPE STATE CONNECTION bond0 bond connected bond0 ens160 ethernet connected ens160 ens192 ethernet connected ens192 virbr0 bridge connected virbr0 lo loopback unmanaged -- virbr0-nic tun unmanaged -- [root@superwu network-scripts]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:7b:9d:e7 brd ff:ff:ff:ff:ff:ff inet 192.168.183.133/24 brd 192.168.183.255 scope global dynamic noprefixroute ens160 valid_lft 730sec preferred_lft 730sec inet6 fe80::d496:6a1f:2d6f:f285/64 scope link noprefixroute valid_lft forever preferred_lft forever 3: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:7b:9d:f1 brd ff:ff:ff:ff:ff:ff inet 192.168.183.134/24 brd 192.168.183.255 scope global dynamic noprefixroute ens192 valid_lft 1179sec preferred_lft 1179sec inet6 fe80::bf0e:7ce3:e187:3eff/64 scope link noprefixroute valid_lft forever preferred_lft forever 4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000 link/ether 52:54:00:eb:ed:e6 brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000 link/ether 52:54:00:eb:ed:e6 brd ff:ff:ff:ff:ff:ff 6: bond0: <NO-CARRIER,BROADCAST,MULTICAST,MASTER,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000 link/ether de:4b:71:3a:d9:39 brd ff:ff:ff:ff:ff:ff inet 192.168.10.10/24 brd 192.168.10.255 scope global noprefixroute bond0 valid_lft forever preferred_lft forever