Advertisement
Brick

VPN UFW Kill Switch

Oct 31st, 2018
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.77 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # https://github.com/renapoliveira/killswitch-for-openvpn
  4. # https://askubuntu.com/questions/530088/ufw-for-openvpn
  5.  
  6. VPN_FILE=openvpn.ovpn
  7. TUNNEL=tun0
  8.  
  9. INTERFACE=`ip addr | grep "state UP" | cut -d ":" -f 2 | cut -c 2- | head -n 1`
  10. IP=`cat $VPN_FILE | grep "remote " | awk '{print $2}'`
  11. PORT=`cat $VPN_FILE | grep "remote " | awk '{print $3}'`
  12. PROTOCOL=`cat $VPN_FILE | grep "proto " | awk '{print $2}'`
  13.  
  14. echo "Using "$INTERFACE"->"$TUNNEL
  15. echo "Connecting to "$IP":"$PORT" via "$PROTOCOL
  16.  
  17. sudo ufw --force reset
  18. sudo ufw default deny incoming
  19. sudo ufw default deny outgoing
  20. sudo ufw allow out on $TUNNEL
  21. sudo ufw allow out on $INTERFACE to any port 53,$PORT,1197 proto $PROTOCOL
  22. sudo ufw enable
  23. sudo ufw status verbose
  24.  
  25. sudo openvpn --config $VPN_FILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement