一个网关设置两个IP地址?

Ahm*_*med 7 networking static-ip nic

我想问一下是否可以通过一个网关设置来自同一子网的两个静态IP?如果是呢?

我感兴趣的在这里描述了多个上行链路/提供商的路由,但在我的情况下,我有来自一个提供商的两个 IP 地址,两者都在同一个子网上,当然我在两者上都可以访问互联网。

我有两个 NIC,但如果可能的话,我不介意使用一个。

任何想法表示赞赏!

Ahm*_*med 10

好的,它正在工作,在这里参考我是如何做到的,希望有人会发现它有用。

我在以下网站上找到了解决方案:

1-同一子网上的多个接口 2- Linux 中同一子网上的两个网络接口和两个 IP 地址

以及我在问题中引用的网站。

假设我有两个 IP 地址:网络 7.7.7.0 上的 7.7.7.4 和 7.7.7.5,它们有一个网关 7.7.7.1

我启用了 ARP 过滤:

# sysctl -w net.ipv4.conf.all.arp_filter=1
# echo "net.ipv4.conf.all.arp_filter = 1" >> /etc/sysctl.conf
Run Code Online (Sandbox Code Playgroud)

我将 /etc/network/interfaces 配置如下:

    # The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
   address 7.7.7.4
   network 7.7.7.0
   netmask 255.255.255.0
   broadcast 7.7.7.255
   up ip route add 7.7.7.0/24 dev eth0 src 7.7.7.4 table eth0table
   up ip route add default via 7.7.7.1 dev eth0 table eth0table
   up ip rule add from 7.7.7.4 table eth0table
   up ip route add 7.7.7.0/24 dev eth0 src 7.7.7.4

auto eth1
iface eth1 inet static
   address 7.7.7.5
   network 7.7.7.0
   netmask 255.255.255.0
   broadcast 7.7.7.255
   up ip route add 7.7.7.0/24 dev eth1 src 7.7.7.5 table eth1table
   up ip route add default via 7.7.7.1 dev eth1 table eth1table
   up ip rule add from 7.7.7.5 table eth1table
   up ip route add default via 7.7.7.1 dev eth1
   up ip route add 7.7.7.0/24 dev eth1 src 7.7.7.5
Run Code Online (Sandbox Code Playgroud)

我将以下两行添加到 /etc/iproute2/rt_tables

10 eth0table
20 eth1table
Run Code Online (Sandbox Code Playgroud)

我有 Ubuntu 12.04 LTS 服务器