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?
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 126.96.36.199 (just a fictitious example), and you want the connection to go through eth1, then the command
will 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
At this point, you can bind your ssh connection via -b to eth1's address, and you are done.
What happens when you use -b?