2

I have two network interfaces with respective ips

 eth0 : 192.168.70.153
 eth2 : 192.168.70.155

when I make

 route -C
 Kernel IP routing cache
 Source          Destination     Gateway         Flags Metric Ref    Use Iface
 192.168.70.155 192.168.70.152  192.168.70.152        0      0        0 eth0

how I can force a telnet conection to 192.168.70.152 over eth2?

JuanPablo
  • 913
  • 3
  • 10
  • 21

2 Answers2

1

You would have to add a specific route for the host 192.168.70.152.

route add -host 192.168.70.152 dev eth2

This would push all traffic destined for 192.168.70.152 over eth2. Would that be enough, or would you require only telnet to be routed?

Paul
  • 1,288
  • 13
  • 25
1

What you want is the Linux Advanced Routing and Traffic Control HOWTO. Specifically, the section on Netfilter & iproute - marking packets is a good place to start for this sort of thing.

You'd set up your default route to go over eth0, then in /etc/iproute2/rt_tables add an entry, say at 200, for "viaeth2". Then you need to set up routing in that table:

ip route add 192.168.70.0/24 dev eth2 src 192.168.70.155 table viaeth2
ip rule add fwmark 1 table viaeth2

Then you can mark packets via iptables that should be routed via that table:

iptables -A PREROUTING -d 192.168.70.152 -t mangle -p tcp --dport 23 \
    -j MARK --set-mark 1

This will do what you specifically asked in the original question. If you want to do more general load-balancing across the two interfaces, you want to do "bonding" via the "bond" driver.

Sean Reifschneider
  • 10,720
  • 3
  • 25
  • 28