rendered paste body#!/bin/bash
# No spoofing
if [ -e /proc/sys/net/ipv4/conf/all/rp_filter ]
then
for filtre in /proc/sys/net/ipv4/conf/*/rp_filter
do
echo 1 > $filtre
done
fi
# No icmp
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
#load some modules you may need
modprobe ip_tables
modprobe ip_nat_ftp
modprobe ip_nat_irc
modprobe iptable_filter
modprobe iptable_nat
# Remove all rules and chains
iptables -F
iptables -X
# first set the default behaviour => accept connections
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
# Create 2 chains, it allows to write a clean script
iptables -N FIREWALL
iptables -N TRUSTED
# Allow ESTABLISHED and RELATED incoming connection
iptables -A FIREWALL -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow loopback traffic
iptables -A FIREWALL -i lo -j ACCEPT
# Send all package to the TRUSTED chain
iptables -A FIREWALL -j TRUSTED
# DROP all other packets
iptables -A FIREWALL -j DROP
# Send all INPUT packets to the FIREWALL chain
iptables -A INPUT -j FIREWALL
# DROP all forward packets, we don't share internet connection in this example
iptables -A FORWARD -j DROP
# Allow HTTPS
iptables -A TRUSTED -i eth0 -p udp -m udp --sport 443 -j ACCEPT
iptables -A TRUSTED -i eth0 -p tcp -m tcp --sport 443 -j ACCEPT
# Allow BitTorrent
iptables -A TRUSTED -i eth0 -p tcp -m tcp --dport 49999 -j ACCEPT
iptables -A TRUSTED -i eth0 -p udp -m udp --dport 49999 -j ACCEPT
# Allow Samba locally
iptables -A TRUSTED -i eth0 -p udp --dport 137 -s 192.168.1.0/24 -j ACCEPT
iptables -A TRUSTED -i eth0 -p udp --dport 138 -s 192.168.1.0/24 -j ACCEPT
iptables -A TRUSTED -i eth0 -p tcp --dport 139 -s 192.168.1.0/24 -j ACCEPT
iptables -A TRUSTED -i eth0 -p tcp --dport 445 -s 192.168.1.0/24 -j ACCEPT
# Allow VNC locally
iptables -A TRUSTED -i eth0 -p tcp --dport 5900 -s 192.168.1.0/24 -j ACCEPT
# Hantera SSH
iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH
iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 8 --rttl --name SSH -j DROP
iptables -A TRUSTED -i eth0 -p tcp -m tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
# End message
echo " [End iptables rules setting]"