Linux 将传出流量绑定到 eth0 而不是 eth0:1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8531835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bind outgoing traffic to eth0 instead of eth0:1
提问by MiDo
We added a second IP-Adress to a linux (debian) machine to implement a second SSL-certificate to a new Apache vhost.
我们向 linux (debian) 机器添加了第二个 IP 地址,以便为新的 Apache vhost 实施第二个 SSL 证书。
Our ifconfig
now looks like this:
我们ifconfig
现在看起来像这样:
eth0 Link encap:Ethernet Hardware Adresse 00:0c:29:1b:ab:6c
inet Adresse:999.999.999.39 Bcast:999.999.999.63 Maske:255.255.255.192
inet6-Adresse: (...)/64 Gültigkeitsbereich:Verbindung
UP BROADCAST RUNNING MULTICAST MTU:1500 Metrik:1
RX packets:219336884 errors:0 dropped:0 overruns:0 frame:0
TX packets:223169420 errors:0 dropped:0 overruns:0 carrier:0
Kollisionen:0 Sendewarteschlangenl?nge:1000
RX bytes:1971307659 (1.8 GiB) TX bytes:713489565 (680.4 MiB)
eth0:1 Link encap:Ethernet Hardware Adresse (...)
inet Adresse:999.999.999.40 Bcast:999.999.999.63 Maske:255.255.255.192
UP BROADCAST RUNNING MULTICAST MTU:1500 Metrik:1
Problem: All outgoing traffic (MySQL connections to external DB-server, outgoing SMTP connections from postfix) now seems to leave through eth0:1, hence the second (new) IP 999.999.999.40.
问题:所有传出流量(MySQL 连接到外部数据库服务器,从 postfix 传出 SMTP 连接)现在似乎通过 eth0:1 离开,因此第二个(新)IP 999.999.999.40。
How can we force all outgoing traffic to leave through eth0, IP-adress 999.999.999.39?
我们如何强制所有传出流量通过 eth0、IP 地址 999.999.999.39 离开?
Output of route:
路线输出:
[n1 ~ #] route
Kernel-IP-Routentabelle
Ziel Router Genmask Flags Metric Ref Use Iface
localnet * 255.255.255.192 U 0 0 0 eth0
10.10.10.0 * 255.255.255.0 U 0 0 0 eth1
default gateway4.XXX 0.0.0.0 UG 0 0 0 eth0
default gateway4.XXX 0.0.0.0 UG 0 0 0 eth0
Found solution:
找到解决方案:
Thanks for your hints, ip route
was the way to go, now it works as desired.
感谢您的提示,这ip route
是要走的路,现在它可以按预期工作。
ip rule add from 999.999.999.39 table t1
ip rule add from 999.999.999.40 table t2
ip route del default via 999.999.999.1
ip route add default 999.999.999.1 dev eth0 table t1
ip route flush cache
回答by Cédric Julien
I think you'll have to play with the routecommand to tell the system how to route the packets. Something like :
我认为您必须使用route命令来告诉系统如何路由数据包。就像是 :
route add -net APACHE_VHOST_IP netmask 255.255.255.0 dev eth0:1
to force the packet in destination of APACHE_VHOST_IP to use the eth0:1 interface.
强制 APACHE_VHOST_IP 目标中的数据包使用 eth0:1 接口。
And
和
route add -net MYSQL_SERVER_IP netmask 255.255.255.0 dev eth0
to force the packet in destination of MYSQL_SERVER_IP to use the eth0 interface.
强制 MYSQL_SERVER_IP 目标中的数据包使用 eth0 接口。
回答by ScurvyJim
Add this to /etc/sysconfig/network
将此添加到 /etc/sysconfig/network
GATEWAYDEV=eth0
Forces default gateway
to eth0
interface
部队default gateway
到eth0
接口