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
相关推荐
wadesir10 小时前
Nginx配置文件CPU优化(从零开始提升Web服务器性能)
服务器·前端·nginx
白狐_79811 小时前
网络基础核心问题深度解析:从IP/MAC到IPv6与路由配置
网络·tcp/ip·macos
板鸭〈小号〉11 小时前
应用层协议 HTTP
网络·网络协议·http
SoleMotive.11 小时前
1、nginx反向代理了解吗?怎么配置nginx服务器?nginx负载均衡的算法都有哪些? 2、后端服务器宕机了,nginx服务器是怎么检查的
服务器·nginx·负载均衡
陶庵看雪11 小时前
服务器纳管:核心概念与全流程解析
运维·服务器
xuanzdhc11 小时前
Gitgit
java·linux·运维·服务器·c++·git
laocooon52385788611 小时前
win下制作一个简单的Cmake,完成运行效果
linux·运维·服务器
北顾南栀倾寒11 小时前
[杂学笔记]HTTP与HTTPS的区别、HTTPS进行TLS握手的过程、HTTPS如何防止中间人攻击、HTTP1.1与HTTP2.0的区别、TCP的拥塞控制
linux·服务器
拾忆,想起11 小时前
Dubbo服务超时与重试策略配置指南:构建 resilient 微服务架构
服务器·网络·微服务·云原生·架构·dubbo
MarkHD11 小时前
车辆TBOX科普 第28次 AT命令集与移动通信技术入门:从基础到4G/5G网络详解
网络·5g