Brick icon

VPN UFW Kill Switch

Brick | PRO | 11/01/18 01:44:01 AM UTC | 0 ⭐ | 1048 👁️ | Never ⏰ | []
Bash |

770 B

|

None

|

0 👍

/

0 👎

#!/bin/bash
 
# https://github.com/renapoliveira/killswitch-for-openvpn
# https://askubuntu.com/questions/530088/ufw-for-openvpn
 
VPN_FILE=openvpn.ovpn
TUNNEL=tun0
 
INTERFACE=`ip addr | grep "state UP" | cut -d ":" -f 2 | cut -c 2- | head -n 1`
IP=`cat $VPN_FILE | grep "remote " | awk '{print $2}'`
PORT=`cat $VPN_FILE | grep "remote " | awk '{print $3}'`
PROTOCOL=`cat $VPN_FILE | grep "proto " | awk '{print $2}'`
 
echo "Using "$INTERFACE"->"$TUNNEL
echo "Connecting to "$IP":"$PORT" via "$PROTOCOL
 
sudo ufw --force reset
sudo ufw default deny incoming
sudo ufw default deny outgoing
sudo ufw allow out on $TUNNEL
sudo ufw allow out on $INTERFACE to any port 53,$PORT,1197 proto $PROTOCOL
sudo ufw enable
sudo ufw status verbose
 
sudo openvpn --config $VPN_FILE

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎