I have the OpenVPN client running with policy rules set to direct all traffic via the VPN for one of the computers on my network and to block all traffic if the tunnel goes down. I also have some port forwards set up with my VPN provider so this computer is still reachable from the internet. My forwarding rules are currently in the openvpn-event script, example below:
However, if the VPN loses connection and auto-restarts, the rules get re-added, causing lots of duplicates. It doesn't appear to cause any issues, but it looks messy (and it just bothers me, haha).
I'm wondering if I should move the rules to the nat-start script instead. That way they get added just once when the router starts and remain regardless of whether the VPN tunnel goes down and restarts. Would it complain if the tun interface doesn't exist yet (assuming nat-start runs before the VPN tunnel is up)? I thought I'd ask on here first before I tried it.
Does anyone see any other issues with this setup? Or any suggestions for other/better ways to do this?
Code:
iptables -I FORWARD -i tun13 -p tcp -d 192.168.1.73 --dport 8081 -j ACCEPT
iptables -t nat -I PREROUTING -i tun13 -p tcp --dport 8081 -j DNAT --to-destination 192.168.1.73
However, if the VPN loses connection and auto-restarts, the rules get re-added, causing lots of duplicates. It doesn't appear to cause any issues, but it looks messy (and it just bothers me, haha).
I'm wondering if I should move the rules to the nat-start script instead. That way they get added just once when the router starts and remain regardless of whether the VPN tunnel goes down and restarts. Would it complain if the tun interface doesn't exist yet (assuming nat-start runs before the VPN tunnel is up)? I thought I'd ask on here first before I tried it.
Does anyone see any other issues with this setup? Or any suggestions for other/better ways to do this?