Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to route all outgoing requests for SSH (port 22) to mydynamicdns.afraid.org via wlan0 instead of eth0 when both are connected?

Since my IP is dynamic, I would like to use a name instead of IP.

share|improve this question
up vote 3 down vote accepted

Yes, you could mark all packets matches such policy, and control the route like this,

# Set mark for out going packets
iptables -t mangle -A OUTPUT -d mydynamicdns.afraid.org -j MARK --set-mark 1

# Route all packets with mark 1 through wlan0
ip rule add fwmark 1 table 1
ip route add XXX table 1 dev wlan0

P.S The rule would not work if DNS resolution fails

share|improve this answer
Thanks, I am using Ubuntu, will this work? Is IPTABLES a file that I can hand edit? – JorgeeFG Mar 3 '13 at 1:24
@Jorge it's a set of command – warl0ck Mar 3 '13 at 1:41
Thanks, how can I see the rules I have added and/or delete them? – JorgeeFG Mar 3 '13 at 16:30
@Jorge ip rule; iptables -t mangle -L; ip route – warl0ck Mar 4 '13 at 0:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.