Basic Two-Interface FirewallTomEastep200220032004Thomas M. Eastep
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 GNU Free Documentation License.
Introduction
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.
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:
Linux system used as a firewall/router for a small local network.
Single public IP address. If you have more than one public IP address, this is not the guide you want -- see the Shorewall Setup Guide instead.
Internet connection through cable modem, DSL, ISDN, Frame Relay, dial-up ...
Here is a schematic of a typical installation:
Shorewall and Mandrake 9.0+
If you are running Shorewall under Mandrake 9.0 or later, you can easily configure the above setup using the MandrakeInternet Connection Sharing applet. From the Mandrake Control Center, select Network & Internet then Connection Sharing.
Note however, that the Shorewall configuration produced by Mandrake Internet Connection Sharing is strange and is apt to confuse you if you use the rest of this documentation (it has two local zones; loc and masq where loc is empty; this conflicts with this documentation which assumes a single local zone loc). We therefore recommend that once you have set up this sharing that you uninstall the Mandrake Shorewall RPM and install the one from the download page then follow the instructions in this Guide.
If you edit your configuration files on a Windows system, you must save them as Unix files if your editor supports that option or you must run them through dos2unix before trying to use them. Similarly, if you copy a configuration file from your Windows hard drive to a floppy disk, you must run dos2unix against the copy before using it with Shorewall.
Windows Version of dos2unixLinux Version of dos2unixSystem Requirements
Shorewall requires that you have the iproute/iproute2 package installed (on RedHat, the package is called iproute). You can tell if this package is installed by the presence of an ip program on your firewall system. As root, you can use the which command to check for this program:
[root@gateway root]# which ip
/sbin/ip
[root@gateway root]#
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.
Conventions
Points at which configuration changes are recommended are flagged with .
Configuration notes that are unique to LEAF/Bering are marked with .
PPTP/ADSLIf you have an ADSL Modem and you use PPTP to communicate with a server in that modem, you must make the changes recommended here in addition to those detailed below. ADSL with PPTP is most commonly found in Europe, notably in Austria.
Shorewall ConceptsThe configuration files for Shorewall are contained in the directory /etc/shorewall -- for simple setups, you will only need to deal with a few of these as described in this guide.
After you have installed Shorewall, download the two-interface sample, un-tar it (tar two-interfaces.tgz) and and copy the files to /etc/shorewall(these files will replace files with the same name).
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:
NameDescriptionnetThe InternetlocYour Local NetworkdmzDemilitarized Zone
Zones are defined in the /etc/shorewall/zones file.
Shorewall also recognizes the firewall system as its own zone - by default, the firewall itself is known as fw.
Rules about what traffic to allow and what traffic to deny are expressed in terms of zones.
You express your default policy for connections from one zone to another zone in the /etc/shorewall/policy file.
You define exceptions to those default policies in the /etc/shorewall/rules file.
For each connection request entering the firewall, the request is first checked against the /etc/shorewall/rules file. If no rule in that file matches the connection request then the first policy in /etc/shorewall/policy that matches the request is applied. If that policy is REJECT or DROP the request is first checked against the rules in /etc/shorewall/common if that file exists; otherwise the rules in /etc/shorewall/common.def are checked.
The /etc/shorewall/policy file included with the two-interface sample has the following policies: