#!/bin/sh
# Path To Iptables (you need to edit that probably)
IPTABLES=/usr/sbin/iptables
# TCP-Ports (enter ports you want open from outside, seperated by comma (maybe ssh))
TCP_PORTS="666"
# UDP-Ports (open ports UDP, for example samba)
UDP_PORTS="666"
# Internet Interface
INET="eth1"
# LAN Interface
LAN="eth0"
startup()
{
# Flush (delete all present rules)
$IPTABLES -F
$IPTABLES -t nat -F
# set default policy
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD DROP
}
chain_input()
{
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# accept TCP & UDP ports as specified above
$IPTABLES -A INPUT -i $INET -p tcp -m state --state NEW -m multiport --dports $TCP_PORTS -j ACCEPT
$IPTABLES -A INPUT -i $INET -p udp -m state --state NEW -m multiport --dports $UDP_PORTS -j ACCEPT
$IPTABLES -A INPUT -i $LAN -m state --state NEW -j ACCEPT
#$IPTABLES -A INPUT -i $LAN -j LOG --prefix "Drop: INPUT (LAN)"
$IPTABLES -A INPUT -i $INET -j LOG --log-prefix "Drop: INPUT (INET)"
}
chain_forward()
{
$IPTABLES -t nat -A POSTROUTING -o $INET -j SNAT --to 123.456.78.90
$IPTABLES -A FORWARD -i $LAN -j ACCEPT
$IPTABLES -A FORWARD -i $INET -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $INET -j LOG --log-prefix "Drop: FORWARD (INET)"
$IPTABLES -A FORWARD -i $LAN -j LOG --log-prefix "Drop: FORWARD (LAN)"
}
startup
chain_input
chain_forward