一、链路聚合
网卡的绑定
链路聚合接口
(1)添加链路接口
在添加链路接口之前需满足虚拟机有两个网卡以供实验并清掉网卡上配置的ip
查看网卡
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:bc:be:27 txqueuelen 1000 (Ethernet)
RX packets 596 bytes 31224 (30.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:88:4e:f3 txqueuelen 1000 (Ethernet)
RX packets 18 bytes 1130 (1.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 24 bytes 2120 (2.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 24 bytes 2120 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:20:94:8d txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
(2)添加链路
注意:一个设备上只能有一个链路,当生成链路时会随之生成一个ip,若之前生成链路时不小心写错,需将原来错的链路删除再生成新的链路(nm-connection-editor)
(3)查看链路
(4)监控链路与网卡
查看链路与网卡
(5)添加硬件到网卡
(6)此时可以在真机上ping给链路添加的ip,此时链路上添加了两块硬盘(eth0/eth1),若将eth0down掉(ifconfig eth0 down)ping结束。
将eth1加入链路,此时eth0正在使用,eth1备用
[root@localhost ~]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 52:54:00:bc:be:27
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
若将eth0 down掉,eth1成为主工作网卡
[root@localhost ~]# ifconfig eth0 down
[root@localhost ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: down ##eth0是down掉的
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 52:54:00:bc:be:27
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 52:54:00:88:4e:f3
Slave queue ID: 0
[root@localhost ~]#
恢复eth0,eth0为备用网卡
[root@localhost ~]# ifconfig eth0 up
[root@localhost ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 52:54:00:bc:be:27
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 52:54:00:88:4e:f3
Slave queue ID: 0
[root@localhost ~]#
(7)查看链路及硬件连接
2、文本编辑方式
删除之前建立的链路以及网卡连接
(1)建立链路编辑文件
[root@localhost network-scripts]# vim ifcfg-bond0
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ifconfig
bond0: flags=5123<UP,BROADCAST,MASTER,MULTICAST> mtu 1500
inet 172.25.254.155 netmask 255.255.255.0 broadcast 172.25.254.255
ether 92:3b:d9:0f:57:d0 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:bc:be:27 txqueuelen 1000 (Ethernet)
RX packets 1921 bytes 100248 (97.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 36 bytes 4924 (4.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:88:4e:f3 txqueuelen 1000 (Ethernet)
RX packets 1376 bytes 75033 (73.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3 bytes 182 (182.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 24 bytes 2120 (2.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 24 bytes 2120 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:20:94:8d txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost network-scripts]#
(2)设置网卡文件,将网卡添加至链路
[root@localhost network-scripts]# vim ifcfg-eth0
(3)查看链路与网卡
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# nmcli connection show
NAME UUID TYPE DEVICE
Bond bond0 ad33d8b0-1f7b-cab9-9447-ba07f855b143 bond bond0
System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 802-3-ethernet eth0
System eth1 9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04 802-3-ethernet eth1
virbr0 3db95441-f28c-4494-8cf2-6a889405b8fc bridge virbr0
[root@localhost network-scripts]#
二。tem格式
设置tem链路方式之前需将bond方式删除
(1)添加team链路
(2)查看链路
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:bc:be:27 txqueuelen 1000 (Ethernet)
RX packets 2473 bytes 129852 (126.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 45 bytes 5960 (5.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:88:4e:f3 txqueuelen 1000 (Ethernet)
RX packets 1931 bytes 104352 (101.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9 bytes 1257 (1.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 24 bytes 2120 (2.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 24 bytes 2120 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
team0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.25.254.155 netmask 255.255.255.0 broadcast 172.25.254.255
ether 3e:84:26:76:b0:52 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:20:94:8d txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]#
(3)监控链路信息
[root@localhost ~]# teamdctl team0 stat
setup:
runner: activebackup
runner:
active port:
[root@localhost ~]#
此时链路与硬盘无任何关系,将硬盘和链路连接起来
[root@localhost ~]# nmcli connection add con-name eth0 ifname eth0 type team-slave master team0
Connection 'eth0' (985f8328-0b61-432f-97da-e021c91c6d0a) successfully added.
[root@localhost ~]# nmcli connection add con-name eth1 ifname eth1 type team-slave master team0
Connection 'eth1' (7c5f2413-7430-4253-b85f-e46047ac1b94) successfully added.
[root@localhost ~]#
[root@localhost ~]# teamdctl team0 statsetup:
runner: activebackup
ports:
eth0
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
eth1
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
runner:
active port: eth0
[root@localhost ~]#
(4)文本方式创建team链路
将之前创建的team链路删除
[root@localhost ~]# nmcli connection
NAME UUID TYPE DEVICE
eth1 695df1fd-a065-40c3-8698-4166f857cc7c 802-3-ethernet eth1
eth0 2b937281-3ab7-43fa-8212-a973e4005c22 802-3-ethernet eth0
team0 3745233e-b7d0-47c4-ae8c-bf65a99c299c team team0
[root@localhost ~]# nmcli connection delete team0
[root@localhost ~]# nmcli connection show
NAME UUID TYPE DEVICE
eth1 695df1fd-a065-40c3-8698-4166f857cc7c 802-3-ethernet --
eth0 2b937281-3ab7-43fa-8212-a973e4005c22 802-3-ethernet --
[root@localhost ~]# nmcli connection delete eth0
[root@localhost ~]# nmcli connection delete eth1
[root@localhost ~]# nmcli connection show
NAME UUID TYPE DEVICE
[root@localhost ~]#
(2)文本创建链路
[root@localhost network-scripts]# vim ifcfg-team0
[root@localhost network-scripts]#
(3)查看链路
[root@localhost network-scripts]# teamdctl team0 stat
setup:
runner: activebackup
runner:
active port:
[root@localhost network-scripts]#
(4)将硬件添加进链路
[root@localhost network-scripts]# vim ifcfg-eth0
[root@localhost network-scripts]#
(5)查看
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# teamdctl team0 stat
setup:
runner: activebackup
ports:
eth0
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
runner:
active port: eth0
[root@localhost network-scripts]#
3、桥接
删除原来的网络配置,包含wifi
重新设置桥接
[root@localhost network-scripts]# vim ifcfg-enp0s25
网桥的作用
(1)网卡配置
先看虚拟机安装的时候有没有通过桥接建立(虚拟机使用的是真机的桥接,刚才全部删除,所以此时没有br0
[root@localhost network-scripts]# virt-manager
[root@localhost network-scripts]#
打开虚拟机—灯泡—看网卡—Network source没有桥接(br0)
现在建立桥接
[root@localhost network-scripts]# vim ifcfg-enp0s25
[root@foundation33 network-scripts]#
(2)配置br0
[root@localhost network-scripts]# vim ifcfg-br0
(3)显示桥接控制
[root@localhost network-scripts]# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.55 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::221:ccff:fe6e:d458 prefixlen 64 scopeid 0x20<link>
ether 00:21:cc:6e:d4:58 txqueuelen 0 (Ethernet)
RX packets 66 bytes 3125 (3.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 29 bytes 4226 (4.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s25: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:21:cc:6e:d4:58 txqueuelen 1000 (Ethernet)
RX packets 472755 bytes 204334008 (194.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 87283 bytes 6744710 (6.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 20 memory 0xf2500000-f2520000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 1156380 bytes 418713609 (399.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1156380 bytes 418713609 (399.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:f6:38:fa txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:75:6d:fd txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp3s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 08:11:96:b9:a2:44 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost network-scripts]#
(4)再次查看虚拟机网络源设置
打开虚拟机—灯泡—看网卡—Network source有桥接(br0)
手动建立网桥
进入虚拟机,删除之前所有网络设置
(1)手动建立
[root@localhost network-scripts]# ifconfig
enp2s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 20:1a:06:3d:ef:79 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 87 bytes 11658 (11.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 87 bytes 11658 (11.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:aa:5c:55 txqueuelen 1000 (Ethernet)
RX packets 117 bytes 12715 (12.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6 bytes 748 (748.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:febc:be27 prefixlen 64 scopeid 0x20<link>
ether fe:54:00:bc:be:27 txqueuelen 1000 (Ethernet)
RX packets 107 bytes 12917 (12.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4131 bytes 216072 (211.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:fe88:4ef3 prefixlen 64 scopeid 0x20<link>
ether fe:54:00:88:4e:f3 txqueuelen 1000 (Ethernet)
RX packets 10 bytes 1436 (1.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3651 bytes 197549 (192.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp3s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 2a:fa:50:e1:89:e1 txqueuelen 1000 (Ethernet)
RX packets 12227 bytes 1757619 (1.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1989 bytes 224076 (218.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost network-scripts]#
(2)添加桥接
[root@localhost ~]# brctl addbr br0
(2)给网桥添加网卡
[root@localhost ~]# ifconfig br0 172.25.254.55/24
[root@localhost ~]# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.55 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::88a1:11ff:feb9:ef81 prefixlen 64 scopeid 0x20<link>
ether 8a:a1:11:b9:ef:81 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30 bytes 4403 (4.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp2s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 20:1a:06:3d:ef:79 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 87 bytes 11658 (11.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 87 bytes 11658 (11.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 52:54:00:aa:5c:55 txqueuelen 1000 (Ethernet)
RX packets 117 bytes 12715 (12.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6 bytes 748 (748.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:febc:be27 prefixlen 64 scopeid 0x20<link>
ether fe:54:00:bc:be:27 txqueuelen 1000 (Ethernet)
RX packets 107 bytes 12917 (12.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4233 bytes 221376 (216.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:fe88:4ef3 prefixlen 64 scopeid 0x20<link>
ether fe:54:00:88:4e:f3 txqueuelen 1000 (Ethernet)
RX packets 10 bytes 1436 (1.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3753 bytes 202853 (198.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp3s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether c6:68:1f:17:fc:b8 txqueuelen 1000 (Ethernet)
RX packets 12227 bytes 1757619 (1.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1989 bytes 224076 (218.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]#
(4)显示桥接
[root@localhost Desktop]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 no
[root@localhost Desktop]# brctl addif br0 eth0 ##将网卡添加进网桥
[root@localhost Desktop]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.52540000210b no eth0
[root@localhost Desktop]#