#!/bin/sh # # firewall-masq This script sets up firewall rules for a machine # acting as a masquerading gateway # # Copyright (C) 2000 Roaring Penguin Software Inc. This software may # be distributed under the terms of the GNU General Public License, version # 2 or any later version. # Interface to Internet EXTIF=eth1 # IP address of external interface EXTIP=`ifconfig $EXTIF | grep addr | cut -d: -f 2 | cut -d " " -f 1` echo $EXTIP #Change the action to -I (insert) to open netbios access #Change the action to -D (delete) to remove the previously configured access ACTION="-D" ACTION=$1 echo ftp rule action will be $ACTION logger -t rc.iptables.tftp-open iptables netbios action -- $ACTION started #PORT=21 #iptables $ACTION INPUT -i $EXTIF -p tcp --destination-port $PORT -j ACCEPT #iptables $ACTION OUTPUT -p tcp --source-port $PORT -j ACCEPT #Port forwarding to allow a web and mail server on boxes inside the firewall I_IP=10.1.1.1 I_PORT=21 E_PORT=21 echo Forwarding port $I_PORT on $EXTIP to $E_PORT on $I_IP iptables -t mangle $ACTION PREROUTING -p tcp --source ! 10.0.0.0/8 --dport $E_PORT -j ACCEPT iptables -t nat $ACTION PREROUTING -p tcp --source ! 10.0.0.0/8 --dport $E_PORT -j DNAT --to-destination "$I_IP:$I_PORT" iptables -t filter $ACTION FORWARD -p tcp -d $I_IP --dport $I_PORT -j ACCEPT iptables -t nat $ACTION POSTROUTING -p tcp -d $I_IP --dport $I_PORT -j ACCEPT logger -t rc.iptables.ftp-open netbios action -- $ACTION completed