I wanted to find guides on this and avoid asking but you can't search "iptables", "vpn", "leak" or "proof" in this forum. Apparently all these words are too common.

Anyway what i'm trying to do is create an iptables configuration that blocks all network traffic when the vpn connection drops. I'd prefer to be able to reconnect to the vpn service as well once it drops.
Here is my shell script, copied and modified from the AIRVPN forums. (I'm using NORD which has no special clients.)
Code: Select all
#!/bin/bash
# IPTABLES lock for openvpn
FW="/sbin/iptables"
LCL="192.168.76.128/24"
VPN="10.8.8.185/30"
local_interface="eno16777736"
virtual_interface="tun0"
#OPENVPN Servers
servers=(
37.235.57.32 # Double AT-NL (TCP)
95.143.198.80 # SE-TOR
94.249.245.17 # AUS
181.41.210.93 # BR
158.255.208.52 # HK
95.211.190.205 # NL2
95.211.224.1 # NL
46.108.39.199 # RO
141.105.68.130 # RU
95.143.198.99 # SE1
95.143.198.47 # SE
154.127.61.142 # ZA
)
#---------------------------------------------------------------
# Remove old rules and tables
#---------------------------------------------------------------
echo "Deleting old iptables rules..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
echo "Setting up new rules..."
#---------------------------------------------------------------
# Default Policy - Drop anything!
#---------------------------------------------------------------
$FW -P INPUT DROP
$FW -P FORWARD DROP
$FW -P OUTPUT DROP
#---------------------------------------------------------------
# Allow all local connections via loopback.
#---------------------------------------------------------------
$FW -A INPUT -i lo -j ACCEPT
$FW -A OUTPUT -o lo -j ACCEPT
#---------------------------------------------------------------
# Allow Multicast for local network.
#---------------------------------------------------------------
$FW -A INPUT -j ACCEPT -p igmp -s $LCL -d 224.0.0.0/4 -i $local_interface
$FW -A OUTPUT -j ACCEPT -p igmp -s $LCL -d 224.0.0.0/4 -o $local_interface
#---------------------------------------------------------------
# Allow all bidirectional traffic from your firewall to the
# local area network
#---------------------------------------------------------------
$FW -A INPUT -j ACCEPT -s $LCL -i $local_interface
$FW -A OUTPUT -j ACCEPT -d $LCL -o $local_interface
#---------------------------------------------------------------
# Allow all bidirectional traffic from your firewall to the
# virtual privat network
#---------------------------------------------------------------
$FW -A INPUT -j ACCEPT -i $virtual_interface
$FW -A OUTPUT -j ACCEPT -o $virtual_interface
#---------------------------------------------------------------
# Connection to AirVPN servers (UDP 443)
#---------------------------------------------------------------
server_count=${#servers[@]}
for (( c = 0; c < $server_count; c++ ))
do
$FW -A INPUT -j ACCEPT -p udp -s ${servers[c]} --sport 443 -i $local_interface
$FW -A OUTPUT -j ACCEPT -p udp -d ${servers[c]} --dport 443 -o $local_interface
done
#---------------------------------------------------------------
# Log all dropped packages, debug only.
# View in /var/log/syslog or /var/log/messages
#---------------------------------------------------------------
#iptables -N logging
#iptables -A INPUT -j logging
#iptables -A OUTPUT -j logging
#iptables -A logging -m limit --limit 2/min -j LOG --log-prefix "IPTables general: " --log-level 7
#iptables -A logging -j DROP
Code: Select all
[root@localhost bin]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.76.128 netmask 255.255.255.0 broadcast 192.168.76.255
ether 00:50:56:3c:9e:74 txqueuelen 1000 (Ethernet)
RX packets 91894 bytes 85457439 (81.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 84554 bytes 17496400 (16.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 0 (Local Loopback)
RX packets 106 bytes 9588 (9.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 106 bytes 9588 (9.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.8.8.186 netmask 255.255.255.255 destination 10.8.8.185
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 100 (UNSPEC)
RX packets 34412 bytes 34864163 (33.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 31507 bytes 4391755 (4.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Code: Select all
Tue Nov 4 01:22:34 2014 UDPv4 link local: [undef]
Tue Nov 4 01:22:34 2014 UDPv4 link remote: [AF_INET]181.41.210.93:1194
Tue Nov 4 01:22:34 2014 write UDPv4: Operation not permitted (code=1)
Tue Nov 4 01:22:36 2014 write UDPv4: Operation not permitted (code=1)
Tue Nov 4 01:22:40 2014 write UDPv4: Operation not permitted (code=1)
Tue Nov 4 01:22:48 2014 write UDPv4: Operation not permitted (code=1)

Will post solution in OP when found.