Ubuntu 20.04 配置多网卡链路聚合
阅读原文时间:2023年07月09日阅读:1

多网卡IP配置

  1. 首先查看网卡信息

    root@it:~# ip add
    1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
    valid_lft forever preferred_lft forever
    2: eth0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:2d:79:40 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.21/24 brd 192.168.121.255 scope global eth0
    valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe2d:7940/64 scope link
    valid_lft forever preferred_lft forever
    3: eth1: mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:0c:29:2d:79:4a brd ff:ff:ff:ff:ff:ff
    4: eth2: mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:0c:29:2d:79:54 brd ff:ff:ff:ff:ff:ff

  • 等会需要添加 eth1eth2 IP信息
  1. /etc/netplan/ 目录下的 00-installer-config.yaml (该文件每个人都会不一样)

    root@it:~# vim /etc/netplan/00-installer-config.yaml

    This is the network config written by 'subiquity'

    network:
    version: 2
    ethernets:
    eth0:
    addresses:
    - 192.168.121.21/24
    gateway4: 192.168.121.2
    nameservers:
    addresses:
    - 8.8.8.8

    eth1:
      addresses:
        - 192.168.121.22/24
      gateway4: 192.168.121.2
      nameservers:
        addresses:
          - 114.114.114.114
    
    eth2:
      addresses:
        - 192.168.121.23/24
      gateway4: 192.168.121.2
      nameservers:
        addresses:
          - 114.114.144.144
  2. 加载配置

    root@it:~# netplan apply
    root@it:~# ip add
    1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
    valid_lft forever preferred_lft forever
    2: eth0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:2d:79:40 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.21/24 brd 192.168.121.255 scope global eth0
    valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe2d:7940/64 scope link
    valid_lft forever preferred_lft forever
    3: eth1: mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:2d:79:4a brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.22/24 brd 192.168.121.255 scope global eth1
    valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe2d:794a/64 scope link
    valid_lft forever preferred_lft forever
    4: eth2: mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:2d:79:54 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.23/24 brd 192.168.121.255 scope global eth2
    valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe2d:7954/64 scope link tentative
    valid_lft forever preferred_lft forever

多网卡链路聚合配置

  1. 查看绑定的网卡信息

    root@it:~# ip add
    1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
    valid_lft forever preferred_lft forever
    2: eth0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:2d:79:40 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.21/24 brd 192.168.121.255 scope global eth0
    valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe2d:7940/64 scope link
    valid_lft forever preferred_lft forever
    3: eth1: mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:0c:29:2d:79:4a brd ff:ff:ff:ff:ff:ff
    4: eth2: mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:0c:29:2d:79:54 brd ff:ff:ff:ff:ff:ff

  2. /etc/netplan/ 目录下新建一个以 .yaml 结尾的文件

    root@it:~# cd /etc/netplan/
    root@it:/etc/netplan# touch bond.yaml

  3. 编辑该文件

    root@it:/etc/netplan# vim bond.yaml
    network:
    version: 2
    ethernets:
    eth1:
    addresses: [] #绑定单网卡不需要写IP地址
    dhcp4: no
    eth2:
    addresses: []
    dhcp4: no

    bonds:
    bond0:
    addresses:
    - 192.168.121.100/24
    gateway4: 192.168.121.2
    nameservers:
    addresses:
    - 114.114.114.114
    interfaces:
    - eth1
    - eth2
    parameters: #参数
    mode: balance-rr #bond模式

  4. 加载配置

    root@it:/etc/netplan# netplan apply
    root@it:/etc/netplan# ip add
    1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
    valid_lft forever preferred_lft forever
    2: eth0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:2d:79:40 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.21/24 brd 192.168.121.255 scope global eth0
    valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe2d:7940/64 scope link
    valid_lft forever preferred_lft forever
    3: eth1: mtu 1500 qdisc fq_codel master bond0 state UP group default qlen 1000
    link/ether 3e:ba:29:6c:0d:e4 brd ff:ff:ff:ff:ff:ff
    4: eth2: mtu 1500 qdisc fq_codel master bond0 state UP group default qlen 1000
    link/ether 3e:ba:29:6c:0d:e4 brd ff:ff:ff:ff:ff:ff
    5: bond0: mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 3e:ba:29:6c:0d:e4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.100/24 brd 192.168.121.255 scope global bond0
    valid_lft forever preferred_lft forever
    inet6 fe80::3cba:29ff:fe6c:de4/64 scope link
    valid_lft forever preferred_lft forever

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器