My situation: A ubuntu server is part of a LAN with 2 gateways. The one offers high speed with high latency. The other low speed with low latency. My server usually uses GW1 for all traffic (because of high bandwidth). I would love to be able to ssh into the server via the low latency connection. GW2 has a port forwarding to the server but it obviously doesn't work out of the box because the server will answer via GW1 which will drop the packages.
After some research, ehre is what i did (my ssh port is 222):
i added a iptables rule to mark the packages
iptables -L PREROUTING -t mangle
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
MARK tcp -- anywhere anywhere tcp dpt:222 MARK set 0x1
i added the following to /etc/iproute2/rt_tables
100 sshtable
i added a ip rule for the new table - this is "ip rule show output"
ip rule show
0: from all lookup local
32764: from all fwmark 0x1 lookup sshtable
32766: from all lookup main
32767: from all lookup default
i changed the routing for the new table - this is "ip route show table sshtable"
ip route show table sshtable
default via 192.168.2.2 dev eth0
rp_filter should be turned off:
cat /etc/sysctl.conf | grep filter
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.all.rp_filter=0
Unfortunately it does not work. I can see the incoming connection being stuck at SYN_SENT (using tcptrack).
Do you have any hints for me? Nik