具有绑定接口的多个 IP 地址

具有绑定接口的多个 IP 地址

我有一台具有两个以太网端口的服务器,并且我使用以下配置将它们绑定在一起/etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet manual
bond-master bond0

auto eth1
iface eth1 inet manual
bond-master bond0

auto bond0
iface bond0 inet static
address 192.168.0.300
gateway 192.168.0.1
netmask 255.255.255.0
dns-nameservers 8.8.8.8 8.8.4.4
bond-mode balance-rr
bond-miimon 100
bond-slaves eth0 eth1

因此,目前所有连接都通过 进行路由bond0。我需要另一个bond1可以在单独的 IP 地址(例如 )上运行的接口192.168.0.301

我知道为了仅通过界面实现这一点eth0,我需要添加:

auto eth0:0
iface eth0:0 inet static
(and so on)

但是我该如何使用网络绑定来解决这个问题?类似于bond0:0bond0:1也许?或者bond0bond1但是创建 4 个总共的网络接口,例如:eth0:0 eth1:0eth0:1eth1:1并将它们用作两个单独绑定的各自从属?有点令人困惑,但任何帮助都将不胜感激!

答案1

由于我自己遇到过这个问题,并且关于它的信息很少,所以这里是 /etc/network/interfaces 文件的“正确”解决方案:

auto bond0
iface bond0 inet static
    address 192.168.0.5
    netmask 255.255.255.0
    gateway 192.168.0.1
    bond-mode 802.3ad
    bond-miimon 100
    bond-updelay 200
    bond-downdelay 200
    bond-lacp-rate 1
    bond-slaves eth0 eth1

auto bond0:1
iface bond0:1 inet static
    address 192.168.10.160
    netmask 255.255.255.0

它的工作原理与 eth0 等常规接口几乎相同,但您不能重复绑定配置 - 只能在 bond0 配置中重复。然后,您可以根据需要添加任意数量的其他 IP 地址,例如 bond0:2、bond0:3 等。

如果您还想添加 IPv6 地址,情况又会有所不同,因为您需要添加这个(作为示例):

iface bond0 inet6 static
    address 2eee:354:3a3::745
    netmask 64
    gateway 2eee:354:3a3::1

IPv6 不需要 bond0:1 或类似的解决方法 - 只需对每个地址使用 bond0。它使用 IPv4 地址的绑定设置,就像第二个 IPv4 地址一样。而且您不需要为其他 IPv6 地址重复网关部分,只需对第二个 IPv6 地址使用addressnetmask

更改接口文件后,您应该执行以下命令来完全重新启动网络并加载这些更改:

ip address flush eth0
ip address flush eth1
systemctl restart networking

这将从 eth0 和 eth1 中删除所有 IP 地址,然后使用新配置重新启动网络。请确保您已本地登录到计算机,因为您需要在重新启动之前完全关闭网络,因此所有连接都将丢失。

答案2

我使用的是您想要的设置,但在 CentOS 上。我相信只要我向您展示它在 CentOS 中的工作原理,您就能弄清楚如何将其转换为 ubuntu 配置。我的设置如下:

ifcfg-eth4

DEVICE=eth4
BOOTPROTO=none
HWADDR=00:0F:FE:E4:A4:CF
ONBOOT=yes
HOTPLUG=no
SLAVE=yes
MASTER=bond2

ifcfg-bond2

DEVICE=bond2
BOOTPROTO=none
IPADDR=192.168.20.1
NETMASK=255.255.0.0
ONBOOT=yes
TYPE=bonding
MASTER=yes
BONDING_OPTS="miimon=100 mode=1" 

ifcfg-bond2:1

DEVICE=bond2:1
BOOTPROTO=none
IPADDR=192.168.41.1
NETMASK=255.255.0.0
ONBOOT=yes
TYPE=bonding
MASTER=yes
BONDING_OPTS="miimon=100 mode=1" 

因此,针对您的情况,我会尝试以下方法:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet manual
bond-master bond0

auto eth1
iface eth1 inet manual
bond-master bond0

auto bond0
iface bond0 inet static
address 192.168.0.300
gateway 192.168.0.1
netmask 255.255.255.0
dns-nameservers 8.8.8.8 8.8.4.4
bond-mode balance-rr
bond-miimon 100
bond-slaves eth0 eth1

auto bond0:1
iface bond0 inet static
address 192.168.1.300
gateway 192.168.1.1
netmask 255.255.255.0
dns-nameservers 8.8.8.8 8.8.4.4
bond-mode balance-rr
bond-miimon 100
bond-slaves eth0 eth1

试试看。

相关内容