Firewall – How to block internet access when the VPN stops on a DD-WRT router and separate VPN/direct clients

firewallopenvpnroutervpn

I am using a DD-WRT 3.0 router to connect via openVPN. In the LAN, 192.168.1.50 is a device which should not go thru the VPN.

(How do I set the firewall to have 192.168.1.50 not go thru VPN
and
How to make all other IPs lose WAN connection when the VPN disconnects/drops?)

OR

(Create two subnets, one thru VPN (wi-fi devices) and the other direct (wired devices)
and
Have the VPN subnet lose WAN connectivity when the VPN drops)

I have no preference for either setup. Whatever is easier.

This rule didn't work (for the 1st scenario):

iptables -I FORWARD ! -o tun1 -s 192.168.1.50 -j DROP

Here's the route table in use, with the router in gateway mode:

enter image description here

Best Answer

To block all outbound traffic for clients on the normal WAN, you can use the nvram variable get wan_iface

IPV4_WAN=$(nvram get wan_iface)
iptables -I FORWARD -s 192.168.x.x/24 -o "$IPV4_WAN" -j DROP

You'll want to define your specific IPv4 subnet, be careful not to block your entire LAN range!

This will block any outbound traffic going beyond your router, when not on the VPN interface, you can confirm by doing a traceroute to any external IPv4 address, you'll find after the first hop the traffic will drop.

For your specific IPv4 client, I'm a little confused. Can't you create a IPv4 subnet for the clients you want going to the VPN and then based on the range make sure that 192.168.1.50 client is not within it? Then just add an ACCEPT rule to allow it to use the WAN as normal?

iptables -I FORWARD -s 192.168.1.50 -o "$IPV4_WAN" -j ACCEPT
Related Topic