我有一个服务器与eth0和eth1即,我想强制所有ssh客户端通过eth0.因此,当我的服务器上有很多ssh客户端时,我可以通过eth1更快地访问我的服务器.
编辑:启动ssh客户端连接的服务器.
更新OPs编辑要求服务器端解决方案 – 这是客户端. 对于临时使用,您可以将选项绑定到特定IP或以太网端口的SSH. ssh target_IP -b source_IP对于更永久的解决方案,请更改路由表.
我尝试从172.x.x.7(eth0)ssh到172.x.x.69,它有另一个以太网端口172.x.x.8(eth1)恰好是默认网关.
如果我尝试直接ssh失败 – 因为此源IP默认为x.x.x.8 eth1,并且在外部防火墙规则中不允许这样做.69
# ssh 172.29.179.69 -l root ssh: connect to host 172.x.x.69 port 22: Connection timed out #
使用-b开关将SSH绑定到x.x.x.7 IP(eth0)时成功 – 允许此IP在防火墙规则中连接到.69.
# ssh 172.x.x.69 -b 172.x.x.7 -l root Last login: Wed Nov 19 14:27:44 2014 from 172.x.x.7 #
在172.x.x.7我有两个以太网端口x.7和x.8
# ifconfig eth0 Link encap:Ethernet HWaddr xxxxx inet addr:172.x.x.7 Bcast:172.x.x.31 Mask:255.255.255.224 inet6 addr: xxx Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:27678 errors:0 dropped:0 overruns:0 frame:0 TX packets:9 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1852058 (1.7 MiB) TX bytes:684 (684.0 b) eth1 Link encap:Ethernet HWaddr xxx inet addr:172.x.x.8 Bcast:172.x.x.31 Mask:255.255.255.224 inet6 addr: xxx Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:72022 errors:0 dropped:0 overruns:0 frame:0 TX packets:34734 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:40788643 (38.8 MiB) TX bytes:4441314 (4.2 MiB)
我需要这个hack的原因是路由表默认eth1而不是eth0
# route (@172.x.x.7) Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 172.x.x.0 * 255.255.255.224 U 0 0 0 eth1 172.x.x.0 * 255.255.255.224 U 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 0 0 0 eth2 link-local * 255.255.0.0 U 1002 0 0 eth0 link-local * 255.255.0.0 U 1003 0 0 eth1 link-local * 255.255.0.0 U 1004 0 0 eth2 default 172.x.x.1 0.0.0.0 UG 0 0 0 eth1 # eth0 OK #
精彩评论