网络绑定:从属网卡仍获得 DHCP

网络绑定:从属网卡仍获得 DHCP

我正在 Ubuntu Server 20.04 LTS 上以模式 0(balanced-rr)设置两个 1 GB 以太网网卡的绑定。

绑定工作正常,因为它出现在分配的 IP 地址上,我可以通过此地址通过 SSH 进入它。但是,每个绑定的从属 NIC 仍然分配有一个 DHCP 地址。

我该如何设置才能让该绑定仅具有 IP 地址?

以下是我的设置方法:

sudo apt-get install ifenslave
sudo modprobe bonding
Edited /etc/modules to add "bonding"

最后,编辑 /etc/network/interfaces 以包含以下内容:(注意,在我编辑它之前它是空白的)

# bond0 is the bonded NIC, can be used like a normal NIC
auto bond0
iface bond0 inet static
  address 10.16.0.91
  gateway 10.16.0.1
  netmask 255.255.0.0

  #mode 0 is balanced-rr
  bond-mode 0
  bond-miimon 100
  bond-slaves enp1s0 enp2s0

# enp1s0 connected to bond0
auto enp1s0
iface enp1s0 inet manual
  bond-master bond0

# enp2s0 connected to bond0
auto enp2s0
iface enp2s0 inet manual
 bond-master bond0

重启后,当我执行“ifconfig”时,它给出以下内容(我可以使用所有 3 个 IP)

bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 10.16.0.91  netmask 255.255.0.0  broadcast 10.16.255.255
        inet6 fe80::203:2dff:fe41:edae  prefixlen 64  scopeid 0x20<link>
        ether 00:03:2d:41:ed:ae  txqueuelen 1000  (Ethernet)
        RX packets 356  bytes 29976 (29.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 110  bytes 16969 (16.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp1s0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        inet 10.16.100.143  netmask 255.255.0.0  broadcast 10.16.255.255
        ether 00:03:2d:41:ed:ae  txqueuelen 1000  (Ethernet)
        RX packets 252  bytes 23651 (23.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 76  bytes 8779 (8.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0x91300000-913fffff

enp2s0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        inet 10.16.100.142  netmask 255.255.0.0  broadcast 10.16.255.255
        ether 00:03:2d:41:ed:ae  txqueuelen 1000  (Ethernet)
        RX packets 240  bytes 19975 (19.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 75  bytes 12250 (12.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0x91100000-911fffff

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 85  bytes 6400 (6.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 85  bytes 6400 (6.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

如何防止从属接口获取自己的 DHCP 地址?

答案1

由于您将使用ifupdown来控制网卡,因此netplan.io不再需要使用。它将与ifupdown导致额外 IP 地址等问题发生冲突。

sudo apt remove netplan.io

希望这可以帮助!

相关内容