2005-02-22 00:18:35 +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">
|
2005-02-22 00:18:35 +01:00
|
|
|
<article>
|
|
|
|
<!--$Id$-->
|
|
|
|
|
|
|
|
<articleinfo>
|
|
|
|
<title>Shorewall and Routing</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>
|
2005-02-22 00:18:35 +01:00
|
|
|
|
|
|
|
<copyright>
|
|
|
|
<year>2005</year>
|
|
|
|
|
2007-02-25 17:16:27 +01:00
|
|
|
<year>2006</year>
|
|
|
|
|
|
|
|
<year>2007</year>
|
|
|
|
|
2005-02-22 00:18:35 +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
|
|
|
|
<quote><ulink url="GnuCopyright.htm">GNU Free Documentation
|
|
|
|
License</ulink></quote>.</para>
|
|
|
|
</legalnotice>
|
|
|
|
</articleinfo>
|
|
|
|
|
2007-06-29 00:06:10 +02:00
|
|
|
<section id="Routing">
|
2005-02-22 00:18:35 +01:00
|
|
|
<title>Routing vs. Firewalling.</title>
|
|
|
|
|
|
|
|
<para>One of the most misunderstood aspects of Shorewall is its
|
2005-07-02 11:28:25 +02:00
|
|
|
relationship with routing. This article attempts to clear some of the fog
|
2005-02-22 00:18:35 +01:00
|
|
|
that surrounds this issue.</para>
|
|
|
|
|
|
|
|
<para>As a general principle:</para>
|
|
|
|
|
|
|
|
<orderedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>Routing determines where packets are to be sent.</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>Once routing determines where the packet is to go, the firewall
|
|
|
|
(Shorewall) determines if the packet is allowed to go there.</para>
|
|
|
|
</listitem>
|
|
|
|
</orderedlist>
|
|
|
|
|
|
|
|
<para>There are ways that Shorewall can affect routing which are described
|
|
|
|
in the following sections.</para>
|
|
|
|
</section>
|
|
|
|
|
2007-06-29 00:06:10 +02:00
|
|
|
<section id="Netfilter">
|
2005-02-22 00:18:35 +01:00
|
|
|
<title>Routing and Netfilter</title>
|
|
|
|
|
|
|
|
<para>The following diagram shows the relationship between routing
|
|
|
|
decisions and Netfilter.</para>
|
|
|
|
|
2007-02-25 17:16:27 +01:00
|
|
|
<graphic align="center" fileref="images/Netfilter.png" />
|
2005-02-22 00:18:35 +01:00
|
|
|
|
2005-03-04 01:16:13 +01:00
|
|
|
<para>The light blue boxes indicate where routing decisions are made. Upon
|
|
|
|
exit from one of these boxes, if the packet is being sent to another
|
|
|
|
system then the interface and the next hop have been uniquely
|
|
|
|
determined.</para>
|
|
|
|
|
|
|
|
<para>The green boxes show where Netfilter processing takes place (as
|
|
|
|
directed by Shorewall). You will notice that there are two different paths
|
|
|
|
through this maze, depending on where the packet originates. We will look
|
|
|
|
at each of these separately.</para>
|
2005-02-22 00:18:35 +01:00
|
|
|
|
2007-06-29 00:06:10 +02:00
|
|
|
<section id="Ingress">
|
2005-02-22 00:18:35 +01:00
|
|
|
<title>Packets Entering the Firewall from Outside</title>
|
|
|
|
|
|
|
|
<para>When a packet arrives from outside, it first undergoes Netfilter
|
|
|
|
PREROUTING processing. In Shorewall terms:</para>
|
|
|
|
|
|
|
|
<orderedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>Packets may be marked using entries in the <ulink
|
|
|
|
url="???">/etc/shorewall/tcrules</ulink> file. Entries in that file
|
|
|
|
containing ":P" in the mark column are applied here as are rules
|
|
|
|
that default to the MARK_IN_FORWARD_CHAIN=No setting in
|
|
|
|
<filename>/etc/shorewall/shorewall.conf</filename>. These marks may
|
|
|
|
be used to specify that the packet should be routed using an
|
|
|
|
<firstterm>alternate routing table</firstterm>; see the <ulink
|
|
|
|
url="Shorewall_Squid_Usage.html">Shorewall Squid
|
|
|
|
documentation</ulink> for examples.</para>
|
2005-03-04 01:16:13 +01:00
|
|
|
|
|
|
|
<caution>
|
|
|
|
<para>Marking packets then using the <emphasis>fwmark</emphasis>
|
|
|
|
selector in your "<emphasis role="bold">ip rule add</emphasis>"
|
|
|
|
commands should NOT be your first choice. In most cases, you can
|
|
|
|
use the <emphasis>from</emphasis> or <emphasis>dev</emphasis>
|
|
|
|
selector instead.</para>
|
|
|
|
</caution>
|
2005-02-22 00:18:35 +01:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>The destination IP address may be rewritten as a consequence
|
|
|
|
of:</para>
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>DNAT[-] rules.</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>REDIRECT[-] rules.</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>Entries in <filename>/etc/shorewall/nat</filename>.</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</listitem>
|
|
|
|
</orderedlist>
|
|
|
|
|
|
|
|
<para>So the only influence that Shorewall has over where these packets
|
|
|
|
go is via NAT or by marking them so that they may be routed using an
|
|
|
|
alternate routing table.</para>
|
|
|
|
</section>
|
|
|
|
|
2007-06-29 00:06:10 +02:00
|
|
|
<section id="Local">
|
2005-02-22 00:18:35 +01:00
|
|
|
<title>Packets Originating on the Firewall</title>
|
|
|
|
|
|
|
|
<para>Processing of packets that originate on the firewall itself are
|
|
|
|
initially routed using the default routing table then passed through the
|
|
|
|
OUTPUT chains. Shorewall can influence what happens here:</para>
|
|
|
|
|
|
|
|
<orderedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>Packets may be marked using entries in the <ulink
|
|
|
|
url="???">/etc/shorewall/tcrules</ulink> file (rules with "$FW" in
|
|
|
|
the SOURCE column). These marks may be used to specify that the
|
|
|
|
packet should be re-routed using an alternate routing table.</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>The destination IP address may be rewritten as a consequence
|
|
|
|
of:</para>
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>DNAT[-] rules that specify $FW as the SOURCE.</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>Entries in <filename>/etc/shorewall/nat</filename> that
|
|
|
|
have "Yes" in LOCAL column.</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</listitem>
|
|
|
|
</orderedlist>
|
|
|
|
|
|
|
|
<para>So again in this case, the only influence that Shorewall has over
|
|
|
|
the packet destination is NAT or marking.</para>
|
|
|
|
</section>
|
|
|
|
</section>
|
|
|
|
|
2007-06-29 00:06:10 +02:00
|
|
|
<section id="RoutingTables">
|
2005-02-22 00:18:35 +01:00
|
|
|
<title>Alternate Routing Table Configuration</title>
|
|
|
|
|
2005-12-15 20:39:13 +01:00
|
|
|
<para>The Shorewall 2.x <ulink
|
|
|
|
url="http://www.shorewall.net/2.0/Shorewall_Squid_Usage.html#Local">Shorewall
|
|
|
|
Squid documentation</ulink> shows how alternate routing tables can be
|
|
|
|
created and used. That documentation shows how you can use logic in
|
2005-02-22 00:18:35 +01:00
|
|
|
<filename>/etc/shorewall/init</filename> to create and populate an
|
|
|
|
alternate table and to add a routing rule for its use. It is fine to use
|
|
|
|
that technique so long as you understand that you are basically just using
|
|
|
|
the Shorewall init script (<filename>/etc/init.d/shorewall</filename>) to
|
|
|
|
configure your alternate routing table at boot time and that <emphasis
|
|
|
|
role="bold">other than as described in the previous section, there is no
|
2005-05-16 01:49:41 +02:00
|
|
|
connection between Shorewall and routing when using Shorewall versions
|
2005-05-20 16:04:11 +02:00
|
|
|
prior to 2.3.2.</emphasis></para>
|
2005-02-22 00:18:35 +01:00
|
|
|
</section>
|
2005-04-10 20:57:39 +02:00
|
|
|
|
2007-06-29 00:06:10 +02:00
|
|
|
<section id="ProxyArp">
|
2005-04-10 20:57:39 +02:00
|
|
|
<title>Routing and Proxy ARP</title>
|
|
|
|
|
2005-05-22 03:28:41 +02:00
|
|
|
<para>There is one instance where Shorewall creates main routing table
|
|
|
|
entries. When an entry in <filename>/etc/shorewall/proxyarp</filename>
|
|
|
|
contains "No" in the HAVEROUTE column then Shorewall will create a host
|
|
|
|
route to the IP address listed in the ADDRESS column through the interface
|
|
|
|
named in the INTERFACE column. <emphasis role="bold">This is the only case
|
|
|
|
where Shorewall directly manipulates the main routing
|
|
|
|
table</emphasis>.</para>
|
2005-04-10 20:57:39 +02:00
|
|
|
|
|
|
|
<para>Example:</para>
|
|
|
|
|
|
|
|
<para><filename>/etc/shorewall/proxyarp</filename>:</para>
|
|
|
|
|
|
|
|
<programlisting>#ADDRESS INTERFACE EXTERNAL HAVEROUTE PERSISTENT
|
|
|
|
206.124.146.177 eth1 eth0 No
|
|
|
|
#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE</programlisting>
|
|
|
|
|
|
|
|
<para>The above entry will cause Shorewall to execute the following
|
|
|
|
command:</para>
|
|
|
|
|
|
|
|
<programlisting><emphasis role="bold">ip route add 206.124.146.177 dev eth1</emphasis></programlisting>
|
|
|
|
</section>
|
2005-05-16 01:49:41 +02:00
|
|
|
|
2007-06-29 00:06:10 +02:00
|
|
|
<section id="MultiISP">
|
2005-07-27 02:12:11 +02:00
|
|
|
<title>Multiple Internet Connection Support in Shorewall 2.4.2 and
|
2005-05-18 23:12:46 +02:00
|
|
|
Later</title>
|
|
|
|
|
2005-05-20 16:04:11 +02:00
|
|
|
<para>Beginning with Shorewall 2.3.2, support is included for multiple
|
2005-07-27 02:12:11 +02:00
|
|
|
internet connections. If you wish to use this feature, we recommend
|
2005-11-16 23:11:52 +01:00
|
|
|
strongly that you upgrade to version 2.4.2 or later.</para>
|
2005-05-18 23:12:46 +02:00
|
|
|
|
2005-11-16 23:11:52 +01:00
|
|
|
<para>Shorewall multi-ISP support is now covered in a <ulink
|
2005-12-15 20:39:13 +01:00
|
|
|
url="MultiISP.html">separate article</ulink>.</para>
|
2005-05-18 23:12:46 +02:00
|
|
|
</section>
|
2008-07-07 22:42:54 +02:00
|
|
|
</article>
|