How can i force a client connection ssh to communicate through a specific interface ?
I have a server with eth0 and eth1 i.e., and i want to force all ssh clients to pass through eth0. So i could access my server via eth1 faster when there is a lot of ssh clients on my server.
Edit : It's the server who initiates the ssh client connections.
Update OPs edit asks for server side solution - this is client side. For temporary use you can bind option to SSH from particular IP or ethernet port. ssh target_IP -b source_IP
For more permanent solution change the routing table.
I cam trying to ssh into 172.x.x.69 from 172.x.x.7 (eth0) which has another Ethernet port 172.x.x.8 (eth1) that happens to be the default gateway.
Fails if i try to ssh directly - because this source IP defaults to x.x.x.8 eth1 and this is not allowed in external firewall rules to .69
# ssh 172.29.179.69 -l root
ssh: connect to host 172.x.x.69 port 22: Connection timed out
#
Success when I bind SSH to x.x.x.7 IP (eth0) using the -b switch - this IP is allowed to connect to .69 in firewall rules.
# 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
#
At 172.x.x.7 I have two ethernet ports x.7 and 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)
The reason I need this hack is the routing table default eth1 instead of 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
#
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With