I'm just getting started with tinkering with Linux / IPTABLES and following this great tutorial here to successfully setup a RaspBerry Pi device (running RaspBerryPi OS / Debian) as a VPN Gateway. Any device on the same network can manually configure their network settings and set their routing to the IP address of the device, which will then process the information via VPN and then send it back (all from the same eth0 interface).
The problem I'm having is the VPN software NordVPN for Linux removes the tun0 interface automatically when I disconnect / logout from VPN, resulting in internet no longer working on the laptop. I understand that this is due to the packets are still being told to forward, and if the tun0 interface doesn't exist those packets have no way to return to the laptop.
What would be the ideal procedure to simply return all incoming traffic on eth0 back out to eth0 when tun0 doesn't exist?
Structure:
Eg: laptop → raspBerry pi (eth0 > tun0 > eth0) → laptop
The iptables on the RaspBerry Pi are as follows:
sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT
sudo iptables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -i eth0 -p icmp -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -P FORWARD DROP
sudo iptables -P INPUT DROP
So far my research has pointed me to a couple answers:
https://unix.stackexchange.com/a/322386
Always Forward Traffic Out The Interface It Originated On
Maybe something like: ip route add table 2 default via 192.168.0.1
(ip address of my main router?) however I have not tried this yet and not fully sure if this is the direction I should be headed.