0

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.

1 Answer 1

4

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

Suppose 1.1.1.1 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 1.1.1.1 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 192.168.0.0/24 table 10

Or from individual IPs:

# ip rule add from 192.168.0.3/32 table 10
# ip rule add from 192.168.0.5/32 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.

You must log in to answer this question.