Advertisement
Guest User

/etc/openvpn/iptables.sh

a guest
Jul 9th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1.  
  2. #! /bin/bash
  3. # Niftiest Software – www.niftiestsoftware.com
  4. # Modified version by HTPC Guides – www.htpcguides.com
  5.  
  6. export INTERFACE="tun0"
  7. export VPNUSER="vpn"
  8. export LOCALIP="192.168.178.203"
  9. export NETIF="ens160"
  10.  
  11. # flushes all the iptables rules, if you have other rules to use then add them into the script
  12. iptables -F -t nat
  13. iptables -F -t mangle
  14. iptables -F -t filter
  15.  
  16. # mark packets from $VPNUSER
  17. iptables -t mangle -A OUTPUT -j CONNMARK --restore-mark
  18. iptables -t mangle -A OUTPUT ! --dest $LOCALIP -m owner --uid-owner $VPNUSER -j MARK --set-mark 0x1
  19. iptables -t mangle -A OUTPUT --dest $LOCALIP -p udp --dport 53 -m owner --uid-owner $VPNUSER -j MARK --set-mark 0x1
  20. iptables -t mangle -A OUTPUT --dest $LOCALIP -p tcp --dport 53 -m owner --uid-owner $VPNUSER -j MARK --set-mark 0x1
  21. iptables -t mangle -A OUTPUT ! --src $LOCALIP -j MARK --set-mark 0x1
  22. iptables -t mangle -A OUTPUT -j CONNMARK --save-mark
  23.  
  24. # allow responses
  25. iptables -A INPUT -i $INTERFACE -m conntrack --ctstate ESTABLISHED -j ACCEPT
  26.  
  27. # block everything incoming on $INTERFACE to prevent accidental exposing of ports
  28. iptables -A INPUT -i $INTERFACE -j REJECT
  29.  
  30. # let $VPNUSER access lo and $INTERFACE
  31. iptables -A OUTPUT -o lo -m owner --uid-owner $VPNUSER -j ACCEPT
  32. iptables -A OUTPUT -o $INTERFACE -m owner --uid-owner $VPNUSER -j ACCEPT
  33.  
  34. # all packets on $INTERFACE needs to be masqueraded
  35. iptables -t nat -A POSTROUTING -o $INTERFACE -j MASQUERADE
  36.  
  37. # reject connections from predator IP going over $NETIF
  38. iptables -A OUTPUT ! --src $LOCALIP -o $NETIF -j REJECT
  39.  
  40. # Start routing script
  41. /etc/openvpn/routing.sh
  42.  
  43. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement