2004-02-14 19:06:39 +01:00
<?xml version="1.0" encoding="UTF-8"?>
2008-07-07 22:42:54 +02:00
< !DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
2004-02-14 19:06:39 +01:00
<article id= "three-interface" >
<!-- $Id$ -->
<articleinfo >
<title > Three-Interface Firewall</title>
<authorgroup >
<author >
<firstname > Tom</firstname>
<surname > Eastep</surname>
</author>
</authorgroup>
2006-07-07 03:04:16 +02:00
<pubdate > <?dbtimestamp format="Y/m/d"?> </pubdate>
2004-02-14 19:06:39 +01:00
<copyright >
2009-06-16 23:33:35 +02:00
<year > 2002-2009</year>
2004-02-14 19:06:39 +01:00
<holder > Thomas M. Eastep</holder>
</copyright>
<legalnotice >
<para > 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
2004-08-17 00:17:09 +02:00
<quote > <ulink url= "GnuCopyright.htm" > GNU Free Documentation
License</ulink> </quote> .</para>
2004-02-14 19:06:39 +01:00
</legalnotice>
</articleinfo>
2005-09-19 21:27:22 +02:00
<caution >
2009-06-16 23:33:35 +02:00
<para > <emphasis role= "bold" > This article applies to Shorewall 4.4 and
2005-09-19 21:27:22 +02:00
later. If you are running a version of Shorewall earlier than Shorewall
2009-06-16 23:33:35 +02:00
4.4.0 then please see the documentation for that
2005-09-19 21:27:22 +02:00
release.</emphasis> </para>
</caution>
2007-06-29 00:06:10 +02:00
<section id= "Intro" >
2004-02-14 19:06:39 +01:00
<title > Introduction</title>
<para > Setting up a Linux system as a firewall for a small network with DMZ
is a fairly straight-forward task if you understand the basics and follow
the documentation.</para>
2004-08-17 00:17:09 +02:00
<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 one of its more popular configurations:</para>
2004-02-14 19:06:39 +01:00
<itemizedlist >
<listitem >
<para > Linux system used as a firewall/router for a small local
network.</para>
</listitem>
<listitem >
<para > Single public IP address.</para>
<note >
<para > If you have more than one public IP address, this is not the
2004-08-17 00:17:09 +02:00
guide you want -- see the <ulink
url="shorewall_setup_guide.htm">Shorewall Setup Guide</ulink>
instead.</para>
2004-02-14 19:06:39 +01:00
</note>
</listitem>
<listitem >
2008-08-15 07:03:24 +02:00
<para > DMZ connected to a separate Ethernet interface. The purpose of a
2005-04-07 18:35:59 +02:00
DMZ is to isolate those servers that are exposed to the Internet from
your local systems so that if one of those servers is compromised
there is still a firewall between the hacked server and your local
systems.</para>
2004-02-14 19:06:39 +01:00
</listitem>
<listitem >
<para > Connection through DSL, Cable Modem, ISDN, Frame Relay, dial-up,
...</para>
</listitem>
</itemizedlist>
<para > Here is a schematic of a typical installation.</para>
2007-06-29 00:06:10 +02:00
<figure id= "Figure1" >
2004-02-14 19:06:39 +01:00
<title > schematic of a typical installation</title>
<mediaobject >
<imageobject >
2016-02-19 20:02:48 +01:00
<imagedata align= "center" fileref= "images/dmz1.png" format= "PNG" />
2004-02-14 19:06:39 +01:00
</imageobject>
</mediaobject>
</figure>
2007-06-29 00:06:10 +02:00
<section id= "Reqs" >
2004-02-14 19:06:39 +01:00
<title > Requirements</title>
2004-08-17 00:17:09 +02:00
<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 <systemitem class= "username" > root</systemitem> , you can use
the <command > which</command> command to check for this program:</para>
2004-02-14 19:06:39 +01:00
<programlisting > [root@gateway root]# <command > which ip</command>
/sbin/ip
[root@gateway root]#</programlisting>
</section>
2007-06-29 00:06:10 +02:00
<section id= "Before" >
2004-02-14 19:06:39 +01:00
<title > Before you start</title>
<para > I recommend that you first read through the guide to familiarize
2004-08-17 00:17:09 +02:00
yourself with what's involved then go back through it again making your
configuration changes.</para>
2004-02-14 19:06:39 +01:00
<caution >
<para > 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.</para>
<itemizedlist >
<listitem >
2013-09-19 17:14:26 +02:00
<para > <ulink
url="http://www.sourceforge.net/projects/dos2unix">Windows Version
of dos2unix</ulink> </para>
2004-02-14 19:06:39 +01:00
</listitem>
<listitem >
2004-08-17 00:17:09 +02:00
<para > <ulink
url="http://www.megaloman.com/%7Ehany/software/hd2u/">Linux
2004-02-14 19:06:39 +01:00
Version of dos2unix</ulink> </para>
</listitem>
</itemizedlist>
</caution>
</section>
2007-06-29 00:06:10 +02:00
<section id= "Conventions" >
2004-02-14 19:06:39 +01:00
<title > Conventions</title>
<para > Points at which configuration changes are recommended are flagged
2016-02-19 20:02:48 +01:00
with <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> .</para>
2004-02-14 19:06:39 +01:00
2009-12-04 18:06:00 +01:00
<para > Configuration notes that are unique to Debian and it's derivatives
are marked with <inlinegraphic fileref= "images/openlogo-nd-25.png"
2016-02-19 20:02:48 +01:00
format="GIF"/>.</para>
2004-02-14 19:06:39 +01:00
</section>
</section>
2007-06-29 00:06:10 +02:00
<section id= "PPTP" >
2004-02-14 19:06:39 +01:00
<title > PPTP/ADSL</title>
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2004-02-14 19:06:39 +01:00
<para > If you have an ADSL Modem and you use PPTP to communicate with a
2004-08-17 00:17:09 +02:00
server in that modem, you must make the <ulink
url="PPTP.htm#PPTP_ADSL">changes recommended here</ulink> in addition to
those detailed below. ADSL with PPTP is most commonly found in Europe,
notably in Austria.</para>
2004-02-14 19:06:39 +01:00
</section>
2007-06-29 00:06:10 +02:00
<section id= "Concepts" >
2004-02-14 19:06:39 +01:00
<title > Shorewall Concepts</title>
<para > The configuration files for Shorewall are contained in the directory
<filename > /etc/shorewall</filename> -- for simple setups, you will only
2011-04-04 04:32:39 +02:00
need to deal with a few of these as described in this guide.</para>
2004-05-19 19:55:45 +02:00
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2004-09-07 18:09:11 +02:00
2005-10-22 19:37:38 +02:00
<para > After you have installed Shorewall, locate the three-interface
Sample configuration:</para>
<orderedlist >
<listitem >
<para > If you installed using an RPM, the samples will be in the
Samples/three-interfaces/ subdirectory of the Shorewall documentation
directory. If you don't know where the Shorewall documentation
directory is, you can find the samples using this command:</para>
2011-01-14 04:24:15 +01:00
<programlisting > ~# rpm -ql shorewall | fgrep three-interfaces
2005-10-22 19:37:38 +02:00
/usr/share/doc/packages/shorewall/Samples/three-interfaces
/usr/share/doc/packages/shorewall/Samples/three-interfaces/interfaces
/usr/share/doc/packages/shorewall/Samples/three-interfaces/masq
/usr/share/doc/packages/shorewall/Samples/three-interfaces/policy
/usr/share/doc/packages/shorewall/Samples/three-interfaces/rules
/usr/share/doc/packages/shorewall/Samples/three-interfaces/zones
~#</programlisting>
</listitem>
<listitem >
<para > If you installed using the tarball, the samples are in the
Samples/three-interfaces directory in the tarball.</para>
</listitem>
2005-11-02 23:16:43 +01:00
<listitem >
2007-11-29 16:43:38 +01:00
<para > If you installed using a Shorewall 3.x .deb, the samples are in
2007-04-03 17:21:35 +02:00
/usr/share/doc/shorewall/examples/three-interfaces. You must install
the shorewall-doc package.</para>
2005-11-02 23:16:43 +01:00
</listitem>
2007-11-29 16:43:38 +01:00
<listitem >
2016-02-19 20:02:48 +01:00
<para > <graphic align= "left" fileref= "images/openlogo-nd-25.png" /> If
2011-04-04 04:32:39 +02:00
you installed using a Shorewall 4.x .deb, the samples are in <emphasis
role="bold"><filename
class="directory">/usr/share/doc/shorewall/examples/three-interfaces</filename> </emphasis> .
2007-11-29 16:50:04 +01:00
You do not need the shorewall-doc package to have access to the
samples.</para>
2011-04-04 04:32:39 +02:00
<warning >
<para > <emphasis role= "bold" > Note to Debian Users</emphasis> </para>
<para > If you install using the .deb, you will find that your
<filename class= "directory" > /etc/shorewall</filename> directory is
empty. This is intentional. The released configuration file
skeletons may be found on your system in the directory <filename
class="directory">/usr/share/doc/shorewall/default-config</filename> .
Simply copy the files you need from that directory to <filename
class="directory">/etc/shorewall</filename> and modify the
copies.</para>
</warning>
2007-11-29 16:43:38 +01:00
</listitem>
2005-10-22 19:37:38 +02:00
</orderedlist>
2004-02-14 19:06:39 +01:00
2011-06-07 00:40:21 +02:00
<para > As each file is introduced, I suggest that you look at the actual
file on your system and that you look at the <ulink
2006-12-23 23:56:47 +01:00
url="configuration_file_basics.htm#Manpages">man page</ulink> for that
2006-12-22 17:22:10 +01:00
file. For example, to look at the man page for the
<filename > /etc/shorewall/zones</filename> file, type <command > man
shorewall-zones</command> at a shell prompt.</para>
2011-06-07 00:40:21 +02:00
<para > Note: Beginning with Shorewall 4.4.20.1, there are versions of the
sample files that are annotated with the corresponding manpage contents.
These files have names ending in '.annotated'. You might choose to look at
those files instead.</para>
2004-02-14 19:06:39 +01:00
<para > Shorewall views the network where it is running as being composed of
a set of zones. In the three-interface sample configuration, the following
zone names are used:</para>
2016-02-19 20:02:48 +01:00
<para > <programlisting > #ZONE TYPE OPTIONS IN_OPTIONS OUT_OPTIONS
2005-09-12 20:43:26 +02:00
fw firewall
2005-09-30 19:39:24 +02:00
net ipv4
loc ipv4
dmz ipv4</programlisting> Zone names are defined in
2004-08-17 00:17:09 +02:00
<filename > /etc/shorewall/zones</filename> .</para>
2004-02-14 19:06:39 +01:00
2005-09-12 20:43:26 +02:00
<para > Note that Shorewall recognizes the firewall system as its own zone.
When the /etc/shorewall/zones file is processed, he name of the firewall
zone is stored in the shell variable <firstterm > $FW</firstterm> which may
be used throughout the Shorewall configuration to refer to the firewall
zone.</para>
2004-02-14 19:06:39 +01:00
<para > Rules about what traffic to allow and what traffic to deny are
expressed in terms of zones.</para>
<itemizedlist >
<listitem >
<para > You express your default policy for connections from one zone to
2004-08-17 00:17:09 +02:00
another zone in the <filename > /etc/shorewall/policy</filename>
file.</para>
2004-02-14 19:06:39 +01:00
</listitem>
<listitem >
<para > You define exceptions to those default policies in the
<filename > /etc/shorewall/rules</filename> file.</para>
</listitem>
</itemizedlist>
<para > For each connection request entering the firewall, the request is
first checked against the <filename > /etc/shorewall/rules</filename> file.
If no rule in that file matches the connection request then the first
policy in <filename > /etc/shorewall/policy</filename> that matches the
2004-05-09 00:31:54 +02:00
request is applied. If there is a <ulink
2009-02-18 17:48:34 +01:00
url="shorewall_extension_scripts.htm">common action</ulink> defined for
the policy in <filename > /etc/shorewall/actions</filename> or
2004-05-09 00:31:54 +02:00
<filename > /usr/share/shorewall/actions.std</filename> then that action is
2009-02-18 17:48:34 +01:00
performed before the action is applied. The purpose of the common action
is two-fold:</para>
2006-10-01 17:58:15 +02:00
<itemizedlist >
<listitem >
<para > It silently drops or rejects harmless common traffic that would
otherwise clutter up your log — Broadcasts for example.</para>
</listitem>
<listitem >
<para > If ensures that traffic critical to correct operation is allowed
through the firewall — ICMP <emphasis > fragmentation-needed</emphasis>
for example.</para>
</listitem>
</itemizedlist>
2004-02-14 19:06:39 +01:00
<para > The <filename > /etc/shorewall/policy</filename> file included with
the three-interface sample has the following policies:</para>
2016-02-19 20:02:48 +01:00
<programlisting > #SOURCE DEST POLICY LOGLEVEL LIMIT
2004-02-14 19:06:39 +01:00
loc net ACCEPT
net all DROP info
all all REJECT info</programlisting>
<important >
<para > In the three-interface sample, the line below is included but
commented out. If you want your firewall system to have full access to
2008-08-15 07:03:24 +02:00
servers on the Internet, uncomment that line.</para>
2004-02-14 19:06:39 +01:00
2016-02-19 20:02:48 +01:00
<programlisting > #SOURCE DEST POLICY LOGLEVEL LIMIT
2005-09-12 20:43:26 +02:00
$FW net ACCEPT</programlisting>
2004-02-14 19:06:39 +01:00
</important>
<para > The above policy will:</para>
<orderedlist >
<listitem >
<para > allow all connection requests from your local network to the
2008-08-15 07:03:24 +02:00
Internet</para>
2004-02-14 19:06:39 +01:00
</listitem>
<listitem >
2008-08-15 07:03:24 +02:00
<para > drop (ignore) all connection requests from the Internet to your
2004-02-14 19:06:39 +01:00
firewall or local network</para>
</listitem>
<listitem >
<para > optionally accept all connection requests from the firewall to
2008-08-15 07:03:24 +02:00
the Internet (if you uncomment the additional policy)</para>
2004-02-14 19:06:39 +01:00
</listitem>
<listitem >
<para > reject all other connection requests.</para>
</listitem>
</orderedlist>
2008-01-04 20:31:42 +01:00
<para > The word <firstterm > info</firstterm> in the LOG LEVEL column for the
2008-08-15 07:03:24 +02:00
DROP and REJECT policies indicates that packets dropped or rejected under
2008-01-04 20:31:42 +01:00
those policies should be <ulink url= "shorewall_logging.html" > logged at
2008-08-15 07:03:24 +02:00
that level</ulink> .</para>
2008-01-04 20:31:42 +01:00
2009-08-16 19:17:48 +02:00
<para > Some people want to consider their firewall to be part of their
local network from a security perspective. If you want to do this, add
these two policies:</para>
2016-02-19 20:02:48 +01:00
<programlisting > #SOURCE DEST POLICY LOGLEVEL LIMIT
2009-08-16 19:17:48 +02:00
loc $FW ACCEPT
$FW loc ACCEPT</programlisting>
2005-11-10 19:45:06 +01:00
<para > It is important to note that Shorewall policies (and rules) refer to
<emphasis role= "bold" > connections</emphasis> and not packet flow. With the
policies defined in the <filename
class="directory">/etc/shorewall/policy</filename> file shown above,
connections are allowed from the <emphasis > loc</emphasis> zone to the
<emphasis > net</emphasis> zone even though connections are not allowed from
the <emphasis > loc</emphasis> zone to the firewall itself.</para>
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2004-02-14 19:06:39 +01:00
<para > At this point, edit your <filename > /etc/shorewall/policy</filename>
file and make any changes that you wish.</para>
</section>
2007-06-29 00:06:10 +02:00
<section id= "Interfaces" >
2004-02-14 19:06:39 +01:00
<title > Network Interfaces</title>
2007-06-29 00:06:10 +02:00
<figure id= "Figure2" >
2004-02-14 19:06:39 +01:00
<title > DMZ</title>
<mediaobject >
<imageobject >
2016-02-19 20:02:48 +01:00
<imagedata align= "center" fileref= "images/dmz1.png" format= "PNG" />
2004-02-14 19:06:39 +01:00
</imageobject>
</mediaobject>
</figure>
<para > The firewall has three network interfaces. Where Internet
connectivity is through a cable or DSL <quote > Modem</quote> , the External
2008-08-15 07:03:24 +02:00
Interface will be the Ethernet adapter that is connected to that
2004-02-14 19:06:39 +01:00
<quote > Modem</quote> (e.g., <filename class= "devicefile" > eth0</filename> )
unless you connect via <emphasis > Point-to-Point Protocol</emphasis> over
Ethernet (PPPoE) or <emphasis > Point-to-Point Tunneling Protocol</emphasis>
2004-08-17 00:17:09 +02:00
(PPTP) in which case the External Interface will be a
<literal > ppp</literal> interface (e.g., <filename
class="devicefile">ppp0</filename> ). If you connect via a regular modem,
your External Interface will also be <filename
class="devicefile">ppp0</filename> . If you connect using ISDN, you
external interface will be <filename
class="devicefile">ippp0</filename> .</para>
2004-02-14 19:06:39 +01:00
2007-02-14 17:45:45 +01:00
<caution >
2007-02-14 17:39:35 +01:00
<para > Be sure you know which interface is your external interface. Many
hours have been spent floundering by users who have configured the wrong
2007-02-14 17:49:27 +01:00
interface. If you are unsure, then as root type <command > ip route
ls</command> at the command line. The device listed in the last
(default) route should be your external interface.</para>
2007-02-14 17:39:35 +01:00
<para > Example:</para>
<programlisting > root@lists:~# ip route ls
192.168.1.1 dev eth0 scope link
192.168.2.2 dev tun0 proto kernel scope link src 192.168.2.1
192.168.3.0/24 dev br0 proto kernel scope link src 192.168.3.254
10.13.10.0/24 dev tun1 scope link
192.168.2.0/24 via 192.168.2.2 dev tun0
192.168.1.0/24 dev br0 proto kernel scope link src 192.168.1.254
206.124.146.0/24 dev eth0 proto kernel scope link src 206.124.146.176
10.10.10.0/24 dev tun1 scope link
default via 206.124.146.254 dev <emphasis role= "bold" > eth0</emphasis>
root@lists:~# </programlisting>
<para > In that example, <filename class= "devicefile" > eth0</filename> is
the external interface.</para>
2007-02-14 17:45:45 +01:00
</caution>
2007-02-14 17:39:35 +01:00
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2004-02-14 19:06:39 +01:00
2005-09-08 04:03:51 +02:00
<para > I<emphasis role= "bold" > f your external interface is <filename
2004-08-17 00:17:09 +02:00
class="devicefile">ppp0</filename> or <filename
class="devicefile">ippp0</filename> then you will want to set
<varname > CLAMPMSS=yes</varname> in
2005-09-08 04:03:51 +02:00
<filename > /etc/shorewall/shorewall.conf</filename> .</emphasis> </para>
2004-02-14 19:06:39 +01:00
2008-08-15 07:03:24 +02:00
<para > Your Local Interface will be an Ethernet adapter (<filename
2004-08-17 00:17:09 +02:00
class="devicefile">eth0</filename> , <filename
class="devicefile">eth1</filename> or <filename
class="devicefile">eth2</filename> ) and will be connected to a hub or
switch. Your local computers will be connected to the same switch (note:
If you have only a single local system, you can connect the firewall
directly to the computer using a cross-over cable).</para>
2004-02-14 19:06:39 +01:00
2008-08-15 07:03:24 +02:00
<para > Your DMZ Interface will also be an Ethernet adapter (<filename
2004-08-17 00:17:09 +02:00
class="devicefile">eth0</filename> , <filename
class="devicefile">eth1</filename> or <filename
class="devicefile">eth2</filename> ) and will be connected to a hub or
switch. Your DMZ computers will be connected to the same switch (note: If
you have only a single DMZ system, you can connect the firewall directly
to the computer using a cross-over cable).</para>
2004-02-14 19:06:39 +01:00
<caution >
2006-10-01 17:33:22 +02:00
<para > <emphasis role= "bold" > Do NOT connect multiple interfaces to the
same hub or switch except for testing</emphasis> . You can test using
this kind of configuration if you specify the <emphasis
2005-11-22 22:36:26 +01:00
role="bold">arp_filter</emphasis> option or the <emphasis
role="bold">arp_ignore</emphasis> option in
<filename > /etc/shorewall/interfaces</filename> for all interfaces
connected to the common hub/switch. <emphasis role= "bold" > Using such a
setup with a production firewall is strongly recommended
against</emphasis> .</para>
2004-02-14 19:06:39 +01:00
</caution>
2009-11-22 18:28:45 +01:00
<caution >
<para > <emphasis role= "bold" > Do not configure a default route on your
internal and DMZ interfaces.</emphasis> Your firewall should have
exactly one default route via your ISP's Router.</para>
</caution>
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2004-02-14 19:06:39 +01:00
<para > The Shorewall three-interface sample configuration assumes that the
external interface is <filename class= "devicefile" > eth0</filename> , the
local interface is <filename class= "devicefile" > eth1</filename> and the
DMZ interface is <filename class= "devicefile" > eth2</filename> . If your
configuration is different, you will have to modify the sample
<filename > /etc/shorewall/interfaces</filename> file accordingly. While you
are there, you may wish to review the list of options that are specified
for the interfaces. Some hints:</para>
<tip >
2004-08-17 00:17:09 +02:00
<para > If your external interface is <filename
class="devicefile">ppp0</filename> or <filename
class="devicefile">ippp0</filename> , you can replace the
2004-02-14 19:06:39 +01:00
<quote > detect</quote> in the second column with <quote > -</quote>
(without the quotes).</para>
</tip>
<tip >
2004-08-17 00:17:09 +02:00
<para > If your external interface is <filename
class="devicefile">ppp0</filename> or <filename
class="devicefile">ippp0</filename> or if you have a static IP address,
you can remove <quote > dhcp</quote> from the option list.</para>
2004-02-14 19:06:39 +01:00
</tip>
</section>
2007-06-29 00:06:10 +02:00
<section id= "Addresses" >
2004-02-14 19:06:39 +01:00
<title > IP Addresses</title>
<para > Before going further, we should say a few words about Internet
Protocol (IP) addresses. Normally, your ISP will assign you a single
Public IP address. This address may be assigned via the Dynamic Host
Configuration Protocol (DHCP) or as part of establishing your connection
when you dial in (standard modem) or establish your PPP connection. In
rare cases, your ISP may assign you a static IP address; that means that
2004-08-17 00:17:09 +02:00
you configure your firewall's external interface to use that address
2004-02-14 19:06:39 +01:00
permanently. Regardless of how the address is assigned, it will be shared
by all of your systems when you access the Internet. You will have to
assign your own addresses for your internal network (the local and DMZ
Interfaces on your firewall plus your other computers). RFC 1918 reserves
several Private IP address ranges for this purpose:</para>
<programlisting > 10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255</programlisting>
<para > You will want to assign your local addresses from one sub-network or
subnet and your DMZ addresses from another subnet. For our purposes, we
can consider a subnet to consists of a range of addresses <systemitem
2004-08-17 00:17:09 +02:00
class="ipaddress">x.y.z.0</systemitem> - <systemitem
class="ipaddress">x.y.z.255</systemitem> . Such a subnet will have a Subnet
Mask of <systemitem class= "netmask" > 255.255.255.0</systemitem> . The
address <systemitem class= "ipaddress" > x.y.z.0</systemitem> is reserved as
the Subnet Address and <systemitem class= "netmask" > x.y.z.255</systemitem>
2004-02-14 19:06:39 +01:00
is reserved as the Subnet Broadcast Address. In Shorewall, a subnet is
described using Classless InterDomain Routing (CIDR) notation with
consists of the subnet address followed by <varname > /24</varname> . The
<varname > 24</varname> refers to the number of consecutive <quote > 1</quote>
bits from the left of the subnet mask.</para>
2007-06-29 00:06:10 +02:00
<table id= "Table1" >
2004-02-14 19:06:39 +01:00
<title > Example sub-network</title>
<tgroup cols= "2" >
2016-02-19 20:02:48 +01:00
<colspec align= "left" />
2004-02-14 19:06:39 +01:00
<tbody >
<row >
<entry > Range:</entry>
<entry > <systemitem class= "ipaddress" > 10.10.10.0</systemitem> -
<systemitem class= "ipaddress" > 10.10.10.255</systemitem> </entry>
</row>
<row >
<entry > Subnet Address:</entry>
2004-08-17 00:17:09 +02:00
<entry > <systemitem
class="ipaddress">10.10.10.0</systemitem> </entry>
2004-02-14 19:06:39 +01:00
</row>
<row >
<entry > Broadcast Address:</entry>
2004-08-17 00:17:09 +02:00
<entry > <systemitem
class="ipaddress">10.10.10.255</systemitem> </entry>
2004-02-14 19:06:39 +01:00
</row>
<row >
<entry > CIDR Notation:</entry>
2004-08-17 00:17:09 +02:00
<entry > <systemitem
class="ipaddress">10.10.10.0/24</systemitem> </entry>
2004-02-14 19:06:39 +01:00
</row>
</tbody>
</tgroup>
</table>
<para > It is conventional to assign the internal interface either the first
2004-08-17 00:17:09 +02:00
usable address in the subnet (<systemitem
class="ipaddress">10.10.10.1</systemitem> in the above example) or the
last usable address (<systemitem
2004-02-14 19:06:39 +01:00
class="ipaddress">10.10.10.254</systemitem> ).</para>
<para > One of the purposes of subnetting is to allow all computers in the
subnet to understand which other computers can be communicated with
directly. To communicate with systems outside of the subnetwork, systems
send packets through a gateway (router).</para>
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2004-02-14 19:06:39 +01:00
2004-08-17 00:17:09 +02:00
<para > Your local computers (Local Computers 1 & 2) should be
2004-02-14 19:06:39 +01:00
configured with their default gateway set to the IP address of the
2004-08-17 00:17:09 +02:00
firewall's internal interface and your DMZ computers (DMZ Computers 1
& 2) should be configured with their default gateway set to the IP
address of the firewall's DMZ interface.</para>
2004-02-14 19:06:39 +01:00
<para > The foregoing short discussion barely scratches the surface
regarding subnetting and routing. If you are interested in learning more
about IP addressing and routing, I highly recommend <quote > IP
2004-08-17 00:17:09 +02:00
Fundamentals: What Everyone Needs to Know about Addressing &
Routing</quote> , Thomas A. Maufer, Prentice-Hall, 1999, ISBN
0-13-975483-0.</para>
2004-02-14 19:06:39 +01:00
2008-08-15 07:03:24 +02:00
<para > The remainder of this guide will assume that you have configured
2004-02-14 19:06:39 +01:00
your network as shown here:</para>
2007-06-29 00:06:10 +02:00
<figure id= "Figure3" >
2004-02-14 19:06:39 +01:00
<title > DMZ</title>
<mediaobject >
<imageobject >
2016-02-19 20:02:48 +01:00
<imagedata fileref= "images/dmz2.png" />
2004-02-14 19:06:39 +01:00
</imageobject>
2009-02-18 17:48:34 +01:00
<caption > <para > The default gateway for the DMZ computers would be
<systemitem class= "ipaddress" > 10.10.11.254</systemitem> and the
default gateway for the Local computers would be <systemitem
class="ipaddress">10.10.10.254</systemitem> .</para> <warning >
2004-02-14 19:06:39 +01:00
<para > Your ISP might assign your external interface an RFC 1918
2004-08-17 00:17:09 +02:00
address. If that address is in the <systemitem
class="ipaddress">10.10.10.0/24</systemitem> subnet then you will
need to select a DIFFERENT RFC 1918 subnet for your local network
and if it is in the <systemitem
2004-02-14 19:06:39 +01:00
class="ipaddress">10.10.11.0/24</systemitem> subnet then you will
need to select a different RFC 1918 subnet for your DMZ.</para>
2009-02-18 17:48:34 +01:00
</warning> </caption>
2004-02-14 19:06:39 +01:00
</mediaobject>
</figure>
</section>
2007-06-29 00:06:10 +02:00
<section id= "SNAT" >
2004-02-14 19:06:39 +01:00
<title > IP Masquerading (SNAT)</title>
<para > The addresses reserved by RFC 1918 are sometimes referred to as
2004-08-17 00:17:09 +02:00
non-routable because the Internet backbone routers don't forward packets
which have an RFC-1918 destination address. When one of your local systems
2008-08-15 07:03:24 +02:00
(let's assume local computer 1) sends a connection request to an Internet
2004-08-17 00:17:09 +02:00
host, the firewall must perform Network Address Translation (NAT). The
firewall rewrites the source address in the packet to be the address of
the firewall's external interface; in other words, the firewall makes it
look as if the firewall itself is initiating the connection. This is
necessary so that the destination host will be able to route return
packets back to the firewall (remember that packets whose destination
2009-02-18 17:48:34 +01:00
address is reserved by RFC 1918 can't be routed across the Internet). When
the firewall receives a return packet, it rewrites the destination address
back to 10.10.10.1 and forwards the packet on to local computer 1.</para>
2004-02-14 19:06:39 +01:00
<para > On Linux systems, the above process is often referred to as IP
Masquerading and you will also see the term Source Network Address
Translation (SNAT) used. Shorewall follows the convention used with
2004-08-17 00:17:09 +02:00
Netfilter: <itemizedlist >
<listitem >
<para > <emphasis > Masquerade</emphasis> describes the case where you
let your firewall system automatically detect the external interface
address.</para>
</listitem>
<listitem >
<para > <emphasis > SNAT</emphasis> refers to the case when you
explicitly specify the source address that you want outbound packets
from your local network to use.</para>
</listitem>
</itemizedlist> In Shorewall, both Masquerading and SNAT are configured
with entries in the <filename
class="directory">/etc/shorewall/</filename> <filename > masq</filename>
2004-02-14 19:06:39 +01:00
file.</para>
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2004-02-14 19:06:39 +01:00
2004-08-17 00:17:09 +02:00
<para > If your external firewall interface is <filename
2009-04-30 00:13:22 +02:00
class="devicefile">eth0</filename> then you do not need to modify the file
2004-08-17 00:17:09 +02:00
provided with the sample. Otherwise, edit <filename
class="directory">/etc/shorewall/</filename> <filename > masq</filename> and
change it to match your configuration.</para>
2004-02-14 19:06:39 +01:00
2004-08-17 00:17:09 +02:00
<para > If, in spite of all advice to the contrary, you are using this guide
2009-04-30 00:13:22 +02:00
and want to use one-to-one NAT or Proxy ARP for your DMZ, you will need to
modify the SOURCE column to list just your local interface (10.10.10.0/24
in the above example).</para>
2004-02-14 19:06:39 +01:00
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2004-02-14 19:06:39 +01:00
<para > If your external IP is static, you can enter it in the third column
2004-08-17 00:17:09 +02:00
in the <filename
class="directory">/etc/shorewall/</filename> <filename > masq</filename>
2004-02-14 19:06:39 +01:00
entry if you like although your firewall will work fine if you leave that
column empty. Entering your static IP in column 3 makes processing
2009-12-04 18:06:00 +01:00
outgoing packets a little more efficient.<graphic align= "left"
2016-02-19 20:02:48 +01:00
fileref="images/openlogo-nd-25.png"/></para>
2004-02-14 19:06:39 +01:00
2005-09-08 04:03:51 +02:00
<para > <emphasis role= "bold" > If you are using the Debian package, please
check your <filename > shorewall.conf</filename> file to ensure that the
following is set correctly; if it is not, change it appropriately:
</emphasis> <itemizedlist >
2004-08-17 00:17:09 +02:00
<listitem >
<para > <varname > IP_FORWARDING=On</varname> </para>
</listitem>
</itemizedlist> </para>
2004-02-14 19:06:39 +01:00
</section>
2009-11-22 18:52:13 +01:00
<section id= "Logging" >
<title > Logging</title>
<para > Shorewall does not maintain a log itself but rather relies on your
<ulink url= "shorewall_logging.htm" > system's logging configuration</ulink> .
The following <ulink url= "manpages/shorewall.html" > commands</ulink> rely
on knowing where Netfilter messages are logged:</para>
<itemizedlist >
<listitem >
<para > <command > shorewall show log</command> (Displays the last 20
Netfilter log messages)</para>
</listitem>
<listitem >
<para > <command > shorewall logwatch</command> (Polls the log at a
settable interval</para>
</listitem>
<listitem >
<para > <command > shorewall dump</command> (Produces an extensive report
for inclusion in Shorewall problem reports)</para>
</listitem>
</itemizedlist>
<para > It is important that these commands work properly because when you
encounter connection problems when Shorewall is running, the first thing
that you should do is to look at the Netfilter log; with the help of
<ulink url= "FAQ.htm#faq17" > Shorewall FAQ 17</ulink> , you can usually
resolve the problem quickly.</para>
2009-11-22 19:11:50 +01:00
<para > The Netfilter log location is distribution-dependent:</para>
<itemizedlist >
<listitem >
<para > Debian and its derivatives log Netfilter messages to
2010-01-07 20:40:43 +01:00
<filename > /var/log/kern.log</filename> .</para>
2009-11-22 19:11:50 +01:00
</listitem>
<listitem >
<para > Recent <trademark > SuSE/OpenSuSE</trademark> releases come
preconfigured with syslog-ng and log netfilter messages to
<filename > /var/log/firewall</filename> .</para>
</listitem>
<listitem >
<para > For other distributions, Netfilter messages are most commonly
logged to <filename > /var/log/messages</filename> .</para>
</listitem>
</itemizedlist>
2009-11-22 18:52:13 +01:00
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2009-11-22 18:52:13 +01:00
<para > If you are running a distribution that logs netfilter messages to a
log other than <filename > /var/log/messages</filename> , then modify the
LOGFILE setting in <filename > /etc/shorewall/shorewall.conf</filename> to
specify the name of your log.</para>
<important >
<para > The LOGFILE setting does not control where the Netfilter log is
maintained -- it simply tells the /sbin/<filename > shorewall</filename>
utility where to find the log.</para>
</important>
</section>
2010-01-22 22:12:41 +01:00
<section id= "Modules" >
<title > Kernel Module Loading</title>
<para > Beginning in Shorewall 4.4.7,
<filename > /etc/shorewall/shorewall.conf</filename> contains a
LOAD_HELPERS_ONLY option which is set to <option > Yes</option> in the
samples. This causes Shorewall to attempt to load the modules listed in
<filename > /usr/share/shorewall/helpers</filename> . In addition, it sets
<emphasis role= "bold" > sip_direct_media=0</emphasis> when loading the
nf_conntrack_sip module. That setting is somewhat less secure than
<emphasis role= "bold" > sip_direct_media=1</emphasis> , but it generally
makes VOIP through the firewall work much better.</para>
<para > The modules in <filename > /usr/share/shorewall/helpers</filename> are
those that are not autoloaded. If your kernel does not support module
autoloading and you want Shorewall to attempt to load all netfilter
modules that it might require, then set LOAD_HELPERS_ONLY=No. That will
cause Shorewall to try to load the modules listed in
<filename > /usr/share/shorewall/modules</filename> . That file does not set
<emphasis role= "bold" > sip_direct_media=0</emphasis> .</para>
<para > If you need to modify either
<filename > /usr/share/shorewall/helpers</filename> or
<filename > /usr/share/shorewall/modules</filename> then copy the file to
<filename > /etc/shorewall</filename> and modify the copy.</para>
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2010-01-22 22:12:41 +01:00
<para > Modify the setting of LOAD_HELPER_ONLY as necessary.</para>
</section>
2006-12-03 17:15:14 +01:00
<section id= "DNAT" >
2004-02-14 19:06:39 +01:00
<title > Port Forwarding (DNAT)</title>
<para > One of your goals will be to run one or more servers on your DMZ
computers. Because these computers have RFC-1918 addresses, it is not
possible for clients on the Internet to connect directly to them. It is
rather necessary for those clients to address their connection requests to
your firewall who rewrites the destination address to the address of your
server and forwards the packet to that server. When your server responds,
the firewall automatically performs SNAT to rewrite the source address in
the response.</para>
<para > The above process is called <emphasis > Port Forwarding</emphasis> or
<emphasis > Destination Network Address Translation</emphasis> (DNAT). You
configure port forwarding using DNAT rules in the <filename
class="directory">/etc/shorewall/</filename> <filename > rules</filename>
file.</para>
<para > The general form of a simple port forwarding rule in <filename
class="directory">/etc/shorewall/</filename> <filename > rules</filename> is:
2016-02-19 20:02:48 +01:00
<programlisting > #ACTION SOURCE DEST PROTO DPORT
2004-08-17 00:17:09 +02:00
DNAT net dmz:<emphasis > < server local IP address> </emphasis> [:<emphasis > < server port> </emphasis> ] <emphasis > < protocol> </emphasis> <emphasis > < port> </emphasis> </programlisting>
If you don't specify the <emphasis > <varname > < server
port> </varname> </emphasis> , it is assumed to be the same as
<emphasis > <varname > < port> </varname> </emphasis> .</para>
2004-02-14 19:06:39 +01:00
2006-02-19 00:53:52 +01:00
<important >
<para > Be sure to add your rules after the line that reads <emphasis
2008-08-15 07:03:24 +02:00
role="bold">SECTION NEW.</emphasis> </para>
2006-02-19 00:53:52 +01:00
</important>
2007-06-29 00:06:10 +02:00
<example id= "Example1" >
2004-02-14 19:06:39 +01:00
<title > You run a Web Server on DMZ Computer 2 and you want to forward
incoming TCP port 80 to that system</title>
2016-02-19 20:02:48 +01:00
<para > <programlisting > #ACTION SOURCE DEST PROTO DPORT
2009-03-15 21:46:56 +01:00
Web(DNAT) net dmz:10.10.11.2
Web(ACCEPT) loc dmz:10.10.11.2</programlisting> <itemizedlist >
2004-08-17 00:17:09 +02:00
<listitem >
<para > Entry 1 forwards port 80 from the Internet.</para>
</listitem>
<listitem >
<para > Entry 2 allows connections from the local network.</para>
</listitem>
</itemizedlist> Several important points to keep in mind:<itemizedlist >
<listitem >
<para > When you are connecting to your server from your local
systems, you must use the server's internal IP address
2011-01-07 19:27:35 +01:00
(<systemitem class= "ipaddress" > 10.10.11.2</systemitem> ) or you
must use DNAT from the loc zone as well (see below).</para>
2016-02-19 20:02:48 +01:00
<programlisting > #ACTION SOURCE DEST PROTO DPORT SPORT ORIGDEST
2011-01-07 19:27:35 +01:00
Web(DNAT) loc dmz:10.10.11.2 - - - <replaceable > external-ip-address</replaceable> </programlisting>
<para > where <replaceable > external-ip-address</replaceable> is the
IP address of the firewall's external interface.</para>
2004-08-17 00:17:09 +02:00
</listitem>
<listitem >
<para > Many ISPs block incoming connection requests to port 80. If
you have problems connecting to your web server, try the following
rule and try connecting to port 5000 (e.g., connect to
<literal > http://w.x.y.z:5000 where w.x.y.z</literal> is your
2016-02-19 20:02:48 +01:00
external IP).<programlisting > #ACTION SOURCE DEST PROTO DPORT SPORT ORIGDEST
2011-01-07 19:27:35 +01:00
DNAT net dmz:10.10.11.2:80 tcp 5000</programlisting> </para>
2004-08-17 00:17:09 +02:00
</listitem>
<listitem >
<para > If you want to be able to access your server from the local
network using your external address, then if you have a static
external IP you can replace the loc-> dmz rule above
2016-02-19 20:02:48 +01:00
with:<programlisting > #ACTION SOURCE DEST PROTO DPORT SPORT ORIGDEST
2004-08-17 00:17:09 +02:00
DNAT loc dmz:10.10.11.2 tcp 80 - <emphasis > < external IP> </emphasis> </programlisting> If
you have a dynamic IP then you must ensure that your external
2016-03-26 21:13:15 +01:00
interface is up before starting Shorewall and you must code the
rule as follows (assume that your external interface is <filename
class="devicefile">eth0</filename> ):</para>
<programlisting > #ACTION SOURCE DEST PROTO DPORT SPORT ORIGDEST
DNAT loc dmz:10.10.11.2 tcp 80 - & eth0</programlisting>
<para > '& eth0' expands to the IP address of eth0 (see <ulink
url="configuration_file_basics.htm#AddressVariables">this
article</ulink> ).</para>
2004-08-17 00:17:09 +02:00
</listitem>
<listitem >
<para > If you want to access your server from the DMZ using your
external IP address, see <ulink url= "FAQ.htm#faq2a" > FAQ
2a</ulink> .</para>
</listitem>
</itemizedlist> </para>
2004-02-14 19:06:39 +01:00
</example>
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2004-02-14 19:06:39 +01:00
2004-08-17 00:17:09 +02:00
<para > At this point, add the DNAT and ACCEPT rules for your
servers.</para>
2005-10-03 16:33:37 +02:00
<important >
<para > When testing DNAT rules like those shown above, you must test from
a client OUTSIDE YOUR FIREWALL (in the 'net' zone). You cannot test
these rules from inside the firewall!</para>
<para > For DNAT troubleshooting tips, <ulink url= "FAQ.htm#faq1a" > see FAQs
1a and 1b</ulink> .</para>
</important>
2004-02-14 19:06:39 +01:00
</section>
2007-06-29 00:06:10 +02:00
<section id= "DNS" >
2004-02-14 19:06:39 +01:00
<title > Domain Name Server (DNS)</title>
<para > Normally, when you connect to your ISP, as part of getting an IP
2004-08-17 00:17:09 +02:00
address your firewall's <emphasis > Domain Name Service</emphasis> (DNS)
resolver will be automatically configured (e.g., the
<filename > /etc/resolv.conf</filename> file will be written).
Alternatively, your ISP may have given you the IP address of a pair of DNS
name servers for you to manually configure as your primary and secondary
name servers. It is your responsibility to configure the resolver in your
internal systems. You can take one of two approaches: <itemizedlist >
<listitem >
<para > You can configure your internal systems to use your ISP's name
servers. If your ISP gave you the addresses of their servers or if
those addresses are available on their web site, you can configure
your internal systems to use those addresses. If that information
isn't available, look in <filename > /etc/resolv.conf</filename> on
your firewall system -- the name servers are given in
<quote > nameserver</quote> records in that file.</para>
</listitem>
<listitem >
<para > <inlinegraphic fileref= "images/BD21298_.gif"
2016-02-19 20:02:48 +01:00
format="GIF"/></para>
2004-08-17 00:17:09 +02:00
<para > You can configure a <emphasis > Caching Name Server</emphasis>
on your firewall or in your DMZ. <trademark > Red Hat</trademark> has
an RPM for a caching name server (which also requires the
'<command > bind</command> ' RPM) and for Bering users, there is
<filename > dnscache.lrp</filename> . If you take this approach, you
configure your internal systems to use the caching name server as
their primary (and only) name server. You use the internal IP
address of the firewall (<systemitem
class="ipaddress">10.10.10.254</systemitem> in the example above)
for the name server address if you choose to run the name server on
your firewall. To allow your local systems to talk to your caching
name server, you must open port 53 (both UDP and TCP) from the local
network to the server; you do that by adding the rules in
<filename > /etc/shorewall/rules</filename> .</para>
</listitem>
</itemizedlist> If you run the name server on the firewall:
2016-02-19 20:02:48 +01:00
<programlisting > #ACTION SOURCE DEST PROTO DPORT
2009-03-15 21:46:56 +01:00
DNS(ACCEPT) loc $FW
DNS(ACCEPT) dmz $FW </programlisting> Run name server on DMZ
2016-02-19 20:02:48 +01:00
computer 1: <programlisting > #ACTION SOURCE DEST PROTO DPORT
2009-03-15 21:46:56 +01:00
DNS(ACCEPT) loc dmz:10.10.11.1
DNS(ACCEPT) $FW dmz:10.10.11.1 </programlisting> </para>
2004-02-14 19:06:39 +01:00
2009-03-15 21:46:56 +01:00
<para > In the rules shown above, <quote > DNS</quote> (ACCEPT)is an example of
2005-09-19 21:27:22 +02:00
a <emphasis > defined macro</emphasis> . Shorewall includes a number of
2005-09-21 00:39:45 +02:00
defined macros and <ulink url= "Macros.html" > you can add your own</ulink> .
To see the list of macros included with your version of Shorewall, run the
2014-03-05 17:57:21 +01:00
command <command > shorewall show
<filename > macros</filename> </command> .</para>
2004-02-14 19:06:39 +01:00
2005-09-19 21:27:22 +02:00
<para > You don't have to use defined macros when coding a rule in
2005-09-21 00:39:45 +02:00
<filename > /etc/shorewall/rules</filename> . The first example above (name
server on the firewall) could also have been coded as follows:</para>
2004-02-14 19:06:39 +01:00
2016-02-19 20:02:48 +01:00
<programlisting > #ACTION SOURCE DEST PROTO DPORT
2005-09-12 20:43:26 +02:00
ACCEPT loc $FW tcp 53
ACCEPT loc $FW udp 53
ACCEPT dmz $FW tcp 53
ACCEPT dmz $FW udp 53 </programlisting>
2004-02-14 19:06:39 +01:00
2005-09-19 21:27:22 +02:00
<para > In cases where Shorewall doesn't include a defined macro to meet
your needs, you can either define the macro yourself or you can simply
2005-09-21 00:39:45 +02:00
code the appropriate rules directly. <ulink url= "ports.html" > This
page</ulink> can be of help if you don't know the protocol and port
involved.</para>
2014-03-05 18:24:41 +01:00
<caution >
<para > The Shorewall-provided macros assume that the service is using its
standard port and will not work with a service listening on a
non-standard port.</para>
</caution>
2004-02-14 19:06:39 +01:00
</section>
2006-12-03 17:15:14 +01:00
<section id= "Open" >
2004-02-14 19:06:39 +01:00
<title > Other Connections</title>
<para > The three-interface sample includes the following rule:
2016-02-19 20:02:48 +01:00
<programlisting > #ACTION SOURCE DEST PROTO DPORT
2009-03-15 21:46:56 +01:00
DNS(ACCEPT) $FW net </programlisting> That rule allow DNS access
2005-09-08 04:03:51 +02:00
from your firewall and may be removed if you commented out the line in
2004-02-14 19:06:39 +01:00
<filename > /etc/shorewall/policy</filename> allowing all connections from
the firewall to the Internet.</para>
2016-02-19 20:02:48 +01:00
<para > The sample also includes: <programlisting > #ACTION SOURCE DEST PROTO DPORT
2009-03-15 21:46:56 +01:00
SSH(ACCEPT) loc $FW
SSH(ACCEPT) loc dmz </programlisting> Those rules allow you to run
2004-02-14 19:06:39 +01:00
an SSH server on your firewall and in each of your DMZ systems and to
connect to those servers from your local systems.</para>
<para > If you wish to enable other connections between your systems, the
2016-02-19 20:02:48 +01:00
general format for using a defined macro is: <programlisting > #ACTION SOURCE DEST PROTO DPORT
2009-03-15 21:46:56 +01:00
< <emphasis > macro</emphasis> > (ACCEPT) <emphasis > < source zone> < destination zone> </emphasis> </programlisting> </para>
2004-02-14 19:06:39 +01:00
2009-06-03 00:05:14 +02:00
<para > The general format when not using a defined macro
2016-02-19 20:02:48 +01:00
is:<programlisting > #ACTION SOURCE DEST PROTO DPORT
2004-08-17 00:17:09 +02:00
ACCEPT <emphasis > < source zone> < destination zone> < protocol> < port> </emphasis> </programlisting> </para>
2004-02-14 19:06:39 +01:00
2007-06-29 00:06:10 +02:00
<example id= "Example2" >
2004-02-14 19:06:39 +01:00
<title > You want to run a publicly-available DNS server on your firewall
system</title>
2005-09-08 04:03:51 +02:00
<para > Using defined macros:</para>
2004-02-14 19:06:39 +01:00
2016-02-19 20:02:48 +01:00
<programlisting > #ACTION SOURCE DEST PROTO DPORT
2009-03-15 21:46:56 +01:00
DNS(ACCEPT) net $FW</programlisting>
2004-02-14 19:06:39 +01:00
2005-11-29 22:19:48 +01:00
<para > Not using defined macros:</para>
2004-02-14 19:06:39 +01:00
2016-02-19 20:02:48 +01:00
<programlisting > #ACTION SOURCE DEST PROTO DPORT
2005-09-12 20:43:26 +02:00
ACCEPT net $FW tcp 53
ACCEPT net $FW udp 53 </programlisting>
2004-02-14 19:06:39 +01:00
<para > Those rules would of course be in addition to the rules listed
2004-08-17 00:17:09 +02:00
above under "If you run the name server on your firewall".</para>
2004-02-14 19:06:39 +01:00
</example>
2004-08-17 00:17:09 +02:00
<para > If you don't know what port and protocol a particular application
uses, <ulink url= "ports.htm" > look here</ulink> .</para>
2004-02-14 19:06:39 +01:00
<important >
2004-08-17 00:17:09 +02:00
<para > I don't recommend enabling telnet to/from the Internet because it
uses clear text (even for login!). If you want shell access to your
2016-02-19 20:02:48 +01:00
firewall from the Internet, use SSH: <programlisting > #ACTION SOURCE DEST PROTO DPORT
2009-03-15 21:46:56 +01:00
SSH(ACCEPT) net $FW</programlisting> </para>
2004-02-14 19:06:39 +01:00
</important>
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/leaflogo.gif" format= "GIF" /> Bering
2004-02-14 19:06:39 +01:00
users will want to add the following two rules to be compatible with
2016-02-19 20:02:48 +01:00
Jacques's Shorewall configuration: <programlisting > #ACTION SOURCE DEST PROTO DPORT
2005-09-12 20:43:26 +02:00
ACCEPT loc $FW udp 53
ACCEPT net $FW tcp 80 </programlisting> <itemizedlist >
2004-08-17 00:17:09 +02:00
<listitem >
<para > Entry 1 allows the DNS Cache to be used.</para>
</listitem>
<listitem >
<para > Entry 2 allows the <quote > weblet</quote> to work.</para>
</listitem>
</itemizedlist> <inlinegraphic fileref= "images/BD21298_.gif"
2016-02-19 20:02:48 +01:00
format="GIF"/></para>
2004-02-14 19:06:39 +01:00
<para > Now modify <filename > /etc/shorewall/rules</filename> to add or
remove other connections as required.</para>
</section>
2007-06-29 00:06:10 +02:00
<section id= "Other" >
2004-04-05 23:13:45 +02:00
<title > Some Things to Keep in Mind</title>
<itemizedlist >
<listitem >
<para > <emphasis role= "bold" > You cannot test your firewall from the
inside</emphasis> . Just because you send requests to your firewall
external IP address does not mean that the request will be associated
with the external interface or the <quote > net</quote> zone. Any
traffic that you generate from the local network will be associated
2004-08-17 00:17:09 +02:00
with your local interface and will be treated as loc-> fw
traffic.</para>
2004-04-05 23:13:45 +02:00
</listitem>
<listitem >
<para > <emphasis role= "bold" > IP addresses are properties of systems,
not of interfaces</emphasis> . It is a mistake to believe that your
firewall is able to forward packets just because you can ping the IP
2004-08-17 00:17:09 +02:00
address of all of the firewall's interfaces from the local network.
The only conclusion you can draw from such pinging success is that the
link between the local system and the firewall works and that you
probably have the local system's default gateway set correctly.</para>
2004-04-05 23:13:45 +02:00
</listitem>
<listitem >
<para > <emphasis role= "bold" > All IP addresses configured on firewall
interfaces are in the $FW (fw) zone</emphasis> . If 192.168.1.254 is
the IP address of your internal interface then you can write
<quote > <emphasis role= "bold" > $FW:192.168.1.254</emphasis> </quote> in a
2004-08-17 00:17:09 +02:00
rule but you may not write <quote > <emphasis
role="bold">loc:192.168.1.254</emphasis> </quote> . Similarly, it is
nonsensical to add 192.168.1.254 to the <emphasis
2004-04-05 23:13:45 +02:00
role="bold">loc</emphasis> zone using an entry in
<filename > /etc/shorewall/hosts</filename> .</para>
</listitem>
<listitem >
<para > <emphasis role= "bold" > Reply packets do NOT automatically follow
the reverse path of the one taken by the original request</emphasis> .
All packets are routed according to the routing table of the host at
each step of the way. This issue commonly comes up when people install
a Shorewall firewall parallel to an existing gateway and try to use
DNAT through Shorewall without changing the default gateway of the
system receiving the forwarded requests. Requests come in through the
Shorewall firewall where the destination IP address gets rewritten but
replies go out unmodified through the old gateway.</para>
</listitem>
<listitem >
<para > <emphasis role= "bold" > Shorewall itself has no notion of inside
or outside</emphasis> . These concepts are embodied in how Shorewall is
configured.</para>
</listitem>
</itemizedlist>
</section>
2007-06-29 00:06:10 +02:00
<section id= "Starting" >
2004-02-14 19:06:39 +01:00
<title > Starting and Stopping Your Firewall</title>
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2004-02-14 19:06:39 +01:00
<para > The <ulink url= "Install.htm" > installation procedure</ulink>
2005-09-19 21:27:22 +02:00
configures your system to start Shorewall at system boot but startup is
disabled so that your system won't try to start Shorewall before
configuration is complete. Once you have completed configuration of your
2005-11-29 22:19:48 +01:00
firewall, you can enable Shorewall startup by editing
<filename > /etc/shorewall/shorewall.conf</filename> and setting
2009-12-04 18:14:59 +01:00
STARTUP_ENABLED=Yes.<graphic align= "left"
2016-02-19 20:02:48 +01:00
fileref="images/openlogo-nd-25.png"/><important >
2004-08-17 00:17:09 +02:00
<para > Users of the <filename > .deb</filename> package must edit
<filename > /etc/default/shorewall</filename> and set
<varname > startup=1</varname> .</para>
2009-02-18 17:48:34 +01:00
</important> </para>
<para > While you are editing <filename > shorewall.conf</filename> , it is a
good idea to check the value of the SUBSYSLOCK option. You can find a
description of this option by typing 'man shorewall.conf' at a shell
2009-03-15 21:46:56 +01:00
prompt and searching for SUBSYSLOCK</para>
2009-02-18 17:48:34 +01:00
<para > The firewall is started using the <command > shorewall start</command>
command and stopped using <command > shorewall stop</command> . When the
firewall is stopped, routing is enabled on those hosts that have an entry
2014-03-05 17:57:21 +01:00
in <filename > <ulink
url="manpages/shorewall-stoppedrules.html">/etc/shorewall/stoppedrules</ulink> </filename>
(<ulink
url="manpages/shorewall-routestopped.html"><filename > /etc/shorewall/routestopped</filename> </ulink>
on Shorewall 4.5.7 and earlier). A running firewall may be restarted using
2016-02-19 20:02:48 +01:00
the <command > shorewall reload</command> command. If you want to totally
2014-03-05 17:57:21 +01:00
remove any trace of Shorewall from your Netfilter configuration, use
<command > shorewall clear</command> .</para>
2004-02-14 19:06:39 +01:00
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" format= "GIF" /> </para>
2004-02-14 19:06:39 +01:00
<para > The three-interface sample assumes that you want to enable routing
to/from <filename class= "devicefile" > eth1</filename> (your local network)
and <filename class= "devicefile" > eth2</filename> (DMZ) when Shorewall is
2004-08-17 00:17:09 +02:00
stopped. If these two interfaces don't connect to your local network and
DMZ or if you want to enable a different set of hosts, modify
<filename > /etc/shorewall/routestopped</filename> accordingly. <warning >
<para > If you are connected to your firewall from the Internet, do not
2014-03-05 17:57:21 +01:00
issue a <quote > <command > shorewall stop</command> </quote> command
unless you have either:</para>
<orderedlist >
<listitem >
<para > Used ADMINISABSENTMINDED=Yes in
<filename > /etc/shorewall/shorewall.conf</filename> ; or</para>
</listitem>
<listitem >
<para > added an entry for the <acronym > IP</acronym> address that
you are connected from to <filename
class="directory">/etc/shorewall/</filename> <filename > routestopped</filename> .</para>
</listitem>
</orderedlist>
<para > Also, I don't recommend using <quote > <command > shorewall
2016-02-19 20:02:48 +01:00
reload</command> </quote> ; it is better to create an alternate
2014-03-05 17:57:21 +01:00
configuration and test it using the <quote > <command > shorewall
try</command> </quote> command.</para>
2004-08-17 00:17:09 +02:00
</warning> </para>
2010-05-31 18:40:20 +02:00
<para > The firewall will start after your network interfaces have been
brought up. This leaves a small window between the time that the network
interface are working and when the firewall is controlling connections
through those interfaces. If this is a concern, you can close that window
by installing the <ulink url= "Shorewall-init.html" > Shorewall Init
Package</ulink> .</para>
2004-02-14 19:06:39 +01:00
</section>
2007-06-29 00:06:10 +02:00
<section id= "Trouble" >
2006-01-15 23:47:18 +01:00
<title > If it Doesn't Work</title>
<itemizedlist >
<listitem >
<para > Re-check each of the items flagged with a red arrow
above.</para>
</listitem>
<listitem >
<para > Check your <ulink
url="shorewall_logging.html">log</ulink> .</para>
</listitem>
<listitem >
<para > Check the <ulink url= "troubleshoot.htm" > Troubleshooting
Guide</ulink> .</para>
</listitem>
<listitem >
<para > Check the <ulink url= "FAQ.htm" > FAQ</ulink> .</para>
</listitem>
</itemizedlist>
</section>
2012-07-18 01:48:15 +02:00
<section >
<title > Disabling your existing Firewall</title>
<para > Before starting Shorewall for the first time, it's a good idea to
stop your existing firewall. On older Redhat/CentOS/Fedora:</para>
<programlisting > <command > service iptables stop</command> </programlisting>
<para > On recent Fedora systems that run systemd, the command is:</para>
<programlisting > <command > systemctl stop iptables.service</command> </programlisting>
<para > If you are running SuSE, use Yast or Yast2 to stop
SuSEFirewall.</para>
<para > On other systems that use a classic SysV init system:</para>
<programlisting > <command > /etc/init.d/iptables stop</command> </programlisting>
<para > Once you have Shorewall running to your satisfaction, you should
totally disable your existing firewall. On older
Redhat/CentOS/Fedora:</para>
<programlisting > <command > chkconfig --del iptables</command> </programlisting>
<para > On Debian systems:</para>
<programlisting > <command > update-rc.d iptables disable</command> </programlisting>
<para > On recent Fedora system running systemd:</para>
<programlisting > <command > systemctl disable iptables.service</command> </programlisting>
2016-02-19 20:02:48 +01:00
<para > <inlinegraphic fileref= "images/BD21298_.gif" /> </para>
2012-07-18 01:48:15 +02:00
<para > At this point, disable your existing firewall service.</para>
</section>
2007-06-29 00:06:10 +02:00
<section id= "Reading" >
2004-02-14 19:06:39 +01:00
<title > Additional Recommended Reading</title>
<para > I highly recommend that you review the <ulink
2004-08-17 00:17:09 +02:00
url="configuration_file_basics.htm">Common Configuration File
Features</ulink> page -- it contains helpful tips about Shorewall features
2009-04-21 00:31:07 +02:00
than make administering your firewall easier. Also, <ulink
url="starting_and_stopping_shorewall.htm">Operating Shorewall and
Shorewall Lite</ulink> contains a lot of useful operational hints.</para>
2004-02-14 19:06:39 +01:00
</section>
2009-11-22 18:28:45 +01:00
</article>