在debian挤压服务器上,我在eth0(eth0和eth0:1)上有2个IP。 打开TCP连接时,服务器默认使用eth0:1 IP。 但是我希望它使用主(eth0)IP,因为我希望另一个只用于(监听)守护进程。
#/etc/network/interfaces auto eth0 iface eth0 inet static address 92.xxx.xxx.92 netmask 255.255.255.192 network 92.xxx.xxx.64 broadcast 93.xxx.xxx.127 gateway 92.xxx.xxx.65 auto eth0:1 iface eth0:1 inet static address 108.xxx.xxx.146 netmask 255.255.255.192 gateway 108.xxx.xxx.129 #ip route show 108.xxx.xxx.128/26 dev eth0 proto kernel scope link src 108.xxx.xxx.146 92.xxx.xxx.64/26 dev eth0 proto kernel scope link src 92.xxx.xxx.92 default via 108.xxx.xxx.129 dev eth0 src 108.xxx.xxx.146 default via 92.xxx.xxx.65 dev eth0
我能做些什么来使debian使用92. IP传出连接? 另一个当然也应该工作。
你几乎可以肯定,在你的networkingconfiguration中只有一个 gateway参数(基本上,如果你不知道为什么你需要两个,你不需要)。 gateway参数指定您的机器的默认网关 – 路由器应该发送没有更具体路由的stream量。 在大多数networking中,只有一个符合该标准的路由器,即使您可能有其他(更具体的)其他networking路由。
如果由于某种原因,你真的需要2个不同的IPnetworking同时工作,你应该在Linux上使用ip rule 。
假设两个IPnetworking“A”和“B”在同一个网卡上。 “A”是主要的,也就是说,当从方块中ping一些主机时,你需要使用“A”IP参数,所以你只把“A”的默认网关放到(主)路由表中。 如果您需要从«B»回复使用«B»的默认网关,那么您可以通过以下方式进行pipe理:
ip rule add from B_Network/Mask lookup table B_table pref 20000 ip route add default via B_gw table B_table B_table应该先在/etc/iproute2/rt_tables定义。 有关详细信息,请参阅LARTC 。