使用bond为物理接口,bond配置可以参考:https://blog.csdn.net/qq_50247813/article/details/143630081
实验一、配置vlan子接口
-
创建bond0,模式为802.3ad;从网卡,ens37,ens38,添加子接口 bond0.10,配置vlanid 10
root@ubuntu22:/etc/netplan# cat bond0.yaml network:version: 2renderer: networkdethernets:ens37:addresses: []dhcp4: nooptional: trueens38:addresses: []dhcp4: nooptional: truebonds:bond0:interfaces: [ens37,ens38]parameters:mode: 802.3adlacp-rate: fastmii-monitor-interval: 100transmit-hash-policy: layer3+4vlans:bond0.10:id: 10link: bond0addresses: [192.168.1.100/24]routes:- to: 0.0.0.0via: 192.168.1.1nameservers:addresses: [114.114.114.114]
-
查看子接口和vlan信息
root@ubuntu22:/etc/netplan# netplan apply root@ubuntu22:/etc/systemd# ip addr show bond0.10 6: bond0.10@bond0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000link/ether 1a:40:de:5e:c3:0c brd ff:ff:ff:ff:ff:ffinet 192.168.1.100/24 brd 192.168.1.255 scope global bond0.10valid_lft forever preferred_lft foreverinet6 fe80::1840:deff:fe5e:c30c/64 scope linkvalid_lft forever preferred_lft forever root@ubuntu22:/etc/systemd# cat /proc/net/vlan/ bond0.10 config root@ubuntu22:/etc/systemd# cat /proc/net/vlan/config VLAN Dev name | VLAN ID Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD bond0.10 | 10 | bond0
实验二、创建网桥
-
正常绑定接口
root@ubuntu22:/etc/netplan# cat br0.yaml network:version: 2renderer: networkdethernets:ens37:addresses: []dhcp4: nooptional: trueens38:addresses: []dhcp4: nooptional: truebonds:bond0:interfaces: [ens37,ens38]parameters:mode: 802.3adlacp-rate: fastmii-monitor-interval: 100transmit-hash-policy: layer3+4bridges:br0:interfaces: [bond0] # 将物理接口绑定到网桥dhcp4: yes # 如果希望通过DHCP获取IP地址# 如果使用静态IP地址,可以配置如下:# addresses: [192.168.1.100/24]# gateway4: 192.168.1.1# nameservers:# addresses: [8.8.8.8, 1.1.1.1]
查看网桥接口,已经网桥信息
root@ubuntu22:/etc/netplan# ifconfig br0 br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.119.130 netmask 255.255.255.0 broadcast 192.168.119.255inet6 fe80::7c7a:a7ff:fecb:de52 prefixlen 64 scopeid 0x20<link>ether 7e:7a:a7:cb:de:52 txqueuelen 1000 (Ethernet)RX packets 548 bytes 72415 (72.4 KB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 493 bytes 60078 (60.0 KB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0root@ubuntu22:/etc/netplan# brctl show bridge name bridge id STP enabled interfaces br0 8000.7e7aa7cbde52 no bond0
-
绑定子接口
root@ubuntu22:/etc/netplan# cat br0.yaml network:version: 2renderer: networkdethernets:ens37:addresses: []dhcp4: nooptional: trueens38:addresses: []dhcp4: nooptional: truebonds:bond0:interfaces: [ens37,ens38]parameters:mode: 802.3adlacp-rate: fastmii-monitor-interval: 100transmit-hash-policy: layer3+4vlans:bond0.10:id: 10link: bond0addresses: []bridges:br0:interfaces: [bond0.10]dhcp4: noaddresses: [192.168.1.100/24]routes:- to: 0.0.0.0via: 192.168.1.1nameservers:addresses: [8.8.8.8]
这里和配置vlan 子接口配置很像,但是配置网桥,子接口地址就无需要配置,地址配置在网桥上,子接口作为网桥的一个端口。
查看接口、vlan、网桥信息
root@ubuntu22:/etc/netplan# ifconfig br0 br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255inet6 fe80::7c7a:a7ff:fecb:de52 prefixlen 64 scopeid 0x20<link>ether 7e:7a:a7:cb:de:52 txqueuelen 1000 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 28 bytes 2400 (2.4 KB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0root@ubuntu22:/etc/netplan# cat /proc/net/vlan/config VLAN Dev name | VLAN ID Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD bond0.10 | 10 | bond0 root@ubuntu22:/etc/netplan# brctl show bridge name bridge id STP enabled interfaces br0 8000.7e7aa7cbde52 no bond0.10