Setting up NAT and MonMotha's firewall
In order to implement NAT (Network Address Translation) also known as Internet Sharing you need to first install ip-masquerading. You will find all the details about ip-masquerading on their homepage.
apt-get install ipmasq
You need to implement ipv4 for iptables to work so do;
This should bring up a text menu. If it doesn't, then install modconf using apt. Go down the list until you see "kernel/net/ipv4/netfilter", select this option and go down the list and select ip_tables. After installing go down the list again and ensure that the module iptable_nat has a "+" next to it. If it doesn't install it. You need the following for MonMotha's script (from requirements in the script);
You will need (at least) the following kernel options to use this firewall:
IP_IPTABLES,IP_FILTER,IP_MATCH_STATE and IP_TARGET_REJECT.
| To use the masquerading you will also need (at least):
IP_CONNTRACK, IP_NAT, IP_NAT_NEEDED and IP_TARGET_MASQUERADE
Now you need MonMotha's script. When you have opened the download link, you will be presented with an ftp file structure. Go down to 2.3 and select the latest version rc.firewall-2.3.8-pre9 (The server hosting MonMotha's script is apparantly down (10/03/2006) so use my copy). You can also download the same file from me here. This will present as a text page. Copy and paste the text into a text editor. The basic setting parameters follow the comments list. The following is what it looks like;
# Main Options
TCP_ALLOW="80 25 22"
UDP_ALLOW="68 6112 6119 4000"
BAD_ICMP="5 9 10 15 16 17 18"
# Flood Params
# Outbound filters
# FIXME: Update config help wiki then remove one-liner help
ALLOW_OUT_TCP="" # Internal hosts allowed to be forwarded out on TCP (do not put
this/these host/s in INTERNAL_LAN, but do define their method of access [snat, masq] if not a public ip)
PROXY="" # Redirect for Squid or other TRANSPARENT proxy. Syntax to specify the
proxy is "host:port".
MY_IP="" # Set to the internal IP of this box (with the firewall), only needed for
PROXY= # Below here is experimental (please report your successes/failures)
MAC_MASQ="" # Currently Broken
MAC_SNAT="" # Ditto...
# Only touch these if you're daring (PREALPHA stuff, as in basically non-functional)
DMZ_IFACE="" # Interface your DMZ is on (leave blank if you don't have one) -
Obsolete: Will be removed before 2.4.0
There are some key lines above that need to be configured;
TCP_ALLOW="80 25 22"
These are the ports that are open. Default are 80 for http, 25 for email and 22 for sftp. If you want to add or reduce the open ports this is place to do it. The same goes for the line below which are the ports for UDP
This is the network card number that connects with your router or the Internet facing NIC and in this case it is "eth1".
This specifies the network card facing your internal network and is specified as "eth0"
Let's look at how to use these rules. I have had problems with users from certain IP addresses and have taken the decision to exclude them from access to the server so I have the following rule;
DENY_ALL="184.108.40.206/23 220.127.116.11/23 18.104.22.168/23 22.214.171.124/23"
Note that the suffix "/23" excludes all addresses from 0 through 255. If you wanted to exclude an IP purely from port 80 then apply the following rule;
Now having set up the various parameters you need to save the script. This is done by saving it as "rc.firewall.sh in /etc/init.d Now to make the script executable from a consol as root do;
chmod 700 rc.firewall
Check to see if the script will run by doing as root from a consol;
The script should output what it is doing and should be error free. If you get errors then you need to correct the script relevant to the error message that you get. You can stop the script running by using the same command but instead of using "start" use "stop".
update-rc.d rc.firewall defaults 89
If you ever want to remove the soft links for initiating the script during the boot phase then do;
update-rc.d -f rc.firewall remove
I hope you find the information
useful and enjoy the site. If you have any suggestions or
comments or would like to contact me then please e-mail me