Ubuntu 22.04.5 配置vlan子接口和网桥

使用bond为物理接口,bond配置可以参考:https://blog.csdn.net/qq_50247813/article/details/143630081

实验一、配置vlan子接口

  1. 创建bond0,模式为802.3ad;从网卡,ens37,ens38,添加子接口 bond0.10,配置vlanid 10

    root@ubuntu22:/etc/netplan# cat bond0.yaml
    network:
        version: 2
        renderer: networkd
        ethernets:
          ens37:
            addresses: []
            dhcp4: no
            optional: true
          ens38:
            addresses: []
            dhcp4: no
            optional: true
        bonds:
          bond0:
            interfaces: [ens37,ens38]
            parameters:
              mode: 802.3ad
              lacp-rate: fast
              mii-monitor-interval: 100
              transmit-hash-policy: layer3+4
        vlans:
          bond0.10:
            id: 10
            link: bond0
            addresses: [192.168.1.100/24]
            routes:
              - to: 0.0.0.0
                via: 192.168.1.1
            nameservers:
              addresses: [114.114.114.114]
    
  2. 查看子接口和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 1000
        link/ether 1a:40:de:5e:c3:0c brd ff:ff:ff:ff:ff:ff
        inet 192.168.1.100/24 brd 192.168.1.255 scope global bond0.10
           valid_lft forever preferred_lft forever
        inet6 fe80::1840:deff:fe5e:c30c/64 scope link
           valid_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
    

实验二、创建网桥

  1. 正常绑定接口

    root@ubuntu22:/etc/netplan# cat br0.yaml
    network:
        version: 2
        renderer: networkd
        ethernets:
          ens37:
            addresses: []
            dhcp4: no
            optional: true
          ens38:
            addresses: []
            dhcp4: no
            optional: true
        bonds:
          bond0:
            interfaces: [ens37,ens38]
            parameters:
              mode: 802.3ad
              lacp-rate: fast
              mii-monitor-interval: 100
              transmit-hash-policy: layer3+4
        bridges:
          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 1500
            inet 192.168.119.130  netmask 255.255.255.0  broadcast 192.168.119.255
            inet6 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 0
            TX packets 493  bytes 60078 (60.0 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    root@ubuntu22:/etc/netplan# brctl show
    bridge name     bridge id               STP enabled     interfaces
    br0             8000.7e7aa7cbde52       no              bond0
    
  2. 绑定子接口

    root@ubuntu22:/etc/netplan# cat br0.yaml
    network:
        version: 2
        renderer: networkd
        ethernets:
          ens37:
            addresses: []
            dhcp4: no
            optional: true
          ens38:
            addresses: []
            dhcp4: no
            optional: true
        bonds:
          bond0:
            interfaces: [ens37,ens38]
            parameters:
              mode: 802.3ad
              lacp-rate: fast
              mii-monitor-interval: 100
              transmit-hash-policy: layer3+4
        vlans:
          bond0.10:
            id: 10
            link: bond0
            addresses: []
        bridges:
          br0:
            interfaces: [bond0.10]
            dhcp4: no
            addresses: [192.168.1.100/24]
            routes:
              - to: 0.0.0.0
                via: 192.168.1.1
            nameservers:
              addresses: [8.8.8.8]
    

    这里和配置vlan 子接口配置很像,但是配置网桥,子接口地址就无需要配置,地址配置在网桥上,子接口作为网桥的一个端口。

    查看接口、vlan、网桥信息

    root@ubuntu22:/etc/netplan# ifconfig br0
    br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 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 0
            TX packets 28  bytes 2400 (2.4 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    root@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
    
相关推荐
涔溪30 分钟前
HTTP TCP三次握手深入解析
网络·tcp/ip·http
憨子周31 分钟前
2M的带宽怎么怎么设置tcp滑动窗口以及连接池
java·网络·网络协议·tcp/ip
三菱-Liu1 小时前
三菱MR-J4-B伺服连接器和信号排列
网络·驱动开发·硬件工程·制造·mr
WeeJot嵌入式2 小时前
网络安全:挑战、策略与未来趋势
网络
Ztiddler4 小时前
【Linux Shell命令-不定期更新】
linux·运维·服务器·ssh
小小不董4 小时前
Oracle OCP认证考试考点详解082系列16
linux·运维·服务器·数据库·oracle·dba
IPdodo全球网络5 小时前
如何利用静态住宅IP优化Facebook商城的网络稳定性与运营效率
运维·服务器
a1denzzz5 小时前
Linux系统的网络设置
linux·服务器·网络
黑客K-ing6 小时前
网络安全名词解释
开发语言·网络·安全·网络安全·php
zyp2468106 小时前
Linux之DNS服务器
linux·运维·服务器