I have a machine with two public IP addresses on two interfaces. This machine is running sshd. Is there a way to specify, when creating a tunnel with a SOCKS interface (i.e. -D), which interface to use for outgoing connections?
Specifying outgoing interface for SSH tunnel
ssh;ssh tunneling
Strictly speaking, you can solve your problem by a combination of the -b option in ssh, as suggested by mgjk, and routing. Suppose you are trying to build a tunnel to the site 8.8.8.7 (just a fictitious example), and you want the connection to go through eth1, then the command sudo route add -host 8.8.8.7 dev eth1will add a proper route, and all should be well. However, this is also the perfect case of application for policy routing. It entails configuring the routing table on the machine setting up the tunnel (i.e. the one on which the command ssh -D ... is issued) simply because it's the only one on which the two interfaces exist. A concise yet sufficient explanation is given by David Schwartz on this very site. Only important detail is: say eth0 is 192.168.1.2, and eth1 is 10.0.0.2, then you may say ip rule add from 10.0.0.2 table <NAME1> ip rule add from 192.168.1.2 table <NAME2>At this point, you can bind your ssh connection via -b to eth1's address, and you are done. 