Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Flush
- iptables -t nat -F
- iptables -t mangle -F
- iptables -F
- iptables -X
- # Block All
- iptables -P OUTPUT DROP
- iptables -P INPUT DROP
- iptables -P FORWARD DROP
- # allow Localhost
- iptables -A INPUT -i lo -j ACCEPT
- iptables -A OUTPUT -o lo -j ACCEPT
- # Make sure you can communicate with any DHCP server
- iptables -A OUTPUT -d 255.255.255.255 -j ACCEPT
- iptables -A INPUT -s 255.255.255.255 -j ACCEPT
- # CHANGED Make sure that you can communicate within your own network. CHANGE 192.168.50.0/24 TO YOUR LOCAL NETWORK
- iptables -A INPUT -s #.#.#.#/24 -d #.#.#.#/24 -j ACCEPT
- iptables -A OUTPUT -s #.#.#.#/24 -d 192.168.50.0/24 -j ACCEPT
- # Allow established sessions to receive traffic:
- iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- # CHANGED Allow TUN. MAKE SURE YOUR INTERFACE IS CALLED wg-something. THE WG+ IS A WILDCARD.
- iptables -A INPUT -i wg+ -j ACCEPT
- iptables -A FORWARD -i wg+ -j ACCEPT
- iptables -A FORWARD -o wg+ -j ACCEPT
- iptables -t nat -A POSTROUTING -o wg+ -j MASQUERADE
- iptables -A OUTPUT -o wg+ -j ACCEPT
- #CHANGED allow VPN connection. MAKE SURE THE WIREGUARD PORT IS CORRECT, MINE IS 1337
- iptables -I OUTPUT 1 -p udp --destination-port 1337 -m comment --comment "Allow VPN connection" -j ACCEPT
- # Block All
- iptables -A OUTPUT -j DROP
- iptables -A INPUT -j DROP
- iptables -A FORWARD -j DROP
- # Log all dropped packages, debug only.
- 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
- echo "saving"
- iptables-save > /etc/iptables.rules
- echo "done"
- #echo 'openVPN - Rules successfully applied, we start "watch" to verify IPtables in realtime (you can cancel it as usual CTRL + c)'
- #sleep 3
- #watch -n 0 "sudo iptables -nvL"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement