/usr/sbin/nat_local.sh
#!/bin/bash
#################################################################
# reset the default policies in the filter table. #
#################################################################
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
#################################################################
# reset the default policies in the nat table. #
#################################################################
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
#################################################################
# reset the default policies in the mangle table. #
#################################################################
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
#################################################################
# flush all the rules in the filter and nat tables. #
#################################################################
iptables -F
iptables -t nat -F
iptables -t mangle -F
#################################################################
# erase all chains that's not default in filter and nat table. #
#################################################################
iptables -X
iptables -t nat -X
iptables -t mangle -X
#################################################################
# politika by default #
#################################################################
iptables -P FORWARD DROP
#################################################################
export LAN=eth1
export WAN=ppp0
iptables -I INPUT 1 -i ${LAN} -j ACCEPT
iptables -I INPUT 1 -i lo -j ACCEPT
iptables -A INPUT -p UDP --dport bootps -i ! ${LAN} -j REJECT
iptables -A INPUT -p UDP --dport domain -i ! ${LAN} -j REJECT
iptables -A INPUT -p TCP --dport ssh -i ${WAN} -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i ${LAN} -s 192.168.0.0/255.255.255.0 -j ACCEPT
iptables -A FORWARD -i ${WAN} -d 192.168.0.0/255.255.255.0 -j ACCEPT
iptables -A FORWARD -i eth0 -d 192.168.0.0/255.255.255.0 -j ACCEPT
#################################################################
# Drop ports #
#################################################################
iptables -A INPUT -i ${WAN} -p tcp -m multiport --dports 111,135,136,137,138,139,445,953,1723,2628 -j REJECT --reject-with icmp-port-unreachable
#################################################################
# bad_tcp_packets #
#################################################################
iptables -N bad_tcp_packets
iptables -A bad_tcp_packets -p tcp --tcp-flags SYN,ACK SYN,ACK -m state --state NEW -j REJECT --reject-with tcp-reset
iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP
iptables -A INPUT -p tcp -j bad_tcp_packets
iptables -A FORWARD -p tcp -j bad_tcp_packets
iptables -A OUTPUT -p tcp -j bad_tcp_packets
#################################################################
# Torrents* * * * * * * * * * * * * * * * * #
#################################################################
iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport 61926 -j DNAT --to-destination 192.168.0.2:61926
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 61926 -j DNAT --to-destination 192.168.0.2:61926
iptables -A FORWARD -d 192.168.0.2 -p tcp --dport 61926 -j ACCEPT
iptables -A FORWARD -d 192.168.0.2 -p udp --dport 61926 -j ACCEPT
#################################################################
# ICQ/Jabber Files #
#################################################################
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 64544 -j DNAT --to-destination 192.168.0.2:64544
iptables -t nat -A PREROUTING -i eth0 -p udp --dport 64544 -j DNAT --to-destination 192.168.0.2:64544
iptables -A FORWARD -d 192.168.0.2 -p tcp --dport 64544 -j ACCEPT
iptables -A FORWARD -d 192.168.0.2 -p udp --dport 64544 -j ACCEPT
#################################################################
# DC++* * * * * * * * ** * * * * * * * * * * #
#################################################################
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 35477 -j DNAT --to-destination 192.168.0.2:35477
iptables -A FORWARD -d 192.168.0.2 -p tcp --dport 35477 -j ACCEPT
#
iptables -t nat -A PREROUTING -i eth0 -p udp --dport 35466 -j DNAT --to-destination 192.168.0.2:35466
iptables -A FORWARD -d 192.168.0.2 -p udp --dport 35466 -j ACCEPT
#
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 35455 -j DNAT --to-destination 192.168.0.2:35455
iptables -A FORWARD -d 192.168.0.2 -p tcp --dport 35455 -j ACCEPT
#
iptables -t nat -A POSTROUTING -o ${WAN} -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE