Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -xu
- #Define the policies to accept in order to avoid being cut out running this remotely via SSH
- sudo iptables -P INPUT ACCEPT
- sudo iptables -P FORWARD ACCEPT
- sudo iptables -P OUTPUT ACCEPT
- #To begin with, flush the tables
- sudo iptables -t mangle -F
- sudo iptables -t nat -F
- sudo iptables -t filter -F
- sudo iptables -X
- # Allow Access Point NAT
- sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
- # Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
- sudo iptables -t filter -A INPUT -i lo -j ACCEPT
- sudo iptables -t filter -A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
- # Accepts all established inbound connections
- sudo iptables -t filter -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
- #Drop all multicast traffic
- sudo iptables -t filter -A INPUT -d 224.0.0.0/4 -j DROP
- sudo iptables -t filter -A OUTPUT -d 224.0.0.0/4 -j DROP
- # Allows all outbound traffic
- sudo iptables -t filter -A OUTPUT -j ACCEPT
- # Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)
- sudo iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
- sudo iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT
- # Allows SSH connections
- sudo iptables -t filter -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
- sudo iptables -t filter -A INPUT -p tcp -m state --state NEW -m recent --dport 22 --set --name ssh --rsource
- sudo iptables -t filter -A INPUT -p tcp -m state --state NEW -m recent --dport 22 ! --rcheck --seconds 60 --hitcount 4 --name ssh --rsource -j ACCEPT
- # Allow ping and other icmp traffic
- sudo iptables -t filter -A INPUT -p icmp -j ACCEPT
- # Allow forwarded the following forwards
- sudo iptables -t filter -A FORWARD -o wlan0 -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
- sudo iptables -t filter -A FORWARD -o eth0 -i wlan0 -j ACCEPT
- # log iptables denied calls
- sudo iptables -t filter -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
- # Reject all other inbound
- sudo iptables -t filter -A INPUT -j DROP
- sudo iptables -t filter -A FORWARD -j DROP
- #Reset the policies
- sudo iptables -P INPUT DROP
- sudo iptables -P FORWARD DROP
- sudo iptables -P OUTPUT DROP
- sudo dmesg -c
- clear
Add Comment
Please, Sign In to add comment