Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover, and with no Back-Cover Texts. A copy of the license is included in the section entitled <quote><ulinkurl="GnuCopyright.htm">GNU Free Documentation License</ulink></quote>.
Setting up a Linux system as a firewall for a small network is a fairly straight-forward task if you understand the basics and follow the documentation.
</para>
<para>
This guide doesn't attempt to acquaint you with all of the features of Shorewall. It rather focuses on what is required to configure Shorewall in its most common configuration:
</para>
<itemizedlistmark="bullet"spacing="compact">
<listitem>
<para>
Linux system used as a firewall/router for a small local network.
</para>
</listitem>
<listitem>
<para>
<emphasisrole="bold">Single public IP address.</emphasis> If you have more than one public IP address, this is not the guide you want -- see the <ulinkurl="shorewall_setup_guide.htm">Shorewall Setup Guide</ulink> instead.
</para>
</listitem>
<listitem>
<para>
Internet connection through cable modem, DSL, ISDN, Frame Relay, dial-up ...
</para>
</listitem>
</itemizedlist>
<para>
Here is a schematic of a typical installation:
<figurelabel="1">
<title>Common two interface firewall configuration</title>
<title>Shorewall and <trademark>Mandrake</trademark> 9.0+</title>
<para>
If you are running Shorewall under <trademark>Mandrake</trademark> 9.0 or later, you can easily configure the above setup using the <trademark>Mandrake</trademark><quote>Internet Connection Sharing</quote> applet. From the <emphasis><interface>Mandrake Control Center</interface></emphasis>, select <quote><guimenuitem>Network</guimenuitem>&<guisubmenu>Internet</guisubmenu></quote> then <quote><interface>Connection Sharing</interface></quote>.
</para>
<para>
Note however, that the Shorewall configuration produced by <emphasis>Mandrake Internet Connection Sharing</emphasis> is strange and is apt to confuse you if you use the rest of this documentation (it has two local zones; <varname>loc</varname> and <varname>masq</varname> where <varname>loc</varname> is empty; this conflicts with this documentation which assumes a single local zone <varname>loc</varname>). We therefore recommend that once you have set up this sharing that you uninstall the <trademark>Mandrake</trademark> Shorewall RPM and install the one from the <ulinkurl="download.htm">download</ulink> page then follow the instructions in this Guide.
If you edit your configuration files on a <trademark>Windows</trademark> system, you must save them as <trademark>Unix</trademark> files if your editor supports that option or you must run them through <command>dos2unix</command> before trying to use them. Similarly, if you copy a configuration file from your <trademark>Windows</trademark> hard drive to a floppy disk, you must run <command>dos2unix</command> against the copy before using it with Shorewall.
<itemizedlist>
<listitem>
<para><ulinkurl="http://www.simtel.net/pub/pd/51438.html"><trademark>Windows</trademark> Version of <command>dos2unix</command></ulink></para>
</listitem>
<listitem>
<para><ulinkurl="http://www.megaloman.com/%7Ehany/software/hd2u/">Linux Version of <command>dos2unix</command></ulink></para>
Shorewall requires that you have the <command>iproute</command>/<command>iproute2</command> package installed (on <trademark>RedHat</trademark>, the package is called <command>iproute</command>). You can tell if this package is installed by the presence of an <command>ip</command> program on your firewall system. As <systemitemclass="username">root</systemitem>, you can use the <command>which</command> command to check for this program:
<programlisting>
[root@gateway root]# which ip
/sbin/ip
[root@gateway root]#
</programlisting>
I recommend that you first read through the guide to familiarize yourself with what's involved then go back through it again making your configuration changes.
<inlinegraphicfileref="images/BD21298_.gif"format="GIF"/>If you have an <acronym>ADSL</acronym> Modem and you use <acronym>PPTP</acronym> to communicate with a server in that modem, you must make the changes recommended here in addition to those detailed below. <acronym>ADSL</acronym> with <acronym>PPTP</acronym> is most commonly found in Europe, notably in Austria.
<inlinegraphicfileref="images/BD21298_.gif"format="GIF"/>The configuration files for Shorewall are contained in the directory <filenameclass="directory">/etc/shorewall</filename> -- for simple setups, you will only need to deal with a few of these as described in this guide.
<tip>
<para>
After you have <ulinkurl="Install.htm">installed Shorewall</ulink>, download the <ulinkurl="http://www1.shorewall.net/pub/shorewall/Samples/">two-interface sample</ulink>, un-tar it (<command>tar <option>-zxvf</option><filename>two-interfaces.tgz</filename></command>) and and copy the files to <filenameclass="directory">/etc/shorewall</filename><emphasisrole="bold">(these files will replace files with the same name)</emphasis>.
</para>
</tip>
As each file is introduced, I suggest that you look through the actual file on your system -- each file contains detailed configuration instructions and default entries.
Shorewall views the network where it is running as being composed of a set of zones. In the two-interface sample configuration, the following zone names are used:
<informaltableframe="all"pgwide="0">
<tgroupcols="2"align="left">
<theadvalign="middle">
<rowvalign="middle">
<entryalign="left">Name</entry>
<entryalign="left">Description</entry>
</row>
</thead>
<tbodyvalign="middle">
<rowvalign="middle">
<entryalign="left"><varname>net</varname></entry>
<entryalign="left">The Internet</entry>
</row>
<rowvalign="middle">
<entryalign="left"><varname>loc</varname></entry>
<entryalign="left">Your Local Network</entry>
</row>
<rowvalign="middle">
<entryalign="left"><varname>dmz</varname></entry>
<entryalign="left">Demilitarized Zone</entry>
</row>
</tbody>
</tgroup>
</informaltable>
Zones are defined in the <ulinkurl="Documentation.htm#Zones"><filenameclass="directory">/etc/shorewall/</filename><filename>zones</filename></ulink> file.
You express your default policy for connections from one zone to another zone in the <ulinkurl="Documentation.htm#Policy"><filenameclass="directory">/etc/shorewall/</filename><filename>policy</filename></ulink> file.
You define exceptions to those default policies in the <ulinkurl="Documentation.htm#Rules"><filenameclass="directory">/etc/shorewall/</filename><filename>rules</filename></ulink> file.
For each connection request entering the firewall, the request is first checked against the <filenameclass="directory">/etc/shorewall/</filename><filename>rules</filename> file. If no rule in that file matches the connection request then the first policy in <filenameclass="directory">/etc/shorewall/</filename><filename>policy</filename> that matches the request is applied. If that policy is <varname>REJECT</varname> or <varname>DROP</varname> the request is first checked against the rules in <filenameclass="directory">/etc/shorewall/</filename><filename>common</filename> if that file exists; otherwise the rules in <filenameclass="directory">/etc/shorewall/</filename><filename>common.def</filename> are checked.
</para>
<para>
The <filenameclass="directory">/etc/shorewall/</filename><filename>policy</filename> file included with the two-interface sample has the following policies: