Linux

刪除從 /etc/network/interfaces (ifupdown) 創建的綁定介面?

  • December 5, 2019

我嘗試將兩個介面合二為一,創建了bond0,但發現它並不令人滿意。/etc/network/interfaces然後我恢復了對和執行的所有更改systemctl restart networking.service,但是綁定介面仍然存在(顯示在ifconfigip link命令中),我不得不執行ip link set bond0 downifconfig bond0 down強制將其踢出。如何在不重新啟動伺服器的情況下完全刪除此介面?

我在 Debian Buster 上。該文件最初是這樣的:

auto eno1
iface eno1 inet static
   # regular network settings like address, netmask, gateway etc.
auto eno2
iface eno2 inet static
   # regular network settings like address, netmask, gateway etc.

我通過將其更改為以下方式將兩個介面變成了一個鍵:

auto eno1
iface eno1 inet manual
   bond-master bond0
auto eno2
iface eno2 inet manual
   bond-master bond0

auto bond0
iface bond0 inet static
   # regular network settings like address, netmask, gateway etc.

與大多數其他介面一樣,管理綁定介面的現代命令在ip link這裡sysfs一起用於可能的少數事情,而不是通過(rt)netlink直接處理。在這種情況下

ip link delete dev bond0

移除綁定時仍然被奴役的任何介面都將被分離,因此無需先將其分離(使用ip link set DEVICE nomaster)。

執行相同操作的另一種sysfs方法是:

echo -bond0 > /sys/class/net/bonding_masters

綁定介面由ifenslave(8)命令行實用程序管理。

以下是手冊頁的摘錄:

NAME
    ifenslave -- Attach and detach slave network devices to a bonding device.

SYNOPSIS
    ifenslave [-acdfhuvV] [--all-interfaces] [--change-active] [--detach] [--force] [--help] [--usage] [--verbose] [--version] master slave ...

DESCRIPTION
    ifenslave is a tool to attach and detach slave network devices to a bonding device.  A bonding device will act like a normal Ethernet network device to the kernel,
    but will send out the packets via the slave devices using a simple round-robin scheduler.  This allows for simple load-balancing, identical to "channel bonding" or
    "trunking" techniques used in switches.

    The kernel must have support for bonding devices for ifenslave to be useful.

OPTIONS
    -a, --all-interfaces
            Show information about all interfaces.

    -c, --change-active
            Change active slave.

    -d, --detach
            Removes slave interfaces from the bonding device.

免責聲明:我沒有測試以下

要完全刪除bond0,我會:

  • ifconfig bond0 down
  • ifenslave -d bond0 eno1
  • ifenslave -d bond0 eno2
  • ̀rmmod綁定`

應該夠了。

引用自:https://unix.stackexchange.com/questions/555745