Advertisement
Guest User

iptables_openvpn

a guest
Mar 28th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # REMEMBER: Run this as a single bash script or you'll lock yourself out of your machine.
  4.  
  5. # Flushing all rules
  6. iptables -F FORWARD
  7. iptables -F INPUT
  8. iptables -F OUTPUT
  9. iptables -X
  10. # Setting default filter policy
  11. iptables -P INPUT DROP
  12. iptables -P OUTPUT DROP
  13. iptables -P FORWARD DROP
  14. # Allow unlimited traffic on loopback
  15. iptables -A INPUT -i lo -j ACCEPT
  16. iptables -A OUTPUT -o lo -j ACCEPT
  17. # Accept outbound on the primary interface
  18. iptables -I OUTPUT -o eth0 -d 0.0.0.0/0 -j ACCEPT
  19. # Accept inbound TCP packets
  20. iptables -I INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
  21. # Allow incoming SSH
  22. iptables -A INPUT -p tcp --dport 22 -m state --state NEW -s 0.0.0.0/0 -j ACCEPT
  23. # Allow incoming OpenVPN
  24. iptables -A INPUT -p udp --dport 1194 -m state --state NEW -s 0.0.0.0/0 -j ACCEPT
  25. # Enable NAT for the VPN
  26. iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
  27. # Allow TUN interface connections to OpenVPN server
  28. iptables -A INPUT -i tun0 -j ACCEPT
  29. # Allow TUN interface connections to be forwarded through other interfaces
  30. iptables -A FORWARD -i tun0 -j ACCEPT
  31. iptables -A OUTPUT -o tun0 -j ACCEPT
  32. iptables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  33. iptables -A FORWARD -i eth0 -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
  34. # Allow outbound access to all networks on the Internet from the VPN
  35. iptables -A FORWARD -i tun0 -s 10.8.0.0/24 -d 0.0.0.0/0 -j ACCEPT
  36. # Block client-to-client routing on the VPN
  37. iptables -A FORWARD -i tun0 -s 10.8.0.0/24 -d 10.8.0.0/24 -j DROP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement