Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I have been able to setup my dd-wrt router to connect to an openvpn server and route all traffic through the vpn to the internet.

This makes it so all traffic comming in from the LAN to the Internet goes through the router->vpn->internet, this works fine.

What I would like to do is only forward traffic from some ip's in my LAN through the vpn and not others. I'm sure there is an iptables way of doing this, but I have not been able to figure it out.

share|improve this question

This is a routing question, so using iptables may not suitable. Here we will use iproute2, which, fortunately, included with DD-WRT.

Suppose is the IP address of the default gateway of the DD-WRT (you have to figure it out, may be by ways of disable OpenVPN so that the default gateway will be set to normal and issue a route -n command to see the normal - before OpenVPN-get-connected default gateway).

Now set up another route table like that (we will use table 10):

# ip route add default via table 10

And set up rules so that traffic from some IPs in the LAN will get routed using this new table:

# ip rule add from table 10

Or from individual IPs:

# ip rule add from table 10
# ip rule add from table 10

You can verify with:

# ip route show table 10
# ip rule list

Read more here on startup scripts on DD-WRT if you want all of these to survive on reboot.

share|improve this answer

Your Answer


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