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
    
相关推荐
添砖java_85710 分钟前
TCP流套接字编程
网络·网络协议·tcp/ip
ZachOn1y16 分钟前
计算机网络:运输层 —— TCP 的超时重传机制
网络·网络协议·tcp/ip·计算机网络·tcp·超时重传
稻草人ZZ1 小时前
Keepalived部署
linux·服务器·网络·keepalived
黑客Ash1 小时前
网络安全提示
网络·安全·web安全
乐维_lwops1 小时前
双因子认证:统一运维平台安全管理策略
运维·服务器·安全
叫我龙翔1 小时前
【项目日记】仿mudou的高并发服务器 --- 实现缓冲区模块,通用类型Any模块,套接字模块
linux·运维·服务器·网络·c++
Learning改变世界2 小时前
ubuntu24.04下Matlab安装踩坑记录
ubuntu·matlab
程序员洲洲2 小时前
使用青果代理IP爬取豆瓣TOP250电影数据
网络·网络协议·tcp/ip
Huazzi.2 小时前
免费好用的静态网页托管平台全面对比介绍
前端·网络·github·web