#! /bin/sh ########################################################### # Define ########################################################### LOCALNET='192.168.10.0/24' BROADCAST='192.168.10.255' SERVER='192.168.10.2/32' ANY='0.0.0.0/0' ########################################################### # Init ########################################################### #Enable SYN Cookie echo '1' > /proc/sys/net/ipv4/tcp_syncookies #Disable Broadcat Ping echo '1' > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts #Enable Forward echo '1' > /proc/sys/net/ipv4/ip_forward #ftp passive modprobe ip_conntrack_ftp #Flush & Reset iptables -F iptables -X # User Chain iptables -N WAN_TO_SERVER iptables -N SERVER_TO_WAN iptables -N LAN_TO_SERVER iptables -N SERVER_TO_LAN iptables -N LOGGING ########################################################### #Deafult Rule ########################################################### iptables -P INPUT DROP iptables -P OUTPUT DROP iptables -P FORWARD DROP iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -s $LOCALNET -d ${SERVER} -j LAN_TO_SERVER iptables -A INPUT -s $LOCALNET -d ${BROADCAST} -j LAN_TO_SERVER iptables -A INPUT -s $ANY -d $SERVER -j WAN_TO_SERVER iptables -A INPUT -j LOGGING iptables -A OUTPUT -o lo -j ACCEPT iptables -A OUTPUT -s $SERVER -d $LOCALNET -j SERVER_TO_LAN iptables -A OUTPUT -s $SERVER -d $ANY -j SERVER_TO_WAN iptables -A OUTPUT -j LOGGING iptables -A FORWARD -j LOGGING ########################################################### #LAN_TO_SERVER & SERVER_TO_LAN ########################################################### iptables -A LAN_TO_SERVER -s $LOCALNET -j ACCEPT iptables -A SERVER_TO_LAN -d $LOCALNET -j ACCEPT iptables -A FORWARD -s $LOCALNET -j ACCEPT ########################################################### #SERVER_TO_WAN ########################################################### iptables -A SERVER_TO_WAN -m state --state ESTABLISHED,RELATED -j ACCEPT #NTP iptables -A SERVER_TO_WAN -p udp --dport 123 -j ACCEPT iptables -A SERVER_TO_WAN -p tcp --dport 123 -m state --state NEW -j ACCEPT #DNS iptables -A SERVER_TO_WAN -p udp --dport 53 -j ACCEPT iptables -A SERVER_TO_WAN -p tcp --dport 53 -m state --state NEW -j ACCEPT #ftp iptables -A SERVER_TO_WAN -p tcp --dport 21 -m state --state NEW -j ACCEPT #http iptables -A SERVER_TO_WAN -p tcp --dport 80 -m state --state NEW -j ACCEPT #https iptables -A SERVER_TO_WAN -p tcp --dport 443 -m state --state NEW -j ACCEPT #smtp iptables -A SERVER_TO_WAN -p tcp --dport 25 -m state --state NEW -j ACCEPT #pop3 iptables -A SERVER_TO_WAN -p tcp --dport 110 -m state --state NEW -j ACCEPT #pop3s iptables -A SERVER_TO_WAN -p tcp --dport 995 -m state --state NEW -j ACCEPT #ICMP iptables -A SERVER_TO_WAN -p icmp -j ACCEPT #logging iptables -A SERVER_TO_WAN -j LOGGING ########################################################### #WAN_TO_SERVER ########################################################### iptables -A WAN_TO_SERVER -m state --state ESTABLISHED,RELATED -j ACCEPT #web iptables -A WAN_TO_SERVER -p tcp --dport 80 -m state --state NEW -j ACCEPT #smtp iptables -A WAN_TO_SERVER -p tcp --dport 25 -m state --state NEW -j ACCEPT #ssh iptables -A WAN_TO_SERVER -p tcp --dport 22 -m state --state NEW -j ACCEPT #pop3s iptables -A WAN_TO_SERVER -p tcp --dport 995 -m state --state NEW -j ACCEPT #OpenVPN iptables -A WAN_TO_SERVER -p udp --dport 1194 -j ACCEPT #Ident Reject iptables -A WAN_TO_SERVER -p tcp --dport 113 -m state --state NEW -j REJECT --reject-with tcp-reset #ICMP(ping) iptables -A WAN_TO_SERVER -p icmp --icmp-type 0 -j ACCEPT #loggin iptables -A WAN_TO_SERVER -j LOGGING ########################################################### #LOGGING ########################################################### #iptables -A LOGGING -j LOG --log-level warning --log-prefix "DROP:" -m limit iptables -A LOGGING -j LOG --log-level warning --log-prefix "DROP:" iptables -A LOGGING -j DROP