Need VPN iproute help

This is my command

sudo openvpn --daemon --log /var/log/openvpn.log --config /home/dietpi/vpn/config.ovpn

Last question for this topic how do i delete these settings after closing my openvpn connection?

ip rule add from 192.168.42.0/24 lookup 42
ip route add default dev tun1 table 42
iptables -t nat -A POSTROUTING -s 192.168.42.0/24 -o tun1 -j MASQUERADE
iptables -t filter -A FORWARD -i wlan0 -o tun1 -j ACCEPT

Deleted via

ip rule delete from 192.168.42.0/24 lookup 42
ip route delete default dev tun1 table 42
iptables -t nat -D POSTROUTING -s 192.168.42.0/24 -o tun1 -j MASQUERADE
iptables -t filter -D FORWARD -i wlan0 -o tun1 -j ACCEPT

is this syntax correct?

del instead of delete in ip commands.
It also depends if you want to allow leaks from the wifi when the VPN is not connected.

Hello like this?

ip rule del from 192.168.42.0/24 lookup 42
ip route del default dev tun1 table 42
iptables -t nat -D POSTROUTING -s 192.168.42.0/24 -o tun1 -j MASQUERADE
iptables -t filter -D FORWARD -i wlan0 -o tun1 -j ACCEPT

Looks ok to me. Is there any error if you run it manually?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.