<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V3.1//EN">

<Book id="ipmasq-toc">

<!-- Search for Blah for markers : verify that all the SGML escaping works -->

<BookInfo>
 <Title>Linux IP Masquerade HOWTO</Title>
 <AUTHOR>
  <FirstName>David</Firstname> 
  <othername role="mi">A.</othername>
  <surname>Ranch</surname>
  <affiliation> 
    <address><email>dranch@trinnet.net</email></address>
  </affiliation> 
 </AUTHOR>

<pubdate>
November 13, 2005
</pubdate>
<Abstract>
 <para>
November 13, 2005
 </para>

<para>
This document describes how to enable the Linux IP Masquerade feature on a 
given Linux host.  IP Masquerade is a form of Network Address Translation or 
NAT which NAT allows internally connected computers that do not have one or more 
registered Internet IP addresses to communicate to the Internet via the Linux 
server's Internet IP address. 
</para>

</Abstract>

</BookInfo>

<Chapter id="ipmasq-intro1.0">
<Title>Introduction</Title>

<Sect1 id="ipmasq-intro1.1">
<Title>Introduction to IP Masquerading or IP MASQ</Title>

<para>
This document describes how to enable the Linux IP Masquerade feature on a 
given Linux host.  IP Masquerade, called "IPMASQ" or "MASQ" for short, is a form 
of Network Address Translation (NAT) which allows internally connected computers 
that do not have one or more registered Internet IP addresses to communicate to 
the Internet via the Linux server's Internet IP address.  Since IPMASQ is a 
generic technology, you can connect the Linux server's internal and external 
to other computers through LAN technologies like Ethernet, TokenRing, and FDDI, 
as well as dialup connections line PPP or SLIP links. This document primarily 
uses Ethernet and PPP connections in examples because it is most commonly used 
with DSL /  Cablemodems and dialup connections.
</para>

<para>
<quote>
<Emphasis role="strong">
This document is intended for systems running stable Linux kernels like 2.4.x,
2.2.x, and 2.0.x preferably on an IBM-compatible PC. IP Masquerade
does work on other Linux-supported platforms like Sparc, Alpha, PowerPC, etc. 
but this HOWTO doesn't cover them in as much detail.  Beta kernels 
such as 2.5.x, 2.3.x, 2.1.x, and ANY kernels less than 2.0.x are NOT covered 
in this document.  The primary reason for this is because many of the older
kernels are considered broken.  If you are using an older kernel version, it 
is highly advisable to upgrade to one of the stable Linux kernels before using 
IP Masquerading.  
</Emphasis>
</quote>
</para>

</Sect1>


<Sect1 id="ipmasq-intro1.2">
<Title>Foreword, Feedback &amp; Credits</Title>

<para>
<emphasis>
From the original IPMASQ HOWTO author:
</emphasis>
</para>

<para>
<quote>
As a new user, I found it very confusing to setup IP masquerade on the Linux 
kernel, (back then, its was a 1.2.x kernel).  Although there was a FAQ and a 
mailing list, there was no documentation dedicated to this.  There was also 
some requests on the mailing list for a HOWTO manual.  So, I decided to write 
this HOWTO as a starting point for new users and possibly create a building 
block for other knowledgeable users.  If you, the reader, have any additional 
ideas, corrections, or questions about this document, please feel free to 
contact us. 
</quote>
</para>

<para>
This document was originally written by <ULink
URL="mailto:ambrose@writeme.com">Ambrose Au</Ulink> back in August, 1996, 
based on the 1.x kernel IPMASQ FAQ written by Ken Eves and numerous helpful     
messages from the original IP Masquerade mailing list.  In particular, a 
mailing list message from Matthew Driver inspired Ambrose to set up IP 
Masquerade and eventually write version 0.80 of this HOWTO.  In April 1997, 
Ambrose created the Linux IP Masquerade Resource Web site at 
<Ulink URL="http://ipmasq.webhop.net">http://ipmasq.webhop.net</Ulink> which has 
provided up-to-date information on Linux IP Masquerading ever since.  In 
February 1999, <ULink URL="dranch@trinnet.net">David Ranch</ULink> took over 
maintenance of the HOWTO.  David then re-wrote the HOWTO and added a 
substantial number of sections to the document.  Today, the HOWTO is still
maintained by David where he constantly updates it and fixes any reported bugs,
etc. 
</para>

<para>
Please feel free to send any feedback or comments regarding this HOWTO to 
<ULink URL="mailto:dranch@trinnet.net">dranch@trinnet.net</ULink> if you have 
any corrections or if any information/URLs/etc. is missing. Your invaluable 
feedback will certainly influence the future of this HOWTO!   
</para>

<para>
<Emphasis>
This HOWTO is meant to be a fairly comprehensive guide to getting your Linux 
IP Masquerading system working in the shortest time possible.  David only 
plays a technical writer on T.V. so you might find the information in this 
document not as general and/or objective as it could be.  If you think a 
section could be clearer, etc.. please let David know.  The latest version of 
the MASQ HOWTO can be found at 
<ULink URL="http://www.ecst.csuchico.edu/~dranch/LINUX/index-linux.html#ipmasq">
Dranch's Linux Page</Ulink>.  Additional news, mirrors of the HOWTO, and 
information regarding IPMASQ can be found at the 
<ULink URL="http://ipmasq.webhop.net/">IP Masquerade Resource</ULink> web page.  
If you have any technical questions on IP Masquerade, please join the 
<ULink URL="http://home.indyramp.net/mailman/listinfo/masq">IP Masquerade Mailing List</ULink>
instead of sending email to David or Ambrose.  Most MASQ problems are -common- 
for ALL MASQ users and can be easily solved by users on the list.  In addition 
to this, the response time of the IP MASQ email list will be much faster than 
a reply from either David or Ambrose.  
</Emphasis>
</para>

<para>
The latest version of this document can be found at the following sites which 
also contains HTML, Postscript, PDF, etc. versions
</para>

<ItemizedList>
<listitem>
<para>
<ULink URL="http://www.ecst.csuchico.edu/~dranch/LINUX/index-linux.html#ipmasq">
Dranch's Linux page</ULink>
</para>
</listitem>

<listitem>
<para>
<ULink URL="http://ipmasq.webhop.net/">http://ipmasq.webhop.net/: The IP 
Masquerade Resources</ULink>
</para>
</listitem>

<listitem>
<para>
<ULink URL="http://ipmasq2.webhop.net/">http://ipmasq2.webhop.net/: The IP 
Masquerade Resources MIRROR</ULink>
</para>
</listitem>

<listitem>
<para>
<ULink URL="http://www.tldp.org">The Linux Documentation Project</ULink>
</para>
</listitem>


<listitem>
<para>
Also refer to <ULink URL="http://ipmasq.webhop.net/index.html#mirror">IP 
Masquerade Resource Mirror Sites Listing
</ULink> for other local mirrored sites.
</para>
</listitem>

</ItemizedList>

</Sect1>

<Sect1 id="ipmasq-intro1.3">
<Title>Copyright &amp; Disclaimer</Title>

<para>
This document is <Literal remap="tt">copyrighted(c) 2003,2002,2001,2000 for 
David A. Ranch </Literal> and it is a FREE document. You may redistribute it 
under the terms of the GNU General Public License (GPL). 
</para>

<para>
The information herein this document is, to the best of David's knowledge, 
correct.  However, the Linux IP Masquerade feature is written by humans and 
thus, the chance of mistakes, bugs, etc. might occur from time to time.
</para>

<para>
No person, group, or other body is responsible for any damage on your 
computer(s) and any other losses by using the information on this document. 
i.e. 
</para>

<para>
<quote><Emphasis>THE AUTHORS AND ALL MAINTAINERS ARE NOT RESPONSIBLE FOR ANY 
DAMAGES INCURRED DUE TO ACTIONS TAKEN BASED ON THE INFORMATION IN THIS 
DOCUMENT.</Emphasis> 
</quote>
</para>

<para>
Ok, with all this behind us... On with the show..
</para>

</Sect1>

</Chapter>

<Chapter id="ipmasq-background2.0">
<Title>Background Knowledge</Title>

<Sect1 id="ipmasq-background2.1">
<Title>What is IP Masquerade?</Title>

<para>
IP Masquerade is a networking function in Linux similar to the one-to-many 
(1:Many) NAT (Network Address Translation) servers found in many commercial 
firewalls and network routers.  For example, if a Linux host is connected to 
the Internet via PPP, Ethernet, etc., the IP Masquerade feature allows other 
"internal" computers connected to this Linux box (via PPP, Ethernet, etc.) to 
also reach the Internet as well.  Linux IP Masquerading allows for this 
functionality even though these internal machines don't have 
<Emphasis role="strong">an officially assigned IP address</Emphasis>. 
</para>

<para>
MASQ allows a set of machines to <Emphasis role="strong">invisibly</Emphasis> 
access the Internet via the MASQ gateway.  To other machines on the Internet, 
the outgoing traffic will appear to be from the IP MASQ Linux server itself.  
In addition to the added functionality, IP Masquerade provides the foundation 
to create a HEAVILY secured networking environment.  With a well built firewall, 
breaking the security of a well configured masquerading system and internal 
LAN should be considerably difficult to accomplish. 
</para>

<para>
If you would like to know more on how MASQ (1:Many) differs from 1:1 (true) NAT 
and Proxy solutions, please see the <XRef LinkEnd="what-is-masq"> FAQ entry.
</para>

</Sect1>

<Sect1 id="ipmasq-background2.2">
<Title>Current Status</Title>

<para>
IP Masquerade has been in the Linux kernels for several years now and is quite 
mature as the kernel enters the 2.4.x stage.  Kernels since Linux 1.3.x have 
had MASQ support built-in.  Today, many individuals and commercial businesses 
are using it with excellent results.  
</para>

<para>
2.4.x kernel users:
<ItemizedList>
  <listitem>
  <para>
  The 2.4.x kernel hosts an entirely re-written set of NAT code which is 
  both far superior, faster, and more secure than any previous versions
  written for Linux.  Unfortunately, several kernel modules that were
  written for the 2.2.x kernel to support things like UDP-based RealAudio,
  etc. have not been ported to 2.4.x yet.  Because of this, some people 
  should consider NOT upgrading if these network applications are critical 
  to them.  But, at the same time, some of these programs have been updated
  and now use different, NAT-friendly protocols.  Thus special NAT treatment 
  is no longer required.  As always, please see the 
  <ULink URL="http://ipmasq.webhop.net/">http://ipmasq.webhop.net/: The IP 
  Masquerade Resources</ULink> site for updated news, etc.
  </para>
  </listitem>
</itemizedlist>
</para>


<para>
Common network functionalities like Web browsing, telnet, ssh, ping, 
traceroute, etc. work well over stock IP Masquerade setups.  Other network 
applications such as ftp, irc, and Real Audio work well with the appropriate 
additional IP MASQ modules loaded into the kernel as modules.  Other 
network-specific programs like streaming audio (MP3s, True Speech, etc) should
work too without any special module.  Some users on the mailing list also had 
good results with video conferencing software.   
</para>

<para>
It should be noted that running IP Masquerade with only ONE network card (NIC) 
to MASQ between internal and external Ethernet networks is NOT recommended.  
For more details, please see <XRef LinkEnd="aliasing"> FAQ section.
</para>

<para>
Anyways, please refer to <XRef LinkEnd="Supported-Client-Software"> for a more 
complete listing of software supported by IP Maquerade all kernel versions. 
</para>

<para>
IP Masquerade works well as a server to other 'client machines' running 
various operating systems and hardware platforms. Here is a sampling of successful 
reports with internal MASQed systems running :
</para>

<para>

<ItemizedList>

<listitem>
<para>
UNIX:  Sun Solaris, [Net,Free,Open,*i]-BSD, Hp-UX, Linux, IBM AIX, Digital UNIX, Ultrix, etc.
</para>
</listitem>

<listitem>
<para>
Microsoft Windows 2000, NT (3.x and 4.x), 95/98/ME, Windows for Workgroups 
(with the TCP/IP package) 
</para>
</listitem>

<listitem>
<para>
IBM OS/2
</para>
</listitem>

<listitem>
<para>
Apple Macintosh MacOS machines running either MacTCP or Open Transport
</para>
</listitem>

<listitem>
<para>
DOS-based systems with packet drivers and the NCSA Telnet package
</para>
</listitem>

<listitem>
<para>
VAXen
</para>
</listitem>

<listitem>
<para>
Compaq/Digital Alpha running Linux and NT
</para>
</listitem>

<listitem>
<para>
Amiga computers with AmiTCP or AS225-stack.   
</para>
</listitem>

</ItemizedList>

</para>

<para>
The list goes on and on but the point is, if your OS platform talks TCP/IP, 
it should work with Linux's IP Masquerade!
</para>

</Sect1>

<Sect1 id="ipmasq-background2.3">
<Title>Who Can Benefit From IP Masquerade?</Title>

<para>

<ItemizedList>
<listitem>

<para>
If you have a Linux host connected to the Internet and.. 
</para>
</listitem>

<listitem>
<para>
if you have internal computers running TCP/IP connected that are connected to
this Linux box via on a network, and/or 
</para>
</listitem>

<listitem>
<para>
if your Linux host has more than one modem and acts as a PPP or SLIP server 
connected to <Emphasis >other</Emphasis> computers, and these machines do not 
have official or public assigned IP addresses (i.e. addressed with private 
TCP/IP numbers). 
</para>
</listitem>

<listitem>
<para>
If you want those <Emphasis >OTHER</Emphasis> machines to communicate to 
the Internet without spending extra money to acquire additional Public / 
Official TCP/IP addresses from your ISP, then you should either configure 
Linux to be a router or purchase an external router. 
</para>
</listitem>

</ItemizedList>

</para>

</Sect1>

<Sect1 id="ipmasq-background2.4">
<Title>Who Doesn't Need IP Masquerade?</Title>

<para>

<ItemizedList>
<listitem>

<para>
If your machine is a stand-alone Linux host connected to the Internet (setting 
up a firewall is a good idea though), or
</para>
</listitem>

<listitem>
<para>
if you already have multiple assigned public addresses for your <Emphasis>
OTHER</Emphasis> machines, and
</para>
</listitem>

<listitem>
<para>
if you don't like the idea of a 'free ride' using Linux and feel more 
comfortable using expensive commercial tools to perform the exact same 
functionalities. 
</para>
</listitem>

</ItemizedList>

</para>

</Sect1>

<Sect1 id="ipmasq-background2.5">
<Title>How does IP Masquerade Work?</Title>


<para>
Based from the original IP Masquerade FAQ by Ken Eves:
  Here is a drawing of the most simplistic setup:
</para>

<screen>
PPP/ETH/etc.        +------------+                         +-------------+
to ISP provider     |  Linux #1  |       PPP/ETH/etc.      | Anybox      |
                    |            |                         |             |
  <---------- modem1|            |modem2 ----------- modem3|             |
                    |            |                         |             |
    111.222.121.212 |            |           192.168.0.100 |             |
                    +------------+                         +-------------+
</screen>

<para>   
In the above drawing, a Linux box with IP_MASQUERADING is installed as Linux 
#1 and is connected to the Internet via PPP, Ethernet, etc.  It has an 
assigned public IP address of 111.222.121.212.  It also has another network
interface (e.g. modem2) connected to allow incoming network traffic be it
from a PPP connection, Ethernet connection, etc.
</para>

<para>
The second system (which does not need to be Linux) connects into the 
Linux #1 box and starts its network traffic to the Internet.  This second 
machine does NOT have a publicly assigned IP address from the Internet, so it 
uses an 
<ULink URL="http://www.ietf.org/rfc/rfc1918.txt?number=1918">
RFC1918 private address</ULink>, say 192.168.0.100. (see below for more info)
</para>

<para>
 With IP Masquerade and the routing configured properly, this second machine 
"Anybox" can interact with the Internet as if it was directly connected to 
the Internet with a few small exceptions [noted later].
</para>

<para>
Quoting Pauline Middelink (the founder of Linux's IPMASQ):
</para>

<para>
"Do not forget to mention that the "ANYBOX" machine should have the Linux #1 
box configured as its default gateway (whether it be the default route or 
just a subnet is no matter). If the "ANYBOX" machine is connected via a PPP
or SLIP connection, the Linux #1 machine should be configured to support 
proxy arp for all routed addresses. But, the setup and configuration of 
proxy arp is beyond the scope of this document.  Please see the <ULink
URL="http://www.tldp.org/HOWTO/PPP-HOWTO/index.html">PPP-HOWTO</ULink> 
for more details."
</para>

<para>
The following is an excerpt on how IPMASQ briefly works though this will be
explained in more detail later.  This short text is based from a previous post 
on comp.os.linux.networking which has been edited to match the names used in 
the above example:
</para>

<screen>
   o I tell machine ANYBOX that my PPP or Ethernet connected Linux box is its 
     gateway.

   o When a packet comes into the Linux box from ANYBOX, it will assign the 
     packet to a new TCP/IP source port number and insert its own IP address 
     inside the packet header, saving the originals.  The MASQ server will 
     then send the modified packet over the PPP/ETH interface onto the 
     Internet.

   o When a packet returns from the Internet into the Linux box, Linux 
     examines if the port number is one of those ports that was assigned 
     above.  If so, the MASQ server will then take the original port and 
     IP address, put them back in the returned packet header, and send 
     the packet to ANYBOX.

   o The host that sent the packet will never know the difference. 
</screen>

<para>
<Emphasis >Another IP Masquerading Example:</Emphasis>
</para>

<para>
A typical example is given in the diagram below:
</para>

<screen>
                  Ethernet
                 192.168.0.x
    +----------+
    |          |  
    | A-box    |::::::
    |          |.2   : 
    +----------+     :
                     :      +----------+   PPP/ETH   
    +----------+     :   .1 |  Linux   |     link
    |          |     :::::::| Masq-Gate|:::::::::::::::::::>> Internet
    | B-box    |::::::      |          |  111.222.121.212
    |          |.3   :      +----------+
    +----------+     :
                     :
    +----------+     :
    |          |     :
    | C-box    |::::::
    |          |.4    
    +----------+  

                
    |                       |          |                           >
    | <-Internal Network--> |          | <- External Network ----> >
    |   connected via an    |          |    Connected from the     >
    |   Ethernet hub or     |          |    Linux server to your   > 
    |       switch          |          |    Internet connection    >
</screen>

<para>
In this example, there are (4) computer systems that we are concerned about.   
There is also presumably something on the far right that your PPP/ETH 
connection to the Internet comes through (modem server, DSL DSLAM, Cablemodem
router, etc.).   Out on the Internet, there exists some remote host (very far 
off to the right of the page) that you are interested in communicating with).  
The Linux system named <Emphasis><Literal>Masq-Gate</Literal></Emphasis> is 
the IP Masquerading gateway for ALL internal networked machines.  In this 
example, the machines <Emphasis><Literal>A-box</Literal></Emphasis>, <Emphasis>
<Literal>B-box</Literal></Emphasis>, and <Emphasis><Literal>C-box</Literal>
</Emphasis> would have to go through the Masq-Gate to reach the Internet.  The 
internal network uses one of several 
<ULink URL="http://www.cis.ohio-state.edu/cgi-bin/rfc/rfc1918.html">
RFC-1918 assigned private network addresses</ULink>, where in this case, would 
be the Class-C network 192.168.0.0.  If you aren't familiar with RFC1918, it
is encouraged to read the first few chapters of the RFC but the jist of it is
that the TCP/IP addresses 10.0.0.0/8, 172.16-31.0.0/12, and 192.168.0.0/16 
are reserved.  When we say "reserved", we mean that anyone can use these
addresses as long as they aren't routed over the Internet.  ISPs are even
allowed to use this private addressing space as long as they keep these
addresses within their own networks and NOT advertise them to other ISPs.
Unfortunately, this isn't always the case but thats beyond the scope of
this HOWTO.
</para>

<para>
Anyway, the Linux box in the diagram above has the TCP/IP address 192.168.0.1 
while the other systems has the addresses:
</para>

<para>

<ItemizedList>
<listitem>

<para>
A-Box: 192.168.0.2
</para>
</listitem>

<listitem>
<para>
B-Box: 192.168.0.3
</para>
</listitem>

<listitem>
<para>
C-Box: 192.168.0.4
</para>
</listitem>

</ItemizedList>

</para>

<para>
The three machines, <Literal>A-box</Literal>, <Literal>B-box</Literal> and 
<Literal>C-box</Literal>, can have any one of several operating systems, just 
as long as they can speak TCP/IP.  Some such as <Emphasis >Windows 
95</Emphasis>, <Emphasis >Macintosh MacTCP or OpenTransport </Emphasis>, or 
even another <Emphasis >Linux box</Emphasis> have the ability to connect to 
other machines on the Internet.  When running the IP Masquerade, the 
masquerading system or <Literal>MASQ-gate</Literal> converts all of these 
internal connections so that they appear to originate from the 
<Literal>masq-gate</Literal> itself.  MASQ then arranges so that the data 
coming back to a masqueraded connection is relayed to the proper originating 
system.   Therefore, the systems on the internal network are only able to see 
a direct route to the internet and are unaware that their data is being 
masqueraded.  This is called a "Transparent" connection.
</para>

<para>
NOTE:  Please see <XRef LinkEnd="FAQ"> for more details on topics such as:
</para>

<para>

<ItemizedList>
<listitem>

<para>
The differences between NAT, MASQ, and Proxy servers.
</para>
</listitem>

<listitem>
<para>
How packet firewalls work
</para>
</listitem>

</ItemizedList>

</para>

</Sect1>


<Sect1 id="kernel-2.4.x-Requirements">
<Title>Requirements for IP Masquerade on Linux 2.4.x</Title>

<para>
<quote> <Emphasis >** Please refer to <ULink URL="http://ipmasq.webhop.net/">IP 
Masquerade Resource</ULink> for the latest information. **</Emphasis> 
</quote> 
</para>

<ItemizedList>
<listitem>
<para>
The newest 2.4.x kernels are now using both a completely new TCP/IP network
stack as well as a new NAT sub-system called NetFilter.  Within this NetFilter
suite of tools, we now have a tool called IPTABLES for the 2.4.x kernels much 
like there was IPCHAINS for the 2.2.x kernels and IPFWADM for the 2.0.x kernels.
The new IPTABLES system is far more powerful (combines several functions into 
one place like true NAT functionality), offers better security (stateful 
inspection), and better performance with the new 2.4.x TCP/IP stack.  But this 
new suite of tools can be a bit complicated in comparison to older generation 
kernels.  Hopefully, if you follow along with this HOWTO carefully, setting up
IPMASQ won't be too bad.  If you find anything unclear, downright wrong, etc. 
please email David about it.
</para>

<para>
<Emphasis role="strong">Unlike</Emphasis> the migration to IPCHAINS from 
IPFWADM, the new NetFilter tool has kernel modules that can actually 
support older IPCHAINS and IPFWADM rulesets with minimal changes.  So 
re-writing your old MASQ or firewall ruleset scripts is not longer required.  
<Emphasis role="strong">BUT..</Emphasis> with the 2.4.x kernels, you cannot
use the old 2.2.x MASQ modules like ip_masq_ftp, ip_masq_irc, etc. 
<Emphasis role="strong">AND</Emphasis> IPCHAINS is incompatible with the 
new IPTABLES modules like ip_conntrack_ftp, etc.  So, what does this mean?
It basically means that if you want to use IPMASQ or PORTFW functionality under 
a 2.4.x kernel, you shouldn't use IPCHAINS rules but IPTABLES ones instead.  
Please also keep in mind that there might be several benefits in performing a 
full ruleset re-write to take advantage of the newer IPTABLES features like 
stateful tracking, etc. but that is dependant upon how much time you have to 
migrate your old rulesets.  Please see <XRef LinkEnd="ipchains-on-2.4.x"> for
additional details.
</para>
</listitem>
</ItemizedList>

<para>
Some new 2.4.x functionalities include the following:
</para>

<para>
<Emphasis role="strong">PROs:</Emphasis>

<ItemizedList>
 <listitem>
  <para>
   Lots of new protocols modules like: amanda, eggdrop, ipsec, ipv6, portscan,
   pptp, quota, rsh, talk, and tftp 
  </para>
 </listitem>

 <listitem>
  <para>
   TRUE 1:1 NAT functionality for those who have TCP/IP addresses and subnets 
   to use (no more iproute2 commands)
</para>
</listitem>

<listitem>
<para>
Stateful application level (FTP, IRC, etc.) and stateful protocol level 
(TCP/UDP/ICMP) network traffic inspection 
</para>
</listitem>


<listitem>
<para>
Built-in PORT Forwarding (no more ipmasqadm or ipportfw commands)
</para>
</listitem>

<listitem>
<para>
The built-in PORTFW'ing support works for both external and internal 
traffic.  This means that users that have PORTFW for external traffic and 
REDIR for internal port redirection do not need to use two tools any more!
</para>
</listitem>

<listitem>
<para>
PORT Forwarding of FTP traffic to internal hosts is now completely supported
and is handled in the conn_trak_ftp module
</para>
</listitem>

<listitem>
<para>
Full Policy-Based routing features (source-based TCP/IP address routing)
</para>
</listitem>

<listitem>
<para>
Compatibility with Linux's FastRoute feature for significantly faster packet 
forwarding (a.k.a Linux network switching).</para>
<para>Note that this feature is still not compatible with packet filtering 
for strong firewall rulesets.
</para>
</listitem>

<listitem>
<para>
Fully supports TCP/IP v4, v6, and even DECnet (ack!)
</para>
</listitem>

<listitem>
<para>
Supports wildcard interface names like "ppp*" for serial interfaces like 
ppp0, ppp1, etc
</para>
</listitem>

<listitem>
<para>
Supports filtering on both input and output INTERFACES (not just IP addresses)
</para>
</listitem>

<listitem>
<para>
Source Ethernet MAC filtering
</para>
</listitem>

<listitem>
<para>
Denial of Service (DoS) packet rate limiting
</para>
</listitem>

<listitem>
<para>
Packet REJECTs now have user-selectable return ICMP messages
</para>
</listitem>

<listitem>
<para>
Variable levels of logging (different packets can go to different SYSLOG 
levels)
</para>
</listitem>

<listitem>
<para>
Other features like traffic mirroring, securing traffic per login, etc. 
</para>
</listitem>

</ItemizedList>

</para>

<para>

<Emphasis role="strong">CONs:</Emphasis>

<ItemizedList>
<listitem>
<para>
Netfilter is an entirely new architechure thus most of the older 2.2.x 
MASQ kernel modules written to make non-NAT friendly network applications
work through IPMASQ need to be re-written for the 2.4.x kernels.  Because of 
this, if you specifically need functionality from some of these modules
(see below), you should stay with a 2.2.x kernel until these modules have 
been either ported or the application has been updated to use NAT-friendly
protocols.  If you are curious on the porting status of a given module, 
please email the author of the module and NOT David or Ambrose.  We don't 
code.. we just document.  :-)
</para>

<para>
Here is the status of the known IP Masq kernel modules or patches as found 
on the <ULink URL="http://ipmasq.webhop.net">IPMASQ WWW site's Application 
Support Matrix</ULink>.  In addition, you should also setup out the 
<ULink URL="http://www.netfilter.org/documentation/pomlist/pom-summary.html">
Netfilter Patch-o-Matic</ULink> URL as well.  If you have the time and 
knowledge to help in the porting of code, your efforts would be highly 
appreciated:
</para>

<screen>
 Status   = Module name =      Description and notes
---------   -----------   ----------------------------------
 Ported     CuSeeme      Used for Video conferencing

NotPorted   DirectPlay    Used for online Microsoft-based games

 Ported        FTP        Used for file transfers
                          - NOTEs:  Built into the kernel and
                                    fully supports PORTFWed FTP

ReWritten     H.323       Used for Video conferencing

NotPorted      ICQ        Used for Instant messaging
                          * No longer required for modern ICQ clients

 Ported        Irc        Used for Online chat rooms

 Ported      Quake        Used for online Quake games

 Ported       PPTP        Allow for multiple clients to the same server

NotPorted   Real Audio    Used for Streaming video / audio
                          * No longer required for modern RealVideo clients

NotPorted    VDO Live     Used for Streaming audio?
</screen>

<para>
Documentation on how to perform MASQ module porting is available at 
<ULink URL="http://www.netfilter.org/documentation/HOWTO/netfilter-hacking-HOWTO.html">
http://www.netfilter.org/documentation/HOWTO/netfilter-hacking-HOWTO.html
</ULink>.  If you have the time and knowledge, your talent would highly be 
appreciated in porting these modules.
</para>
</listitem>


</ItemizedList>
</para>


<para>
If you'd like to read up more on NetFilter and IPTables, please see:
<ULink URL="http://www.netfilter.org/documentation/index.html#HOWTO">
http://www.netfilter.org/documentation/index.html#HOWTO</ULink> 

and more specifically <ULink 
URL="http://www.netfilter.org/documentation/HOWTO//NAT-HOWTO.html">
http://www.netfilter.org/documentation/HOWTO//NAT-HOWTO.html</ULink> 
</para>


<para>
<Emphasis role="strong">Linux 2.4.x IP Masquerade requirements include:
</Emphasis>
</para>

<ItemizedList>

 <listitem>
  <para>
   Any decent computer hardware.  See <XRef LinkEnd="FAQ-Hardware"> for more 
   details.
  </para>
  </listitem>

  <listitem>
   <para>
    The 2.4.x kernel source is available from <ULink URL="http://www.kernel.org/">
    http://www.kernel.org/</ULink>. 
   </para>
   <para>
    NOTE: Most modern Linux distributions, 
    <XRef LinkEnd="MASQ-supported-Distributions">, that 
    natively come with 2.4.x kernels are typically modular kernels and have 
    all the IP Masquerade functionality already included.  In such cases, 
    there is no need to compile a new Linux kernel.  If you are UPGRADING your 
    kernel, you should be aware of other programs that might be required and/or 
    need to be upgraded as well (mentioned later in this HOWTO).
   </para>
  </listitem>

  <listitem>
   <para>
   The program "iptables" version 1.2.4 or newer ( 1.2.7a or newer is highly 
   recommended ) archive available from 
   <ULink URL="http://www.netfilter.org/">
   http://www.netfilter.org/</ULink>

   <ItemizedList>
    <listitem>
     <para>
     NOTE #1:  All versions of IPTABLES less than 1.2.3 have a FTP module issue
     that can bypass any existing firewall rulesets.  ALL IPTABLES users are
     highly recommended to upgrade to the newest version.  The URL is above.
     </para>
     <para>
     NOTE #2:  All versions of IPTABLES less than 1.2.2 have a FTP "port" security 
     vulnerability in the ip_conntrack_ftp module.  All IPTABLES users are highly 
     recommended to upgrade to the newest version.  The URL is above.
     </para>
    </listitem>

    <listitem>
     <para>
     This tool, much like the older IPCHAINS and IPFWADM tools enables the various
     Masquerding code, more advanced forms of NAT, packet filtering, etc.  It also
     makes use of additional MASQ modules like the FTP and IRC modules.  Additional 
     information on version requirements for the newest IPTABLES howto, etc. is 
     located at the 
     <ULink URL="http://www.netfilter.org/">Unreliable IPTABLES HOWTOs</Ulink>
     page.
     </para>
    </listitem>
   </ItemizedList>

</para>
</listitem>

<listitem>
  <para>
Loadable kernel modules, preferably 2.1.121 or higher, are available from 
<ULink URL="http://home.pi.se/blox/modutils/index.html">
http://home.pi.se/blox/modutils/index.html </ULink> or 
<ULink URL="ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils
">ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils</ULink>
  </para>
</listitem>

<listitem>
<para>
A properly configured and running TCP/IP network running on the Linux machine
as covered in 
<ULink URL="http://www.tldp.org/HOWTO/Net-HOWTO/index.html">
Linux NET HOWTO</ULink> and the 
<ULink URL="http://www.tldp.org/LDP/nag2/index.html">
Network Administrator's Guide</ULink> .  Also check out the 
<ULink URL="http://www.ecst.csuchico.edu/~dranch/LINUX/index-linux.html#TrinityOS">
TrinityOS</ULink> document which is also authored by David Ranch.  TrinityOS is a 
very comprehensive guide for Linux networking.  Some topics include IP MASQ, security, 
DNS, DHCP, Sendmail, PPP, Diald, NFS, IPSEC-based VPNs, and performance sections, 
to name a few.  There are over Fifty sections in all!
</para>
</listitem>

<listitem>
<para>
Connectivity to the Internet for your Linux host covered in 
<ULink URL="http://www.tldp.org/HOWTO/ISP-Hookup-HOWTO.html">
Linux ISP 
Hookup HOWTO</ULink>, <ULink URL="http://www.tldp.org/HOWTO/PPP-HOWTO/index.html">
Linux PPP HOWTO</ULink>, and 
<ULink URL="http://www.ecst.csuchico.edu/~dranch/LINUX/index-linux.html#TrinityOS">
TrinityOS</ULink>.  Other helpful HOWTOs could include: 
<ULink URL="http://www.tldp.org/HOWTO/mini/DHCP/index.html">Linux DHCP 
mini-HOWTO</ULink>, 
<ULink URL="http://www.tldp.org/HOWTO/Cable-Modem/index.html">
Linux Cable Modem mini-HOWTO</ULink> and 
<ULink URL="http://www.tldp.org/HOWTO/DSL-HOWTO/index.html">
http://www.tldp.org/HOWTO/DSL-HOWTO/index.html</ULink>
</para>
</listitem>

<listitem>
<para>
Know how to configure, compile, and install a new Linux kernel as described in 
the <ULink URL="http://www.tldp.org/HOWTO/Kernel-HOWTO/index.html">Linux Kernel 
HOWTO</ULink>.  This HOWTO does cover kernel compiling but only for IP
Masquerade related options.
</para>
</listitem>

</ItemizedList>

</Sect1>


<Sect1 id="kernel-2.2.x-Requirements">
<Title>Requirements for IP Masquerade on Linux 2.2.x </Title>

<para>
<quote> <Emphasis >** Please refer to <ULink URL="http://ipmasq.webhop.net/">IP 
Masquerade Resource</ULink> for the latest information. **</Emphasis> 
</quote> 
</para>

<para>

<ItemizedList>

 <listitem>
  <para>
   Any decent computer hardware.  See <XRef LinkEnd="FAQ-Hardware"> for more 
   details.
  </para>
  </listitem>

  <listitem>
   <para>
    The 2.2.x kernel source is available from <ULink URL="http://www.kernel.org/">
    http://www.kernel.org/</ULink>. 
   </para>
   <para>
    NOTE: Most modern Linux distributions, 
    <XRef LinkEnd="MASQ-supported-Distributions">, that 
    natively come with 2.2.x kernels are typically modular kernels and have 
    all the IP Masquerade functionality already included.  In such cases, 
    there is no need to compile a new Linux kernel.  If you are UPGRADING your 
    kernel, you should be aware of other programs that might be required and/or 
    need to be upgraded as well (mentioned later in this HOWTO).
   </para>

  <ItemizedList>
  <listitem>
    <para>
    NOTE #1:    --- UPDATE YOUR KERNEL ---

    Linux 2.2.x kernels less than version 2.2.20 contain several different 
    security vulnerabilities (some were MASQ specific).  Kernels less than 
    2.2.20 have a few local vulnerabilities.  Kernel versions less 
    than 2.2.16 have a TCP root exploit vulnerability and versions less than 
    2.2.11 have a IPCHAINS fragmentation bug.  Because of these issues, users 
    running a firewall with strong IPCHAINS rulesets are open to possible 
    instrusion.  Please upgrade your kernel to a fixed version.
    </para>
  </listitem>
  </ItemizedList>

</listitem>

<listitem>
<para>
  NOTE #2: Some newer <XRef LinkEnd="MASQ-supported-Distributions"> such as 
           Redhat 5.2 might not be Linux 2.2.x ready (upgradable).  Tools 
           like DHCP, NetUtils, etc. will need to be upgraded.  More details 
           can be found later in the HOWTO.
</para>
</listitem>

 <listitem>
  <para>
   Loadable kernel modules, preferably 2.1.121 or higher, are available from 
   <ULink URL="http://home.pi.se/blox/modutils/index.html">
   http://home.pi.se/blox/modutils/index.html</ULink> or 
   <ULink URL="ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils
   ">ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils</ULink>
  </para>
 </listitem>


<listitem>
<para>
A properly configured and running TCP/IP network running on the Linux
machine as covered in 
<ULink URL="http://www.tldp.org/HOWTO/Net-HOWTO/index.html">
Linux NET HOWTO</ULink> and the 
<ULink URL="http://www.tldp.org/LDP/nag2/index.html">
Network Administrator's Guide</ULink> .  Also check out the 
<ULink URL="http://www.ecst.csuchico.edu/~dranch/LINUX/index-linux.html#TrinityOS">
TrinityOS</ULink> document which is also authored by David Ranch.  TrinityOS is 
a very comprehensive guide for Linux networking.  Some topics include IP MASQ, 
security, DNS, DHCP, Sendmail, PPP, Diald, NFS, IPSEC-based VPNs, and 
performance sections, to name a few.  There are over Fifty sections in all!
</para>
</listitem>

<listitem>
<para>
Connectivity to the Internet for your Linux host covered in 
<ULink URL="http://www.tldp.org/HOWTO/ISP-Hookup-HOWTO.html">
Linux ISP 
Hookup HOWTO</ULink>, <ULink URL="http://www.tldp.org/HOWTO/PPP-HOWTO/index.html">
Linux PPP HOWTO</ULink>, and 
<ULink URL="http://www.ecst.csuchico.edu/~dranch/LINUX/index-linux.html#TrinityOS">
TrinityOS</ULink>.  Other helpful HOWTOs could include:  
<ULink URL="http://www.tldp.org/HOWTO/mini/DHCP/index.html">Linux DHCP 
mini-HOWTO</ULink>, 
<ULink URL="http://www.tldp.org/HOWTO/Cable-Modem/index.html">
Linux Cable Modem mini-HOWTO</ULink> and 
<ULink URL="http://www.tldp.org/HOWTO/DSL-HOWTO/index.html">
http://www.tldp.org/HOWTO/DSL-HOWTO/index.html</ULink>
</para>
</listitem>

<listitem>
<para>
IP Chains 1.3.10 or newer are available from 
<ULink URL="http://www.netfilter.org/ipchains/">
http://www.netfilter.org/ipchains/</ULink>.  
Additional information on 
version requirements for the newest IPCHAINS HOWTO, etc is located at the 
<ULink URL="http://www.netfilter.org/ipchains/"> Linux IP Chains 
page</ULink> <ULink URL="http://www.netfilter.org/ipchains"> (mirror at
Samba.org)</ULink>
</para>
</listitem>

<listitem>
<para>
Know how to configure, compile, and install a new Linux kernel as described in 
the <ULink URL="http://www.tldp.org/HOWTO/Kernel-HOWTO/index.html">Linux Kernel 
HOWTO</ULink>.  This HOWTO does cover kernel compiling but only for IP
Masquerade related options.
</para>
</listitem>

</ItemizedList>
</para>


<para>
 <Emphasis role="strong">
 Other optional patches and tools for 2.2.x kernels</Emphasis>

 <itemizedlist>
  <listitem>
   <para>
   TCP/IP port-forwarding or re-directing:
   <ItemizedList>
     <listitem>
     <para>
      <ULink URL="http://ipmasq.webhop.net/juanjox/">IP PortForwarding (IPMASQADM) 
- RECOMMENDED - mirror</ULink> 
     </para>
    </listitem>
   </ItemizedList>

   </para>
  </listitem>

  <listitem>
   <para>
    PORTFW FTP Solutions:
    <ItemizedList>
     <listitem>
      <para>
      There are 2.2.x and 2.0.x kernel MASQ Module solutions for PORTFWed FTP 
      to a MASQed machine (put an FTP server behind a MASQ server).  Please 
      see the Application Page on the <ULink URL="http://ipmasq.webhop.net">
      IPMASQ WWW site </ULink> for full details.  Please note that this is not 
      required for 2.4.x kernels.
      </para>
      <para>
      There is a full FTP proxy application from SuSe that will also allow 
      PORTFWed-like functionality to reach an internal FTP server.  For more 
      details, please refer to the 
      <ULink URL="http://www.suse.de/en/whitepapers/proxy_suite/">SuSe Proxy 
      URL</ULink>.
      </para>
     </listitem>
    </itemizedlist>
   </para>
  </listitem>

  <listitem>
   <para>
   IPROUTE2 for True 1:1 NAT, Policy-based (source) routing, and Traffic 
   Shaping:

   <ItemizedList>

    <listitem>
     <para>
      <ULink URL="ftp://ftp.inr.ac.ru/ip-routing/">ftp://ftp.inr.ac.ru/ip-routing
      </ULink>
     </para>
    </listitem>

    <listitem>
     <para>
     Documentation can be found at 
     <ULink URL="http://www.compendium.com.ar/policy-routing.txt">
     http://www.compendium.com.ar/policy-routing.txt</ULink> 
     </para>
    </listitem>

    <listitem>
     <para>
     The <ULink URL="http://www.tldp.org/HOWTO/Adv-Routing-HOWTO/index.html">
     Advanced Routing HOWTO</ULink>
     </para>
    </listitem>

    <listitem>
     <para>
     Some source code mirrors are at:
     </para>

     <para>
     <ULink URL="ftp://ftp.funet.fi/pub/mirrors/ftp.inr.ac.ru/ip-routing/">
     ftp://ftp.funet.fi/pub/mirrors/ftp.inr.ac.ru/ip-routing/ (STM1 to USA)</ULink>
     --- 
     <ULink URL="ftp://sunsite.icm.edu.pl/pub/Linux/iproute/">
     ftp://sunsite.icm.edu.pl/pub/Linux/iproute/</ULink>
     </para>

     <para>
     <ULink URL="ftp://ftp.sunet.se/pub/Linux/ip-routing/">
     ftp://ftp.sunet.se/pub/Linux/ip-routing/</ULink> --- 
     <ULink URL="ftp://ftp.nvg.ntnu.no/pub/linux/ip-routing/">
     ftp://ftp.nvg.ntnu.no/pub/linux/ip-routing/</ULink>
     </para>

     <para>
     <ULink URL="ftp://ftp.crc.ca/pub/systems/linux/ip-routing/">
     ftp://ftp.crc.ca/pub/systems/linux/ip-routing/</ULink> --- 
     <ULink URL="ftp://ftp.paname.org">ftp://ftp.paname.org (France)</ULink>
     </para>
 
    </listitem>

   </ItemizedList>
  </para>
 </listitem>
</ItemizedList>
</para>
 
<para>
Please see the <ULink URL="http://ipmasq.webhop.net/">IP Masquerade Resource
</ULink> page for more information available on these patches and possibly 
others as well.
</para>

</Sect1>


<Sect1 id="kernel-2.0.x-Requirements">
<Title>Requirements for IP Masquerade on Linux 2.0.x</Title>

<para>
<quote> <Emphasis >** Please refer to <ULink URL="http://ipmasq.webhop.net/">IP 
Masquerade Resource</ULink> for the latest information. **</Emphasis> 
</quote>
</para>

<ItemizedList>

<listitem>
<para>
Any decent computer hardware.  See <XRef LinkEnd="FAQ-Hardware"> for more 
details.
</para>
</listitem>

  <listitem>
   <para>
    The 2.0.x kernel source is available from <ULink URL="http://www.kernel.org/">
    http://www.kernel.org/</ULink>. 
   </para>
   <para>
    NOTE: Most modern Linux <XRef LinkEnd="MASQ-supported-Distributions"> that 
    natively come with 2.0.x kernels are typically modular kernels and have 
    all the IP Masquerade functionality already included.  In such cases, 
    there is no need to compile a new Linux kernel.  If you are UPGRADING your 
    kernel, you should be aware of other programs that might be required and/or 
    need to be upgraded as well (mentioned later in this HOWTO).
   </para>
  </listitem>

 <listitem>
  <para>
   Loadable kernel modules, preferably 2.1.85 or newer is available from 
   <ULink URL="http://home.pi.se/blox/modutils/index.html">
   http://home.pi.se/blox/modutils/index.html </ULink> or 
   <ULink URL="ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils
   ">ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils</ULink>
   (modules-1.3.57 is the minimal requirement)
   </para>
  </listitem>

<listitem>
<para>
A properly configured and running TCP/IP network running on the Linux machine
as covered in <ULink URL="http://www.tldp.org/HOWTO/Net-HOWTO/index.html">
Linux 
NET HOWTO </ULink> and the <ULink URL="http://www.tldp.org/LDP/nag2/index.html">
Network Administrator's Guide</ULink>Also check out the 
<ULink URL="http://www.ecst.csuchico.edu/~dranch/LINUX/index-linux.html#TrinityOS">
TrinityOS</ULink> document which is also authored by David Ranch.  TrinityOS is 
a very comprehensive guide to Linux networking.  Topics include IP MASQ, 
security, DNS, DHCP, Sendmail, PPP, Diald, NFS, IPSEC-based VPNs, performance 
issues, and many more.  There exists over fifty sections in all!
</para>
</listitem>

<listitem>
<para>
Connectivity to the Internet for your Linux host is covered in 
<ULink URL="http://www.tldp.org/HOWTO/ISP-Hookup-HOWTO.html">
Linux ISP 
Hookup HOWTO</ULink>, <ULink URL="http://www.tldp.org/HOWTO/PPP-HOWTO/index.html">
Linux PPP HOWTO</ULink>, and
<ULink URL="http://www.ecst.csuchico.edu/~dranch/LINUX/index-linux.html#TrinityOS">
TrinityOS</ULink>.  Other helpful HOWTOs could include: 
<ULink URL="http://www.tldp.org/HOWTO/mini/DHCP/index.html"> Linux DHCP 
mini-HOWTO</ULink>, 
<ULink URL="http://www.tldp.org/HOWTO/Cable-Modem/index.html">
Linux Cable Modem mini-HOWTO</ULink> and 
<ULink URL="http://www.tldp.org/HOWTO/DSL-HOWTO/index.html">Linux DSL HOWTO
</ULink>
</para>
</listitem>

<listitem>
<para>
Ipfwadm 2.3.0 or newer is available from 
<ULink URL="http://www.xos.nl/linux/ipfwadm/download.html">
http://www.xos.nl/linux/ipfwadm/download.html
</ULink>
</para>
</listitem>

<listitem>
<para>
More information on version requirements are on the 
<ULink URL="http://www.xos.nl/linux/ipfwadm/">Linux IPFWADM page</ULink>
</para>
</listitem>

<listitem>
<para>
If you are interested in running IPCHAINS on a 2.0.x+ kernel, see 
<ULink URL="http://miaif.lip6.fr/~tarreau/pub/linux-patches/">
Willy Tarreau's 
IPCHAINS enabler for 2.0.36+</ULink> or 
<ULink URL="http://www.tldp.org/HOWTO/IPCHAINS-HOWTO.html"> Rusty's 
IPCHAINS for 2.0.x kernels</ULink>.  Please note that these patches are NOT
compatible with the IPPORTFW patches for the 2.0.x kernels.  Unfortunately,
its an either/or deal.
</para>
</listitem>

<listitem>
<para>
Know how to configure, compile, and install a new Linux kernel as described in 
the <ULink URL="http://www.tldp.org/HOWTO/Kernel-HOWTO/index.html">
Linux Kernel HOWTO</ULink>.  This HOWTO does cover kernel compiling but only 
for IP Masquerade related options.
</para>
</listitem>

</ItemizedList>



<para>
<Emphasis role="strong">Here is a list of IP Masquerading patches for 2.0.x kernels:</Emphasis>
</para>
 
<ItemizedList>

 <listitem>
  <para>
  Steven Clarke's 
  <ULink URL="http://www.ox.compsoc.org.uk/~steve/portforwarding.html">IP 
  PortForwarding (IPPORTFW)</ULink> - <Emphasis >RECOMMENDED</Emphasis>
  </para>
 </listitem>

 <listitem>
  <para>
  <ULink URL="http://ipmasq.webhop.net/ipautofw.tar.gz">IP AutoForward</ULink> 
  - <ULink URL="http://ipmasq.webhop.net/tcpdeath.html">NOT 
  Recommended</ULink>
  </para>
 </listitem>

 <listitem>
  <para>
  <ULink URL="http://ipmasq.webhop.net/redir_0.7.orig.tar.gz">REDIR</ULink> for TCP 
  (REDIR) - NOT Recommended unless required for internal PORTFW
  </para>
 </listitem>

 <listitem>
  <para>
  <ULink URL="http://ipmasq.webhop.net/udpred.c.gz">UDP redirector</ULink> 
  (UDPRED) - NOT Recommended
  </para>
 </listitem>

 <listitem>
  <para>
  PORTFWed FTP:

  <ItemizedList>
   <listitem>
    <para>
     If you are going to port forward FTP traffic to an internal FTP server, you 
     might need to download <ULink URL="http://ipmasq.webhop.net/files22/ip_masq-v0.27-for_2.2.18pre9.patch.gz">
     Fred Viles's FTP server patch</ULink> 
     The reason for "might" is that some 
     users have had success without the use of these pathches, while others need it.  
     Explicit details on this topic can be found in <XRef LinkEnd="Forwarders"> of 
     this HOWTO.
    </para>
   </listitem>
  </ItemizedList>
  </para>
 </listitem>


 <listitem>
  <para>
  X-Windows display forwarders:

  <ItemizedList>
   <listitem>
    <para>
     <ULink URL="ftp://sunsite.unc.edu/pub/Linux/X11/compress/dxpc-3.7.0.tar.gz">
     X-windows forwarding (DXCP)</ULink>
    </para>
   </listitem>
  </ItemizedList>

  </para>
 </listitem>

 <listitem>
  <para>
  PPTP (GRE) and SWAN (IPSEC) VPNs tunneling forwarders:

  <ItemizedList>
   <listitem>
    <para>If you plan connecting an internal MASQed PC to a remote PPTP server,
you MUST INSTALL the PPTP-Masquerade kernel patch available from the URLsbelow.  
If you plan on having external PPTP users connect to an internal masqueraded 
PPTP server, not only do you need the kernel patch installed but you also need 
PORTFW support enabled in the kernel.   Please see the following URLs for the 
patches and more information:
    </para>

    <para>
    <ULink URL="http://www.impsec.org/linux/masquerade/ip_masq_vpn.html">
    John Hardin's VPN Masquerade forwarders</ULink> or the old patch for just 
    <ULink URL="http://ipmasq.webhop.net/ip_masq_pptp.patch.gz">PPTP Support</ULink>.  
    </para>
   </listitem>
  </ItemizedList>

  </para>
 </listitem>

 <listitem>
  <para>
  Game specific patches:

  <ItemizedList>
   <listitem>
    <para>
    Glenn Lamb's 
    <ULink URL="http://ipmasq.webhop.net/files20/loose-udp-2.0.36.patch.gz">
    LooseUDP for 2.0.36+</ULink> patch.  
    </para>
   </listitem>
  </ItemizedList>
  </para>

 </listitem>
</ItemizedList>

</Sect1>
</Chapter>


<Chapter>
<Title>Setting Up IP Masquerade</Title>

<Sect1 id="ipmasq-compiling3.0">
<Title>Compiling a new kernel if needed</Title>

<para>
If your private network contains any vital information, think carefully in 
terms of SECURITY before implementing IP Masquerade.  By default, IP MASQ 
becomes a GATEWAY for you to get onto the Internet, but it also can allow 
someone from the Internet to possibly get into your internal network.
</para>

<para>
 <emphasis role="strong">
 Once you have IP MASQ functioning, it is HIGHLY recommended for the user to 
 implement a STRONG IPFWADM/IPCHAINS firewall ruleset.  Please see 
 <XRef LinkEnd="rc.firewall-iptables-stronger">, 
 <XRef LinkEnd="rc.firewall-ipchains-stronger"> and 
 <XRef LinkEnd="rc.firewall-ipfwadm-stronger"> located below for more details.
 </emphasis>
</para>

</Sect1>

<Sect1 id="ipmasq-compiling3.1">
<Title>Checking your existing kernel for MASQ functionality</Title>

<para>
<Emphasis role="strong">Almost ALL modern Linux distributions come MASQ-Ready 
these days but its always good to check your system before you try to set 
things up.  Follow these few steps for your kernel to see if your kernel
is MASQ ready.
</Emphasis>
</para>

<para>
To see which kernel your system is running, run the following command:
<Screen>
uname -a
</Screen>
</para>

<para>

<ItemizedList> <!-- Start general check list -->

 <listitem>
  <para>
   Just for clarity: 2.4.x kernels run IPTABLES :: 2.2.x kernels run IPCHAINS ::
 2.0.x kernels run IPFWADM 
  </para>
 </listitem>

 <listitem>
  <para>
   In general, you must have kernel support for:
   
   <Itemizedlist>

    <listitem>
     <para>
      IP forwarding
     </para>
    </listitem>
    <listitem>
     <para>
      IP masquerading
     </para>
    </listitem>
    <listitem>
     <para>
      IP Firewalling
     </para>
    </listitem>
    <listitem>
     <para>
      etc.
     </para>
    </listitem>

   </ItemizedList>

  </para>
 </listitem>

</ItemizedList> <!-- end general check list -->
</para>

<para>
You will also need to have most MASQ-related modules compiled (most modular 
kernels will already have all you need already done.  Then you will NOT need 
to re-compile the kernel.  If you AREN'T SURE if your Linux distribution is 
MASQ ready, do the following: 

<ItemizedList> <!-- start specific check list -->

 <listitem> <!-- 2.4.x -->
  <para>
  <Emphasis role="strong">2.4.x kernels</Emphasis> (look for most of the 
following entries out of the much longer list):
   
   <Itemizedlist> <!-- 2.4.x sub 1 -->

    <listitem>
     <para>
      Run the command "<Literal>ls /proc/sys/net/ipv4</Literal>" while logged
      into the Linux box.  These items are required and should be present 
      regardless if your kernel built IPMASQ as modules or statically.

      <ItemizedList> <!-- 2.4.x sub 2 -->
       <listitem>
        <para>
         <Literal>ip_dynaddr</Literal>
        </para>
        <para>
         <Literal>ip_forward</Literal>
        </para>
       </listitem
      </Itemizedlist>  <!-- 2.4.x sub 2 -->

     </para>
    </listitem>

    <listitem>
     <para>
      To check if IPMASQ was compiled statically into the kernel, run the 
      command "<Literal>/sbin/lsmod</Literal>" and see if and modules like
      the ones shown below for the MODULE section are loaded.  No?  Ok, 
      now run the command "<Literal>ls /proc/net/</Literal>" and see if you 
      see additional /proc files such as:

      <ItemizedList>  <!-- 2.4.x sub 3 -->
       <listitem>
        <para>
         <Literal>ip_masquerade</Literal>
        </para>
        <para>
         <Literal>ip_conntrack</Literal>
        </para>
        <para>
         <Literal>ip_tables_names</Literal>
        </para>
       </listitem
      </Itemizedlist>  <!-- 2.4.x sub 3 -->

     If you see these /proc entries and there WEREN'T any kernel modules loaded
     (shown via the "lsmod" command mentioned above), then your kernel has 
     the IPTABLES subsystem statically compiled into it and is ready to go to 
     use IPMASQ on this system.
     </para>
    </listitem>

    <listitem>
     <para>
      If your kernel uses IPTABLES via modules, most of the stuff listed above 
      should have been missing (because the modules probably aren't loaded).  
      Run the command "<Literal>ls 
/lib/modules/`uname -r`/kernel/net/ipv4/netfilter/</Literal>" where you should 
      see files like:

      <ItemizedList>  <!-- 2.4.x sub 4 -->
       <listitem>
        <para>
         <Literal>ip_conntrack.o, ip_conntrack_ftp.o, ip_conntrack_irc.o, 
ip_nat_ftp.o, ip_nat_irc.o</Literal> 
        </para>
        <para>
         <Literal>ip_tables.o, ipt_MASQUERADE.o, iptable_nat.o, 
iptable_mangle.o, iptable_filter.o</Literal>
        </para>
        <para>
        And some optional ones like: <Literal>ipchains.o, ipt_REJECT.o, 
and ipt_tcpmss.o</Literal>
        </para>
       </listitem
      </Itemizedlist>  <!-- 2.4.x sub 4 -->

     If you see those kernel files, IPTABLES was compiled using modules and 
     things look ready to go to use IPMASQ on this system. 

     </para>
    </listitem>
   </Itemizedlist> <!-- 2.4.x sub 1 -->

   </para>
  </listitem> <!-- 2.4.x -->

 <listitem> <!-- 2.2.x -->
  <para>
   <Emphasis role="strong">2.2.x kernels</Emphasis> (look for most of the 
following entries out of the much longer list): list):
   
   <Itemizedlist> <!-- 2.2.x sub 1 -->
    <listitem>
     <para>
      Run the command "<Literal>ls /proc/sys/net/ipv4</Literal>" while logged
      into the Linux box.  These items are required and should be present 
      regardless if your kernel built IPMASQ as modules or statically.

      <ItemizedList> <!-- 2.2.x sub 2 -->
       <listitem>
        <para>
         <Literal>ip_always_defrag</Literal>
        </para>
        <para>
         <Literal>ip_dynaddr</Literal>
        </para>
        <para>
         <Literal>ip_forward</Literal>
        </para>
        <para>
         <Literal>ip_masq_debug</Literal>
        </para>
        <para>
         <Literal>ip_masq_udp_dloose</Literal>  (some distros don't support 
this -- ignore it for now
        </para>

        <para>


         <Emphasis role="strong">Other 2.2.x options</Emphasis> can be checked 
by running "ls /proc/net/"

         <Itemizedlist> <!-- 2.2.x sub 2a -->
          <listitem>
           <para>
            <Literal>ip_fwchains</Literal>
           </para>
           <para>
            <Literal>ip_fwnames</Literal>
           </para>
           <para>
            <Literal>ip_masquerade</Literal>
           </para>
          </listitem>
         </Itemizedlist> <!-- 2.2.x sub 2a -->

        </para>

        <para>
         <Emphasis role="strong">Even more 2.2.x options</Emphasis> can be 
checked by running "ls /proc/net/"
        
         <Itemizedlist> <!-- 2.2.x sub 2b -->
          <listitem>
           <para>
            <Literal>app</Literal>
           </para>
           <para>
            <Literal>icmp</Literal>
           </para>
           <para>
            <Literal>icq</Literal>
           </para>
           <para>
            <Literal>mfw</Literal>
           </para>
           <para>
            <Literal>portfw</Literal>
           </para>
           <para>
            <Literal>tcp</Literal>
           </para>
           <para>
            <Literal>udp/</Literal>
           </para>
          </listitem>
         </Itemizedlist> <!-- 2.2.x sub 2b -->

        </para>
       </listitem>

      </Itemizedlist> <!-- 2.2.x sub 2 -->
     </para>
    </listitem>

   </ItemizedList> <!-- 2.2.x sub 1 -->
  </para>
 </listitem> <!-- 2.2.x -->
 
 <listitem> <!-- 2.0.x -->
  <para>
   <Emphasis role="strong">2.0.x kernels</Emphasis> (look for most of the 
following entries out of the much longer list): 
   
   <Itemizedlist> <!-- 2.0.x sub 1 -->
    <listitem>
     <para>
      Run the command "<Literal>ls /proc/sys/net/ipv4</Literal>" while logged
      into the Linux box.  These items are required and should be present 
      regardless if your kernel built IPMASQ as modules or statically.
         
      <ItemizedList>  <!-- 2.0.x sub 2 -->
       <listitem>
        <para>
         <Literal>ip_dynaddr</Literal>
        </para>
        <para>
         <Literal>ip_forward</Literal>
        </para>
        <para>
         running "ls /proc/net"

        <Itemizedlist>  <!-- 2.0.x sub 3 -->
          <listitem>
           <para>
            <Literal>ip_forward</Literal>
           </para>
           <para>
            <Literal>ip_masq_app</Literal>
           </para>
           <para>
            <Literal>ip_masquerade</Literal>
           </para>
           <para>
            <Literal>ip_portfw</Literal>
           </para>
          </listitem
         </Itemizedlist>  <!-- 2.0.x sub 3 -->

         </para>

       </listitem>
      </Itemizedlist>  <!-- 2.0.x sub 2 -->

     </para>
    </listitem>
   </Itemizedlist>  <!-- 2.0.x sub 1 -->

  </para>
 </listitem> <!-- 2.0.x -->

</ItemizedList> <!-- specific check list -->
</para>

<para>
Ultimately, it comes down to the fact if you see /proc files such as 
"i<Literal>ip_forward</Literal>", "<Literal>ip_masq_debug</Literal>", 
"<Literal>ip_masq_udp_dloose</Literal>"(optional), and "<Literal>
ip_always_defrag</Literal>" (optional) exist.  
</para>

<para>
  So.  Do most of the above /proc entries or kernel modules show up for your 
  respective kernel?  If so, thats good!  If you cannot find any of the above 
  entries or if you aren't sure if your distribution supports IP Masquerading by 
  default, ASSUME IT DOESN'T SUPPORT MASQ.  You can do one last check by looking 
  at the <XRef LinkEnd="MASQ-supported-Distributions"> section and see if your 
  Linux Distribution is listed.  Still not there?  Sounds like you'll need to 
  compile a kernel but don't worry.. it isn't hard.
</para>

<para>
<Emphasis role="strong">Regardless if your current kernel has MASQ support or 
not</Emphasis>, reading the remainder of this section is still highly 
recommended as it contains other useful information.  
</para>


<Sect2 id=ipmasq-compiling3.1.1>
<Title>Compiling Linux 2.4.x Kernels</Title>

<ItemizedList>
 <listitem>
  <para>
   First, you'll need to get some 2.4.x kernel sources (preferably the latest 
   kernel version - NEWER *IS* BETTER IN LINUX LAND)
  </para>

  <Itemizedlist>
   <listitem>
    <para>
     NOTE #1: As both the 2.4.x kernel train and the iptables program 
development progresses, the compile configurion options will change over time.  
As of this version of the IPMASQ howto, this section reflects the settings for 
IPTABLES 1.2.7a and the 2.4.20 kernel.  If you are compiling against a newer 
or previous kernel or IPTABLES version, the dialogs and even commands might 
look different.  It is recommended that you update to the newest versions of 
both the kernel and IPTABLES for added capability, performance, and stability 
of the kernel.
    </para>
   </listitem>
  </Itemizedlist>
 </listitem>

 <listitem>
  <para>
   Next, depending on the version of the Linux kernel and IPTABLES archive you 
   downloaded, you <Emphasis role="strong">might </Emphasis>want to apply some 
   IPTABLES "patch-o-matic" patches against the kernel.  These OPTIONAL patches 
   might fix some known problems, add additional functionality you might need 
   (H.323 protocol, specific issues with network games), etc.  It should be 
   noted that the Patch-O-Matic patches used to come with the IPTABLES archive.
   This is no longer the case and you have to download them (if any) seperately. 
   You can find the the various URLs for downloading IPTABLES, the 
   Patch-o-matic system, etc.  <XRef LinkEnd="kernel-2.4.x-Requirements">.
  </para>
 </listitem>

<listitem>
<para>
If this is your first time compiling the kernel, don't be scared. In fact, 
it's rather easy and it's covered in several URLs found in 
<XRef LinkEnd="kernel-2.4.x-Requirements">.  Please note that the instructions
included here is just one way to do build a kernel.  Please see the Kernel
HOWTO for full details.
</para>

<para>
<Emphasis role="strong">NOTE: </Emphasis>Please notice that it <Emphasis
role="strong">IS NOT </Emphasis> recommended to put the new kernel sources 
into the /usr/src/linux directory.  You should leave the original kernel 
sources that came with your Linux distribution in /usr/src/linux.  For more 
details on this topic, please read the "README" file in the top level 
directory of the kernel sources.
</para>
</listitem>

<listitem>
<para>For this HOWTO example, create a directory called <Literal>/usr/src/kernel</Literal>.  
Next, "cd" into this directory and download the newest 2.4.x kernel sources
into it.  Once downloaded, issue the following command (if the file ends in a .tar.gz): 
<Literal>tar xvzf linux-2.4.x.tar.gz</Literal> or (if the file ends in a 
.tar.bzip2): <Literal>tar xyvf linux-2.4.x.tar.bz2</Literal>.  Please 
substitute the "x" in the 2.4.x filename with the Linux 2.4 kernel version you 
downloaded.  
</para>

<para>
BZ2 Note:  Some Linux distributions use the "I" option instead of the "y" 
option to decompress bzip2 archives.
</para>

  <para>
   Once uncompressed, I recommend that you rename the directory from the stock
   "linux" name to "linux-2.4.x" (replace the "x" with the specific version of
   your newly installed kernel) for clarity.  To do this, run the command 
   "<Literal>mv linux linux-2.4.x</Literal>".  Next, make sure there is a 
   directory or symbolic link pointing to 
   "<Literal>/usr/src/kernel/linux</Literal>" ie.  run the command: 
   <screen>ln -s /usr/src/kernel/linux-2.4.x /usr/src/kernel/linux</screen> 
   again subsituting the "x" for your proper kernel version.
  </para>
</listitem>

<listitem>
<para>
As mentioned above, you might consider applying any appropriate or optional 
patches to the kernel's MASQ code BEFORE you compile the final kernel.  
The IP MASQ code found in the stock kernels is already very useful and does 
not require any specific patching in order for the system to work for 
NAT-friendly network applications.  Many of these patches are only to fix 
possible known bugs, add new features (some are /very/ cool), etc.  Please 
refer to <XRef LinkEnd="kernel-2.4.x-Requirements"> for URLs and the 
<ULink URL="http://ipmasq.webhop.net/">IP Masquerade Resources</ULink> for 
up-to-date information and patch URLs.
</para>
</listitem>

<listitem>
<para>
  <Emphasis role="strong">Applying IPTABLES and Patch-o-Matic kernel patches
</Emphasis>
</para>

<para>
Download the iptables package and optional Patch-O-matics from the 
<XRef LinkEnd="kernel-2.4.x-Requirements"> and put it into a directory, say 
"<Literal>/usr/src/archive/netfilter</Literal>".  Next, go into this new 
netfilter directory and uncompress the iptables archive with the command: 
</para>

<para>
<screen>
<Literal>tar xyvf iptables-x.y.z.tar.bz2</Literal>
<Literal>tar xyvf patch-o-matic-x.tar.bz2</Literal>
</screen>
</para>

<para>
Now, go into the new iptables-x.y.x directory
(/usr/src/archive/netfilter/iptables-x.y.z) and run the command
</para>
<para>
<screen>
 <Literal>#For iptables v1.2.7a:</Literal>
 <Literal>make KERNEL_DIR=/usr/src/kernel/linux</Literal>
 <Literal> </Literal>
 <Literal>#For iptables v1.2.4 (when Patch-o-matic was built-in):</Literal>
 <Literal>make pending-patches KERNEL_DIR=/usr/src/kernel/linux</Literal>
 <Literal> </Literal>
</screen>
</para>

<para>
NOTE: this assumes that your 2.4.x kernel sources are in the 
<Literal>/usr/src/kernel/linux</Literal> directory.  
</para>

<para>
NOTE #2: If you append a "/" to the end of the above command line, you
will get an error stating: 
<screen>
"make: *** [/usr/src/kernel/linux/include/asm/socket.h] Error 1".
</screen>
Remove the trailing "/" and try again.
</para>

<para>
Here is an example of compiling IPTABLES v1.2.7a.  Your output might look
different depending on what version you are trying to use.
</para>
</listitem>

<listitem>
<para>
<screen>
# make KERNEL_DIR=/usr/src/kernel/linux

Extensions found:

cc -O2 -Wall -Wunused -I/usr/src/kernel/linux/include -Iinclude/
-DIPTABLES_VERSION=\"1.2.7a\"  -fPIC -o extensions/libipt_ah_sh.o -c
extensions/libipt_ah.c
ld -shared -o extensions/libipt_ah.so extensions/libipt_ah_sh.o
cc -O2 -Wall -Wunused -I/usr/src/kernel/linux/include -Iinclude/
-DIPTABLES_VERSION=\"1.2.7a\"  -fPIC -o extensions/libipt_conntrack_sh.o -c
extensions/libipt_conntrack.c
ld -shared -o extensions/libipt_conntrack.so extensions/libipt_conntrack_sh.o
cc -O2 -Wall -Wunused -I/usr/src/kernel/linux/include -Iinclude/
-DIPTABLES_VERSION=\"1.2.7a\"  -fPIC -o extensions/libipt_dscp_sh.o -c
extensions/libipt_dscp.c
extensions/libipt_dscp_helper.c:69: warning: `dscp_to_name' defined but not
used
ld -shared -o extensions/libipt_dscp.so extensions/libipt_dscp_sh.o
.
.
.
cc -O2 -Wall -Wunused -I/usr/src/kernel/linux/include -Iinclude/
-DIPTABLES_VERSION=\"1.2.7a\"    -c -o libipulog/libipulog.o
libipulog/libipulog.c
ar rv libipulog/libipulog.a libipulog/libipulog.o
a - libipulog/libipulog.o
rm libiptc/libip6tc.o libiptc/libip4tc.o libipulog/libipulog.o libipq/libipq.o
</screen>
</para>
</listitem>

<listitem>
<para>
Ok, hopefully the IPTABLES program compiled up for you.  Now, you need to
install it.  To do this, directory and run the command
</para>

<para>
<screen>
 <Literal>make install KERNEL_DIR=/usr/src/kernel/linux</Literal>
</screen>
</para>
</listitem>

<listitem>
<para>
Here is an example of installing IPTABLES v1.2.7a.  Your output might look
different depending on what version you are trying to use.
</para>
</listitem>

<listitem>
<para>
<screen>
# make install KERNEL_DIR=/usr/src/kernel/linux   

cp iptables /usr/local/sbin/iptables
cp iptables-save /usr/local/sbin/iptables-save
cp iptables-restore /usr/local/sbin/iptables-restore
cp ip6tables /usr/local/sbin/ip6tables
cp extensions/libipt_ah.so /usr/local/lib/iptables/libipt_ah.so
cp extensions/libipt_conntrack.so /usr/local/lib/iptables/libipt_conntrack.so
cp extensions/libipt_dscp.so /usr/local/lib/iptables/libipt_dscp.so
cp extensions/libipt_ecn.so /usr/local/lib/iptables/libipt_ecn.so
cp extensions/libipt_esp.so /usr/local/lib/iptables/libipt_esp.so
cp extensions/libipt_helper.so /usr/local/lib/iptables/libipt_helper.so
.
.
.
cp extensions/libip6t_udp.so /usr/local/lib/iptables/libip6t_udp.so
cp extensions/libip6t_LOG.so /usr/local/lib/iptables/libip6t_LOG.so
cp extensions/libip6t_MARK.so /usr/local/lib/iptables/libip6t_MARK.so
</screen>
</para>
</listitem>
</ItemizedList>

<para>
Next, if you are interested in applying a Patch-O-Matic patch set, go into the 
<Literal>patch-o-matic-X </Literal>directory 
(/usr/src/archive/netfilter/patch-o-matic-X) and run the command
</para>

<ItemizedList>
<listitem>
<para>
<screen>
 <Literal>#For Patch-O-Matic later than the release of iptables v1.2.7a:</Literal>
 <Literal>KERNEL_DIR=/usr/src/kernel/linux</Literal>
 <Literal>./runme pending</Literal>
 <Literal> </Literal>
</screen>
</para>

<para>
NOTE #1: The use of the "pending" batch is the most common for IPMASQ
functionality but there are several others.  See below.
</para>

<para>
NOTE #2: this assumes that your 2.4.x kernel sources are in the 
<Literal>/usr/src/kernel/linux</Literal> directory.  
</para>

<para>
NOTE #3: If you append a "/" to the end of the command line, you
will get an error stating: 
<screen>
"make: *** [/usr/src/kernel/linux/include/asm/socket.h] Error 1".
Remove the trailing "/" and try again.
</screen>
</para>

<para>
Here is an example of the Patch-O-Matic prompts you might receive for a 
2.4.20 kernel with the "20030107" Patch-O-Matic set.  You can also run the 
"runme" program in a batch mode to speed things up, add experimental patches,
etc. if you'd like.  To better 
understand your options, simply run the "<Literal>./runme</Literal>" command 
by itself.  Please note that these prompts WILL CHANGE over time.
</para>
</listitem>

<listitem>
<para>
<screen>
Welcome to Rusty's Patch-o-matic!

Each patch is a new feature: many have minimal impact, some do not.
Almost every one has bugs, so I don't recommend applying them all!
-------------------------------------------------------
Already applied: submitted/01_2.4.19
                 submitted/02_2.4.20
                 submitted/ipt_ULOG-mac_len-fix
                 submitted/ipt_multiport-invfix
                 pending/01_ip_conntrack_proto_tcp-lockfix
                 pending/02_newnat-udp-helper
                 pending/03_REJECT-fwspotting-phrack60-fix
                 pending/04_ftp-conntrack-msg-fix

Testing... 05_ECN-tcpchecksum-littleendian-fix.patch NOT APPLIED (1 rejects out
of 1 hunks)
The pending/05_ECN-tcpchecksum-littleendian-fix patch:
   Author: Patrick McHardy 
   Status: Pending for kernel inclusion
   
   The 2.4.20 kernel included the new iptables 'ECN' target, enabling a
selective
   ECN disable mechanism.   Unfortunately there was a bug in the incremental
TCP
   checksum update, resulting in broken TCP checksums on little endian
machines.
   
   This patch fixes the Bug.
   
Testing patch pending/05_ECN-tcpchecksum-littleendian-fix.patch...
   Patch pending/05_ECN-tcpchecksum-littleendian-fix.patch applied cleanly.
Applying patch pending/05_ECN-tcpchecksum-littleendian-fix.patch...
   Patch pending/05_ECN-tcpchecksum-littleendian-fix.patch applied cleanly.

Excellent! Kernel is now ready for compilation.
</screen>
</para>
</listitem>

<listitem>
  <para>
   If everything patches fine, you should see something like the text
  </para>

  <para>
   <screen>Excellent! Kernel is now ready for compilation.</screen>
  </para>

  <para>
   towards the bottom of the screen.  Beyond that, you don't have to
   install anything at this point.  The next step is to compile the new 
   PATCHED kernel.
  </para>
 </listitem>


 <listitem>
  <para>
   Ok, now the new kernel is ready to be compiled but you should make sure 
   that you also have the proper matching <literal>iptables</literal> program 
   on your machine too (just to make sure).  Run the command:
   <Itemizedlist>
    <listitem>
     <para>
      <screen>whereis iptables</screen>
     </para>
    </listitem>
   </Itemizedlist>
   and make sure its installed on the machine (the default place is in
   <literal>/usr/local/sbin/iptables</literal>.  If you cannot find it
   or patched up your kernel sources as shown above, I recommend you just 
   re-compile it up as shown above.  
  </para>
 </listitem>
</ItemizedList>

<para>
 Now that the kernel sources are patched up, you need to configure it to
 know what kinds of features you need (HD support, Networking support, MASQ 
 support, etc.).  Here are the MINIMUM kernel configuration options required 
 to enable IP Masquerade functionality.  Please understand that this HOWTO 
 illustrates just ONE way to configure and compile a kernel (modules vs static).  
 The main difference from this example vs. an example given by a different
 MASQ guide is that some people might wish to compile kernel components either 
 as <Emphasis role="strong">modules OR monolithically</Emphasis> into the 
 kernel.  Basically, compiling things as modules gives you added flexibility 
 to what is or isn't installed into the kernel (reduces unneeded memory use 
 for things you aren't / won't use and modules also allow for drop-in software
 upgrades [usually no need to reboot the machine]).  On the flip side, kernel 
 modules add more complexity to your configuration and sometimes the kernel 
 auto-loader might make mistakes (not that I've ever seen this happen).  
 Compiling things directly into the kernel makes things simpler BUT you loose 
 a huge level of flexibility.  The following kernel configuration example is a 
 mixture of both a selection of kernel modules and building them in 
 monolithically (you probably will ALWAYS need MASQ functionality ready to go).
</para>

<ItemizedList>
 <listitem>
  <para>
   Side Note:  It is assumed that you will also configure the kernel to use your 
   other installed hardware such as USB printers, Ethernet network interfaces, 
   SCSI and IDE HD controllers, etc. as well.  Please refer to the 
   <ULink URL="http://www.tldp.org/HOWTO/Kernel-HOWTO/index.html">
   Linux Kernel HOWTO</ULink> and the kernel source's "<Literal>README</Literal>" 
   file and "<Literal>Documentation/</Literal>" directory for detailed help on 
   compiling a kernel.
  </para>
 </listitem>
</ItemizedList>

<para>
You will need to answer either <Emphasis role="strong">YES, NO, or MODULE
</Emphasis> to the following program.  Not all options will be available 
without the proper kernel patches described later in this HOWTO.  This
shouldn't be an issue as most 3rd party patches are only needed for a very 
select group of users.
</para>

<para>
Run the following commands to configure your kernel:
</para>

<para>

 <Itemizedlist>

  <listitem>
   <para>
    <literal>cd /usr/src/kernel/linux</literal>
   </para>
  </listitem

  <listitem>
   <para>
    <literal>make menuconfig</literal>
   </para>
  </listitem>

 </Itemizedlist>
</para>


<para>
Please note the following kernel prompts reflect a 2.4.14 kernel (with some of
the optional Patch-O-Matic additions.  Please read the following carefully for
recommendations:
</para>

<para>
<Screen>
[ Code maturity level options ]

  * Prompt for development and/or incomplete code/drivers (CONFIG_EXPERIMENTAL) [Y/n/?]
    - YES: though not required for IP MASQ, this option allows the kernel to create 
           the MASQ modules and enable the option for port forwarding

  * Enable loadable module support (CONFIG_MODULES) [Y/n/?]
    - YES: allows you to load kernel IP MASQ modules

  * Set version information on all module symbols (CONFIG_MODVERSIONS) [Y/n/?]
    - YES: allows newer kernels to load older modules if possible

  * Kernel module loader (CONFIG_KMOD) [Y/n/?] 
    - OPTIONAL: Recommended : allows the kernel to load various kernel modules as it needs them

  == Non-MASQ options skipped
  ==   (CPU type, memory, SMP, FPU, specific stuff)


[ General setup ]

  * Networking support (CONFIG_NET) [Y/n/?]
    - YES: Enables the network subsystem

  == Non-MASQ options skipped 
  ==   (specific hardware, PCI, kernel binaries, PCMCIA, etc.)


  * Sysctl support (CONFIG_SYSCTL) [Y/n/?] 
    - YES:  Enables the ability to enable disable options such as forwarding,
      dynamic IPs, etc. via the /proc interface


[ Block devices ]

  == Non-MASQ options skipped
  ==   (kernel binaries, power management, PnP, RAID, etc.)

    == Don't forget to compile in support for hardware that you might need:
    ==   IDE controllers, HDs, CDROMs, etc.

[ Networking options ]

  * Packet socket (CONFIG_PACKET) [Y/m/n/?]
    - YES: Though this is OPTIONAL, this recommended feature will allow you 
           to use TCPDUMP to debug any problems with IP MASQ

  * Packet socket: mmapped IO (CONFIG_PACKET_MMAP) [N/y/?] y
    - YES: Speed up the packet protocol

  * Kernel/User netlink socket (CONFIG_NETLINK) [Y/n/?] 
    - OPTIONAL:  Recommended : this feature will allow the logging of 
           advanced firewall issues such as routing messages, etc

  * Routing messages (CONFIG_RTNETLINK) [N/y/?] (NEW) y
    - OPTIONAL: Allows for support of advanced kernel routing messages
                if you enabled the CONFIG_NETLINK option

  * Netlink device emulation (CONFIG_NETLINK_DEV) [N/y/m/?] (NEW)  
    - NO:  This option does not have anything to do with packet firewall 
           logging

  * Network packet filtering (replaces ipchains) (CONFIG_NETFILTER) [N/y/?] y
    - YES: Enable this option to let IPTABLES configure the TCP/IP subsection
           of the kernel.  By enabling this, then you can turn on advanced 
           routing mechanisms like IP Masq, packet filtering, etc.

  * Network packet filtering debugging (CONFIG_NETFILTER_DEBUG) [N/y/?] (NEW) n
    - NO: Not required for Masquerading functionality though it may help 
          for troubleshooting.  There might be a performance penalty when
          enabling this.

  * Socket Filtering (CONFIG_FILTER) [Y/n/?]
    - OPTIONAL:  Recommended : Though this doesn't have anything do with IPMASQ, 
      if you plan on implimenting a DHCP server on the internal network, you WILL 
      need to enable this option.

  * Unix domain sockets (CONFIG_UNIX) [Y/m/n/?]
    - YES:  This enables the UNIX TCP/IP sockets mechanisms

  * TCP/IP networking (CONFIG_INET) [Y/n/?]
    - YES: Enables the TCP/IP protocol

  * IP: multicasting (CONFIG_IP_MULTICAST) [N/y/?] 
    - OPTIONAL:  You can enable this if you want to be able to receive
                 Multicast traffic.  Please note that your ISP must 
                 support Multicast as well for this all to work at all
                 
  * IP: advanced router (CONFIG_IP_ADVANCED_ROUTER) [Y/n/?]
    - OPTIONAL:  Though there is nothing in this section mandatory for 
                 Masquerade, some specific options might be useful

    == Non-MASQ options skipped 
    ==   ( autoconf, tunneling )

  * IP: multicast routing (CONFIG_IP_MROUTE) [N/y/?] n
    - OPTIONAL:  Though not needed for IPMASQ, enabling this feature will
                 let you route multicast traffic through your Linux box.
                 Please note that this requires that your ISP be multicast
                 enabled as well.

    == Non-MASQ options skipped 
    ==   (ARPd) 

  * IP: TCP Explicit Congestion Notification support (CONFIG_INET_ECN) [N/y/?] n
    - NO: Though enabling this option would be great, there are many Internet
          sites out there that will block this.  Hit the "?" when configuring
          the kernel to learn more about it but it is recommended to say NO for 
          now.

  * IP: TCP syncookie support (disabled per default) (CONFIG_SYN_COOKIES) [Y/n/?]
    - YES: Recommended : for basic TCP/IP network security


[ Networking options --> IP: Netfilter Configuration ]


  * Connection tracking (required for masq/NAT) (CONFIG_IP_NF_CONNTRACK) [N/y/m/?] (NEW) m
    - YES: (Module) This enables the kernel to track various network connections.
           This option is required for Masquerading support as well as to enable 
           Stateful tracking for various filewall mechanisms.  Please note that
           if you compile this directly into the kernel, you cannot enable
           the legacy IPCHAINS or IPFWADM compatibility modules.

  * FTP protocol support (CONFIG_IP_NF_FTP) [M/n/?] (NEW) m
    - YES: (Module) This enables the proper Masquerading of FTP connections if 
           CONFIG_IP_NF_CONNTRACK was enabled above

  * IRC protocol support (CONFIG_IP_NF_IRC) [M/n/?] (NEW) m
    - YES: (Module) This enables the proper Masquerading of IRC connections if 
           CONFIG_IP_NF_CONNTRACK was enabled above

  * Userspace queueing via NETLINK (EXPERIMENTAL) (CONFIG_IP_NF_QUEUE) [N/y/m/?] (NEW) m
    - OPTIONAL: Though this is OPTIONAL, this feature will allow IPTABLES to 
                copy specific packets to UserSpace tools for additional checks

  * IP tables support (required for filtering/masq/NAT) (CONFIG_IP_NF_IPTABLES) [N/y/m/?] (NEW) m
    - YES: (Module) Enables IPTABLES support

  * limit match support (CONFIG_IP_NF_MATCH_LIMIT) [N/y/m/?] (NEW) y
    - OPTIONAL:  (Module) Recommended : Though not required, this option can used to 
                 enable rate limiting of both traffic and loggin messages help slow down denial
                 of service (DoS) attacks.

  * MAC address match support (CONFIG_IP_NF_MATCH_MAC) [N/y/m/?] (NEW) m
    - OPTIONAL:  Though not required, the option can allow you to 
                 filter traffic based upon the SOURCE Ethernet MAC address.

  * netfilter MARK match support (CONFIG_IP_NF_MATCH_MARK) [N/y/m/?] (NEW) y
    - YES: (Module) Recommended : This enables IPTABLES to take action upon marked packets.  
           This mechanism can allow for PORTFW functionality, TOS marking, etc.

  * Multiple port match support (CONFIG_IP_NF_MATCH_MULTIPORT) [N/y/m/?] (NEW) y
    - YES: (Module) Recommended : This enables IPTABLES to accept mutliple SRC/DST port
           ranges (non-contiguous) instead of one port range per IPTABLES 
           statement.

  * TOS match support (CONFIG_IP_NF_MATCH_TOS) [Y/m/n/?] n
    - OPTIONAL:  This allows IPTABLES to match packets based upon their
                 DIFFSERV settings.

  * LENGTH match support (CONFIG_IP_NF_MATCH_LENGTH) [N/m/?] (NEW) n
    - OPTIONAL:  This allows IPTABLES to match packets based upon their
                 packet length.

  * TTL match support (CONFIG_IP_NF_MATCH_TTL) [N/m/?] (NEW) ? n
    - OPTIONAL:  This allows IPTABLES to match packets based upon their
                 TTL settings.

  * tcpmss match support (CONFIG_IP_NF_MATCH_TCPMSS) [N/y/m/?] m
    - OPTIONAL: (Module) Recommended :  This option allows users to examine the MSS value in
                 TCP SYN packets.  This is an advanced knob but can be very valuable in 
                 troubleshooting MTU problems.

  * Connection state match support (CONFIG_IP_NF_MATCH_STATE) [M/n/?]  m
    - YES: (Module) Recommended : This option allows for Stateful tracking of network
            connections.

  * Unclean match support (EXPERIMENTAL) (CONFIG_IP_NF_MATCH_UNCLEAN) [N/y/m/?] y
    - YES: (Module) Recommended :  This option allows for connection tracking on odd packets.
           It cal also help in the detection of possibly malicious packets.
            This can be a valuable tool in tracking hostile people on the network.

  * Owner match support (EXPERIMENTAL) (CONFIG_IP_NF_MATCH_OWNER) [N/y/m/?] n
    - OPTIONAL:  This option allows IPTABLES to match traffic based upon the 
                 user login, group, etc. who created the traffic.

  * Packet filtering (CONFIG_IP_NF_FILTER) [N/y/m/?] ? y
    - YES: (Module) This option allows for the kernel to be able filter traffic at
            the INPUT, FORWARDING, and OUTPUT traffic points.

    * REJECT target support (CONFIG_IP_NF_TARGET_REJECT) [N/y/m/?] (NEW) y
      - YES: (Module) With this option, a packet firewall can send an ICMP Reject packet
            back to the originator when a packet is blocked.

  * MIRROR target support (EXPERIMENTAL) (CONFIG_IP_NF_TARGET_MIRROR) [N/y/m/?] (NEW) n
    - OPTIONAL: This option allows the packet firewall to mirror the exact same 
                network packet back to the originator when it is supposed to be 
                blocked.  This is similar to the REJECT option above but it actually 
                sends the original packet back to the originator.  i.e. a
                hostile user could actually portscan themselves.


  * Full NAT (CONFIG_IP_NF_NAT) [M/n/?] m
    - YES: (Module) This option enables the future menus to enable Masquerading, 
           PORTFWing, Full (1:1) NAT, etc.


  * MASQUERADE target support (CONFIG_IP_NF_TARGET_MASQUERADE) [M/n/?] (NEW) m
    - YES: (Module) This option specifically enables Masquerade into the 
           kernel

  * REDIRECT target support (CONFIG_IP_NF_TARGET_REDIRECT) [N/y/m/?] n
    - OPTIONAL: Not needed for normal MASQ functionality though people who 
                want to do transparent proxy via Squid will want this.  

  * Basic SNMP-ALG support (EXPERIMENTAL) (CONFIG_IP_NF_NAT_SNMP_BASIC) [N/m/?] n
    - OPTIONAL: This enables IPTABLES to properly NAT internal SNMP packets so 
                that machines with duplicate addressing ranges can be properly
                managed.

                
  * Packet mangling (CONFIG_IP_NF_MANGLE) [N/y/m/?] y
    - YES: (Module) This option allows for advanced IPTABLES packet manipulation 
           options.


  * TOS target support (CONFIG_IP_NF_TARGET_TOS) [N/y/m/?] (NEW) n
    - OPTIONAL: Enables the kernel to modify the TOS field in a packet 
           before routing it on

  * MARK target support (CONFIG_IP_NF_TARGET_MARK) [N/y/m/?] (NEW) m
    - OPTIONAL: (Module) Recommended : This enables the kernel to manipulate 
                packets based upon the MARK field.  This can be used for PORTFW 
                as well as many other things.

  * LOG target support (CONFIG_IP_NF_TARGET_LOG) [N/y/m/?]  m
    - YES: (Module)  This allows for the logging of packets before they are accepted,
           denied, rejected, etc.

  * TCPMSS target support (CONFIG_IP_NF_TARGET_TCPMSS) [N/y/m/?] ? m
    - YES: (Module) This option help some people with MTU problems.  Typically,
           most users have to set their Internet connection's MTU to 
           1500 as well as ALL internal machines to 1500.  With this
           option, this whole MTU issue might be finally solved.

  * ipchains (2.2-style) support (CONFIG_IP_NF_COMPAT_IPCHAINS) [N/y/m/?] m
    - OPTIONAL: (Module) Recommended : If you have an existing IPCHAINS ruleset 
           (2.2.x kernels) and enable this option, you can continue to use the 
           IPCHAINS program and the majority of your old ruleset except for the 
           use of any 2.2.x kernel-specific modules.  Please note that if this
           IPCHAINS module is loaded, ALL IPTABLES modules will be non-
           operational.  This is an either/or deal only intended for legacy
           rulesets.

  * ipfwadm (2.0-style) support (CONFIG_IP_NF_COMPAT_IPFWADM) [N/y/m/?] n
    - OPTIONAL: If you have an existing IPFWADM ruleset (2.0.x kernels) and 
           enable this option, you can continue to use the IPFWADM program and 
           the majority of your old ruleset except for the use of any 2.0.x 
           kernel-specific modules.   Please note that if this IPFWADM module 
           is loaded, ALL IPTABLES modules will be non operational.  This is 
           an either/or deal only intended to support legacy rulesets.                 


    == Non-MASQ options skipped
    ==   (IPv6, khttpd, ATM, IPX, AppleTalk, etc.) --

  * Fast switching (read help!) (CONFIG_NET_FASTROUTE) [N/y/?] n
    - NO: This performance optimization is NOT compatible with IP MASQ and/or
          packet filtering


    == Non-MASQ options skipped
    == (QoS, Telephony, IDE, SCSI, 1394FW, I2O, etc)

      == Don't forget to compile in support for hardware that you might need:
      ==   IDE:    HDs, CDROMs, etc.
      ==   SCSI:   HDs, CDROMs, etc.


[ Network device support ]

  * Network device support (CONFIG_NETDEVICES) [Y/n/?]
    - YES: Enables the Linux Network device sublayer 

    == Non-MASQ options skipped
    ==   (Arcnet) 


  * Dummy net driver support (CONFIG_DUMMY) [M/n/y/?] 
    - YES:  Though OPTIONAL, this option can help when debugging problems

    == Non-MASQ options skipped
    == (EQL, etc..)

    == Don't forget to compile in support for hardware that you might need:
    ==   NICs:   eth, tr, etc.
    ==   MODEMs: ppp (ppp async) and/or slip
    ==   WANs:   T1, T3, ISDN, etc.
    ==   ISDN:   for internal ISDN modems


    == Non-MASQ options skipped
    ==   (Amateur Radio, IrDA, ISDN, USB, etc.)


[ Character devices ]

    == Don't forget to compile in serial port support if you are a modem user
    == Don't forget to compile in mouse support

    == Non-MASQ options skipped
    ==   (I2C, Watchdog cards, Ftape, Video for Linux, etc. )


[ File systems ]

    == Non-MASQ options skipped
    ==   (Quota, ISO9660, NTFS, etc )

  * /proc filesystem support (CONFIG_PROC_FS) [Y/n/?]
    - YES:  Required to dynamically configure the Linux forwarding 
            and NATing systems


    == Non-MASQ options skipped
    ==   (Console drivers, Sound, USB, Kernel Hacking) 

</screen>

So go ahead and select "exit" and you should be prompted to save your config.
</para>

<para>
NOTE: These are just the kernel components you need for IP Masquerade networking
support.  You will need to select whatever other options needed for your 
specific setup.  If you want more information on what each one of these kernel 
modules does, please see the FAQ section of this HOWTO for details.

<!-- Blah . add FAQ URL -->

</para>

<ItemizedList>
<listitem>
<para>
Now compile the kernel (make dep; make clean; make bzImage; make modules; 
make modules_install) , etc.  Again, it is beyond the scope of this HOWTO
if you have problems compiling your kernel.  Please see 
<XRef LinkEnd="kernel-2.4.x-Requirements"> for URLs to the KERNEL howto, etc.
</para>
</listitem>

<listitem>
<para>
You will then have move over the kernel binary, update your bootloader 
(LILO, Grub, etc.), and reboot.  If you have questions about kernel compiling, 
I highly recommend to consult some of the URLs mentioned above in this section.
</para>
</listitem>

</ItemizedList>
</Sect2>


<Sect2 id=ipmasq-compiling3.1.2>
<Title>Compiling Linux 2.2.x Kernels</Title>

<para>
<Emphasis role="strong">Please see <XRef LinkEnd="kernel-2.2.x-Requirements"> for 
any required software, patches, etc.</Emphasis>
</para>

<ItemizedList>

 <listitem>
  <para>
   First of all, you need the kernel source for 2.2.x (preferably the latest 
   kernel version)
  </para>

  <Itemizedlist>
   <listitem>
    <para>
    NOTE #1:    --- UPDATE YOUR KERNEL ---

    Linux 2.2.x kernels less than version 2.2.20 contain several different 
    <ULink URL="http://www.linux.org.uk/VERSION/">security 
    vulnerabilities</Ulink> (some were MASQ specific).  Kernels less than
    2.2.20 have a few local vulnerabilities. Kernel versions less 
    than 2.2.16 have a TCP root exploit vulnerability and versions less than 
    2.2.11 have a IPCHAINS fragmentation bug.  Because of these issues, users 
    running a firewall with strong IPCHAINS rulesets are open to possible 
    instrusion.  Please upgrade your kernel to a fixed version.
    </para>
   </listitem>

   <listitem>
    <para>
     NOTE #2: As the 2.2.x train progressed, the compile-time options keep on 
     changing.  As of this version, this section reflects the settings for  a 
     2.2.20 kernel.
    </para>
    <para>
     If you are running either a newer or older kernel version, the dialogs 
     will look different.  It is recommended that you update to the newest 
     kernel for added capability and stability of the system.
    </para>
   </listitem>
  </Itemizedlist>

 </listitem>

 <listitem>
  <para>
   If this is your first time compiling the kernel, don't be scared. In fact, 
   it's rather easy and it's covered in several URLs found in 
   <XRef LinkEnd="kernel-2.2.x-Requirements">.  Please note that the instructions
   included here is just one way to do build a kernel.  Please see the Kernel
   HOWTO for full details.
  </para>

  <para>
   <Emphasis role="strong">NOTE: </Emphasis>Please notice that it isn't 
   recommended to put the new kernel sources into /usr/src/linux.  You 
   should leave the original kernel sources that came with your Linux 
   distribution in /usr/src/linux.  For more details on this 
   topic, please read the "README" file in the top level directory of 
   your kernel sources.
  </para>
 </listitem>

 <listitem>
  <para>
   For this HOWTO example, create a directory called <Literal>/usr/src/kernel</Literal>.  
   Next, "cd" into this directory and download the newest 2.2.x kernel sources
   into it.  Once downloaded, issue the following command (if the file ends in a .tar.gz): 
   <Literal>tar xvzf linux-2.2.x.tar.gz</Literal> or (if the file ends in a 
   .tar.bzip2): <Literal>tar xyvf linux-2.2.x.tar.bz2</Literal>.  Please 
   substitute the "x" in the 2.2.x filename with the Linux 2.2 kernel version you 
   downloaded.  
  </para>
  <para>
   NOTE:  Some Linux distributions use the "I" option instead of the "y" option to 
   decompress bzip2 archives.
  </para>
  <para>
   Once uncompressed, I recommend that you rename the directory from "linux" to
   "linux-2.2.x" for clarity.  To do this, run the command <Literal>mv linux
   linux-2.2.x</Literal>.  Next, make sure there is a directory or symbolic 
   link pointing to <Literal>/usr/src/kernel/linux</Literal> ie.  run the 
   command: <Literal>ln -s /usr/src/kernel/linux-2.2.x /usr/src/kernel/linux</Literal>o
   again subsituting the "x" for your proper kernel version.
  </para>
 </listitem>

 <listitem>
  <para>
   Apply any appropriate or optional patches to the kernel source code.  By
   default, stock Linux kernels do not require any specific patching in order 
   for the system to work.  Features like PPTP/IPSEC masqurading are already
   built-in in the newest kernels but other tools like Xwindows forwarders 
   are optional.  Please refer to <XRef LinkEnd="kernel-2.2.x-Requirements"> for 
   URLs and the <ULink URL="http://ipmasq.webhop.net/">IP Masquerade Resources</ULink> 
   for up-to-date information and patch URLs.
  </para>
 </listitem>

 <listitem>
  <para>
   Now that the kernel is patched up (if required), here are the MINIMUM kernel
   configuration options required to enable IP Masquerade functionality.  Please
   understand that this HOWTO illustrates just ONE way to compile a kernel. The
   main difference from this method vs. a different one is some people wish to
   compile things either as modules OR monolithically right into the kernel.
   Basically, compiling things as modules gives you added flexibility to what is
   or isn't installed into the kernel (reduces unneeded memory use and allow for
   drop-in upgrades [no need to reboot]) BUT they add more complexity to your
   configuration. On the flip side, compiling things directly into the kernel
   makes things simpler BUT you loose a level of flexibility. The following
   example is a mixture of both built-in AND modules.
  </para>

  <para>
   <Emphasis role="strong">Side Note:</Emphasis>
   It is assumed that you will also configure the kernel to use your 
   other installed hardware such as network interfaces, optional SCSI controllers,
   etc. as well.  Please refer to the 
   <ULink URL="http://www.tldp.org/HOWTO/Kernel-HOWTO/index.html">
   Linux Kernel 
   HOWTO</ULink> and the kernel source's README file and Documentation/ directory
   for detailed help on compiling a kernel.
  </para>

 </listitem>
</ItemizedList>

<para>
Please note the <Emphasis role="strong">YES or NO ANSWERS</Emphasis> to the 
following.  Not all options will be available without the proper kernel 
patches described later in this HOWTO.
</para>

<para>
Run the following commands to configure your kernel:

<Itemizedlist>
 <listitem>
  <para>
   <literal>cd /usr/src/kernel/linux</literal>
  </para>
  </listitem

  <listitem>
  <para>
   <literal>make menuconfig</literal>
  </para>
 </listitem>
</Itemizedlist>

</para>

<para>
The following kernel prompts reflect a 2.2.20 kernel: 
</para>

<para>
<Screen>
[ Code maturity level options ]

  * Prompt for development and/or incomplete code/drivers (CONFIG_EXPERIMENTAL) [Y/n/?]
    - YES: though not entirely required for IP MASQ, this option allows the kernel 
           to create possible additional MASQ modules such as PORTFW, etc.

  == Non-MASQ options skipped
  ==   (CPU, memory, MTRR, SMP, etc.)


[ Loadable module support ]

  * Enable loadable module support (CONFIG_MODULES) [Y/n/?] y
    - YES: allows you to load kernel IP MASQ modules

  * Set version information on all symbols for modules (CONFIG_MODVERSIONS) [N/y/?] y
    - YES: allows newer kernels to load older modules if possible

  * Kernel module loader (CONFIG_KMOD) [Y/n/?] y
    - OPTIONAL: Recommended : allows the kernel to load various kernel modules as 
         it needs them


[ General setup ]

  * Networking support (CONFIG_NET) [Y/n/?]
    - YES: This enables the network subsystem

  == Non-MASQ options skipped
  ==   (PCI, kernel binaries, specific hardware options, etc.)


  * Sysctl support (CONFIG_SYSCTL) [Y/n/?] 
    - YES:  Enables the ability to enable disable options such as forwarding,
      dynamic IPs, etc. via the /proc interface


[ Block devices ]

  == Non-MASQ options skipped
  ==   (kernel binaries, power management, PnP, IDE, SCSI, etc.)

    == Don't forget to compile in support for hardware that you might need:
    ==   IDE controllers, HDs, CDROMs, etc.


[ Networking options ]


  * Packet socket (CONFIG_PACKET) [Y/m/n/?] y
    - YES: Though this is OPTIONAL, this recommended feature will allow you 
           to use TCPDUMP to debug any problems with IP MASQ

  * Kernel/User netlink socket (CONFIG_NETLINK) [Y/n/?] y
    - OPTIONAL: Recommended :  This feature will allow the logging of 
           advanced firewall issues such as routing messages, etc

  * Routing messages (CONFIG_RTNETLINK) [Y/n/?] y
    - OPTIONAL: If you enabled the CONFIG_NETLINK option above, this option 
           will send routing messages and other information to SYSLOG.

  * Netlink device emulation (CONFIG_NETLINK_DEV) [N/y/m/?] (NEW) n
    - NO:  This option does not have anything to do with packet firewall 
           logging

  * Network firewalls (CONFIG_FIREWALL) [Y/n/?] y
    - YES: Enables the kernel to be comfigured by the IPCHAINS firewall tool

  * Socket Filtering (CONFIG_FILTER) [Y/n/?] y
    - OPTIONAL:  Though this doesn't have anything do with IPMASQ, if you 
         plan on implimenting a DHCP server on the internal network, you 
         WILL need this option.

  * Unix domain sockets (CONFIG_UNIX) [Y/m/n/?] y
    - YES:  This enables the UNIX TCP/IP sockets mechanisms

  * TCP/IP networking (CONFIG_INET) [Y/n/?] y
    - YES: Enables the TCP/IP protocol

  * IP: multicasting (CONFIG_IP_MULTICAST) [N/y/?] y
    - OPTIONAL:  You can enable this if you want to be able to receive
                 Multicast traffic.  Please note that your ISP must 
                 support Multicast as well for this all to work
                 
  * IP: advanced router (CONFIG_IP_ADVANCED_ROUTER) [Y/n/?] n
    - OPTIONAL:  Though there is nothing in this section mandatory for 
                 Masquerade, some specific options might be useful

  * IP: kernel level autoconfiguration (CONFIG_IP_PNP) [N/y/?] ?
    - NO:  Not needed for normal MASQ functionality

  * IP: firewalling (CONFIG_IP_FIREWALL) [Y/n/?] y
    - YES: This enables the kernel to support packet filtering, NAT, etc.

  * IP: firewall packet netlink device (CONFIG_IP_FIREWALL_NETLINK) [Y/n/?] n
    - OPTIONAL: Though this is OPTIONAL, this feature will allow IPCHAINS to 
                copy some packets to UserSpace tools for additional checks

  * IP: transparent proxy support (CONFIG_IP_TRANSPARENT_PROXY) [N/y/?] n
    - OPTIONAL:  Not needed for normal MASQ functionality though people who 
           want to do transparent proxy via Squid will want this.  Please note
           that there is a PERFORMANCE PENALTY enabling this feature.

  * IP: masquerading (CONFIG_IP_MASQUERADE) [Y/n/?] y
    - YES: Enable IP Masquerade to re-address specific internal to external 
           TCP/IP packets

  * IP: ICMP masquerading (CONFIG_IP_MASQUERADE_ICMP) [Y/n/?] y
    - YES: Enable support for masquerading ICMP ping packets (ICMP error 
           codes will be MASQed regardless).  This is an important feature 
           for troubleshooting connections.

  * IP: masquerading special modules support (CONFIG_IP_MASQUERADE_MOD) [Y/n/?] y
    - YES: Though OPTIONAL, this enables the option to later enable other
           modules like the PORTFW to give external computers a directly 
           connection to specified internal MASQed machines.

  * IP: ipautofw masq support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_IPAUTOFW) [N/y/m/?] n
    - NO:  NOT recommended : IPautofw is a legacy method of port forwarding.  It 
           is mainly old code and has been found to have some issues.  

  * IP: ipportfw masq support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_IPPORTFW) [Y/m/n/?] y
    - OPTIONAL: Recommended : This enables PORTFW which allows external computers 
           on the Internet to directly communicate to specified internal MASQed 
           machines.  This feature is typically used to allow access to internal 
           SMTP, TELNET, and WWW servers.  Please note that FTP port forwarding 
           needs an additional patch, as described in the FAQ section of the MASQ 
           HOWTO.  Please see the this FAQ section in the HOWTO for additional 
           information.

  * IP: ip fwmark masq-forwarding support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_MFW) [Y/m/n/?] y
    - OPTIONAL:  This is a NEW method of performing PORTFW-like functionality which is
           similar to how the new 2.4.x kernels do things.  With this option, IPCHAINS 
           can mark packets that should have additional work done upon it.  Using a 
           UserSpace tool, much like IPMASQADM or IPPORFW, IPCHAINS would then 
           do things like re-address the packets, change their TOS value, etc. 
           Currently, this code is less tested than PORTFW but it looks promising.  
           For now, this HOWTO recommends to use IPMASQADM and IPPORTFW.  If you 
           have specific thoughts or comments on MFW, please email dranch.

  * IP: optimize as a router not host (CONFIG_IP_ROUTER) [Y/n/?] y
    - YES:  This optimizes the kernel for the network subsystem, though it 
            isn't well known if this makes a siginificant performance difference 
            or not.

  == Non-MASQ options skipped 
  ==   ( autoconf, tunneling, GRE )


  * IP: multicast routing (CONFIG_IP_MROUTE) [N/y/?] n
    - OPTIONAL:  Though not needed for IPMASQ, enabling this feature will
                 let you route multicast traffic through your Linux box.
                 Please note that this requires that your ISP be multicast
                 enabled as well.


    == Non-MASQ options skipped 
    ==  (Aliasing, ARPd) 

  * IP: TCP syncookie support (disabled per default) (CONFIG_SYN_COOKIES) [Y/n/?]
    - YES: Recommended : for basic TCP/IP network security

  * IP: GRE tunnels over IP (CONFIG_NET_IPGRE) [N/y/m/?]
    - NO:   This OPTIONAL selection is to enable PPTP and GRE tunnels through 
            the IP MASQ box

    == Non-MASQ options skipped
    ==   (aliasing, ARPd) 


  * IP: TCP syncookie support (not enabled per default) (CONFIG_SYN_COOKIES) [Y/n/?]
    - YES: HIGHLY recommended for basic TCP/IP network security

    == Non-MASQ options skipped
    ==  (RARP)


  * IP: Allow large windows (not recommended if <16Mb of memory) * (CONFIG_SKB_LARGE) [Y/n/?]
    - YES:  This is recommended to optimize Linux's TCP window 

    == Non-MASQ options skipped
    ==   (IPv6, IPX, WAN router, etc.)

  * Fast switching (read help!) (CONFIG_NET_FASTROUTE) [N/y/?] n
    - NO: This performance optimization is NOT compatible with IP MASQ and/or
          packet filtering


  == Non-MASQ options skipped
  == (Slow CPU, Telephony, SCSI, I2O, etc. )

    == Don't forget to compile in support for hardware that you might need:
    ==   SCSI:   HDs, CDROMs, etc.


[ Network device support ]

  * Network device support (CONFIG_NETDEVICES) [Y/n/?]
    - YES: Enables the Linux Network device sublayer 


  == Non-MASQ options skipped
  ==   (Arcnet) 


  * Dummy net driver support (CONFIG_DUMMY) [M/n/y/?] 
    - YES:  Though OPTIONAL, this option can help when debugging problems


  == Non-MASQ options skipped
  == (EQL, NICs, Wireless, IrDA, ISDN, etc..)

    == Don't forget to compile in support for hardware that you might need:
    ==   NICs:   eth, tr, etc.
    ==   MODEMs: ppp and/or slip
    ==   WANs:   T1, T3, ISDN, etc.
    ==   ISDN:   for internal ISDN modems


 [ Character devices ]

  == Don't forget to compile in serial port support for modem users
  == Don't forget to compile in mouse support


  == Non-MASQ options skipped
  ==   (I2C, Watchdog cards, Ftape, Video for Linux, USB, etc. )


[ File systems ]

  == Non-MASQ options skipped
  ==   (Quota, ISO9660, NTFS, etc )


  * /proc filesystem support (CONFIG_PROC_FS) [Y/n/?]
    - YES:  Required to dynamically configure the Linux forwarding 
            and NATing systems


  == Non-MASQ options skipped
  ==   (network fs, NLS, video section, sound, kernel hacking)
</Screen>

So go ahead and "exit" and you should be prompted to save your config.

</para>

<para>
NOTE: These are just the components you need for IP Masquerade.  You will need 
to select whatever other options needed for your specific setup.  
</para>

<ItemizedList>

 <listitem>
  <para>
   Now compile the kernel (make dep; make clean; make bzImage; make modules; 
   make modules_install) , etc.  Again, it is beyond the scope of this HOWTO
   if you have problems compiling your kernel.  Please see 
   <XRef LinkEnd="kernel-2.2.x-Requirements"> for URLs to the KERNEL howto, etc.
  </para>
 </listitem>

 <listitem>
  <para>
   You will then have move over the kernel binary, update your bootloader 
   (LILO, Grub, etc.), and reboot.  If you have questions about kernel compiling, 
   I highly recommend to consult some of the URLs above in this section.
  </para>
 </listitem>


</ItemizedList>
</Sect2>

<Sect2 id="ipmasq-compiling3.1.3">
<Title>Compiling Linux 2.0.x Kernels</Title>

<para>
<Emphasis role="strong">Please see <XRef LinkEnd="kernel-2.0.x-Requirements"> for any 
required software, patches, etc.</Emphasis>
</para>

<ItemizedList>
 <listitem>
  <para>
   First of all, you need the kernel source for 2.0.x (preferably the latest 
   kernel version)

  <Itemizedlist>
   <listitem>
    <para>
     As the 2.0.x train progress, the compile-time options keep on changing.
     As of this version, this section reflects the settings for a 2.0.39 
     kernel.   
    </para>
   </listitem>
  </Itemizedlist>

  </para>
 </listitem>

 <listitem>
  <para>
   If this is your first time compiling the kernel, don't be scared. In fact, 
   it's rather easy and it's covered in several URLs found in 
   <XRef LinkEnd="kernel-2.0.x-Requirements">.  Please note that the instructions
   included here is just one way to do build a kernel.  Please see the Kernel
   HOWTO for full details.
  </para>

  <para>
   <Emphasis role="strong">NOTE: </Emphasis>Please notice that it isn't 
   recommended to put the new kernel sources into /usr/src/linux.  You 
   should leave the original kernel sources that came with your Linux 
   distribution in /usr/src/linux.  For more details on this 
   topic, please read the "README" file in the top level directory of 
   your kernel sources.
  </para>
 </listitem>

 <listitem>
  <para>
   For this HOWTO example, create a directory called <Literal>/usr/src/kernel</Literal>.  
   Next, "cd" into this directory and download the newest 2.0.x kernel sources
   into it.  Once downloaded, issue the following command: 
   <Literal>tar xvzf linux-2.0.x.tar.gz</Literal> .  Please substitute the "x" 
   in the 2.0.x filename with the Linux 2.0 kernel version you downloaded.  
  </para>
  <para>
   Once uncompressed, I recommend that you rename the directory from "linux" to
   "linux-2.0.x" for clarity.  To do this, run the command <Literal>mv linux
   linux-2.0.x</Literal>.  Next, make sure there is a directory or symbolic 
   link pointing to <Literal>/usr/src/kernel/linux</Literal> ie.  run the 
   command: <Literal>ln -s /usr/src/kernel/linux-2.0.x /usr/src/kernel/linux</Literal>o
   again subsituting the "x" for your proper kernel version.
  </para>
 </listitem>

 <listitem>
  <para>
   Apply any appropriate or optional patches to the kernel source code.  By
   default, stock Linux kernels do not require any specific patching in order 
   for the system to work.  Features like IPPORTFW, PPTP, and Xwindows 
   forwarders are optional but very useful.  Please refer to 
   <XRef LinkEnd="kernel-2.0.x-Requirements"> for URLs and the 
   <ULink URL="http://ipmasq.webhop.net/">IP Masquerade Resources</ULink> 
   for up-to-date information and patch URLs.
  </para>
 </listitem>

 <listitem>
  <para>
   Now that the kernel is patched up (if required), here are the MINIMUM kernel
   configuration options required to enable IP Masquerade functionality.  Please
   understand that this HOWTO illustrates just ONE way to compile a kernel. The
   main difference from this method vs. a different one is some people wish to
   compile things either as modules OR monolithically right into the kernel.
   Basically, compiling things as modules gives you added flexibility to what is
   or isn't installed into the kernel (reduces unneeded memory use and allow for
   drop-in upgrades [no need to reboot]) BUT they add more complexity to your
   configuration. On the flip side, compiling things directly into the kernel
   makes things simpler BUT you loose a level of flexibility. The following
   example is a mixture of both built-in AND modules.
  </para>

  <para>
   <Emphasis role="strong">Side Note:</Emphasis>
   It is assumed that you will also configure the kernel to use your 
   other installed hardware such as network interfaces, optional SCSI controllers,
   etc. as well.  Please refer to the 
   <ULink URL="http://www.tldp.org/HOWTO/Kernel-HOWTO/index.html">
   Linux Kernel 
   HOWTO</ULink> and the kernel source's "<Literal>README</Literal>" file and 
   "<Literal>Documentation/</Literal>" directory for detailed help on compiling a kernel.
  </para>

 </listitem>
</Itemizedlist>




<para> 
Please note the <Emphasis role="strong">YES or NO ANSWERS</Emphasis> to the 
following options.  Not all options will be available without the proper 
kernel patches described later in this HOWTO:
</para>
<para>
Run the following commands to configure your kernel:

<Itemizedlist>
 <listitem>
  <para>
   <literal>cd /usr/src/kernel/linux</literal>
  </para>
  </listitem

  <listitem>
  <para>
   <literal>make menuconfig</literal>
  </para>
 </listitem>
</Itemizedlist>
</para>


<para>
The following kernel prompts reflect a 2.0.39 kernel: 
</para>

<para>
<Screen>
[ Code maturity level options ]

  * Prompt for development and/or incomplete code/drivers (CONFIG_EXPERIMENTAL) [Y/n/?] 
    - YES: this will allow you to later select the IP Masquerade feature code 


[ Loadable module support ]

  * Enable loadable module support (CONFIG_MODULES) [Y/n/?] y
    - YES: allows you to load kernel IP MASQ modules

  * Set version information on all module symbols (CONFIG_MODVERSIONS) [N/y/?] y
    - YES: allows newer kernels to load older modules if possible

  * Kernel daemon support (e.g. autoload of modules) (CONFIG_KERNELD) [N/y/?] y
    - OPTIONAL: Recommended : allows the kernel to load various kernel modules as 
         it needs them


[ General setup ]

  == Non-MASQ options skipped
  ==   (FPU, memory) 

  * Networking support (CONFIG_NET) [Y/n/?] y
    - YES: Enables the network subsystem

  == Non-MASQ options skipped
  ==   (memory, PCI, binary format, APM, etc.) 

    == Don't forget to compile in support for hardware that you might need:
    ==   IDE controllers, HDs, CDROMs, etc.


[ Networking options ]

  * Network firewalls (CONFIG_FIREWALL) [Y/n/?] y
    - YES: Enables the IPFWADM firewall tool

  == Non-MASQ options skipped
  ==   (Aliasing)


  * TCP/IP networking (CONFIG_INET) [Y/n/?] y
    - YES: Enables the TCP/IP protocol

  * IP: forwarding/gatewaying (CONFIG_IP_FORWARD) [N/y/?] y
    - YES: Enables Linux network packet forwarding and routing 
           - Controlled by IPFWADM

  * IP: multicasting (CONFIG_IP_MULTICAST) [N/y/?] y
    - OPTIONAL:  You can enable this if you want to be able to receive
                 Multicast traffic.  Please note that your ISP must 
                 support Multicast as well for this all to work
                 
  * IP: syn cookies (CONFIG_SYN_COOKIES) [Y/n/?] y
    - YES: HIGHLY recommended for basic network security

  * IP: firewalling (CONFIG_IP_FIREWALL) [Y/n/?] y
    - YES: Enable the packet firewall features

  * IP: firewall packet logging (CONFIG_IP_FIREWALL_VERBOSE) [Y/n/?] y
    - YES: Allows the kernel to report back on various packets traversing
           the firewall.

  * IP: masquerading (CONFIG_IP_MASQUERADE [Y/n/?] y
    - YES: Enable the kernel to perform IP MASQ NAT functionality

  * IP: ipautofw masquerade support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_IPAUTOFW) [Y/n/?] n
    - NO:  NOT Recommended : IPautofw is a legacy method of TCP/IP port forwarding.  
           Though IPautofw works, IPPORTFW is a better choice.


  * IP: ipportfw masq support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_IPPORTFW) [Y/n/?] y
    - YES: This option is ONLY AVAILABLE VIA A PATCH for the 2.0.x kernels.  
           With this option, external computers on the Internet can directly 
           communicate to specified internal MASQed machines.  This feature is 
           typically used to access internal SMTP, TELNET, and WWW servers.  
           FTP port forwarding sometimes might require an additional patch as 
           described in the FAQ section.  Additional information on port 
           forwarding is available in the Forwards section of this HOWTO.


  * IP: MS PPTP masq support (EXPERIMENTAL) (CONFIG_IP_MASQUERADE_PPTP) [N/y/?] (NEW) n
    - OPTIONAL: Enabling this feature will allow internal MASQ clients to
          properly connect to PPTP servers on the Internet.

  * IP: MS PPTP Call ID masq support (CONFIG_IP_MASQUERADE_PPTP_MULTICLIENT) [N/y/?] (NEW) n
    - OPTIONAL:  If you enabled the CONFIG_IP_MASQUERADE_PPTP above, this
          option will allow for multiple internal PPTP clients behind the MASQ 
          server to communicate to the same PPTP server.

  * IP: MS PPTP masq debugging (DEBUG_IP_MASQUERADE_PPTP) [N/y/?] n
    - OPTIONAL:  NOT recommended : This is not required for IP MASQ or MASQing PPTP 
           connections unless you need additional troubleshooting help.  If enabled, 
           this can fill up your logs quickly.

  * IP: MS PPTP masq verbose debugging (DEBUG_IP_MASQUERADE_PPTP_VERBOSE) [N/y/?] (NEW) n
    - OPTIONAL: NOT Recommended : If you enabled the DEBUG_IP_MASQUERADE_PPTP
           option above, this will make the logging even more verbose.

  * IP: IPSEC ESP & ISAKMP masq support (EXPERIMENTAL) * (CONFIG_IP_MASQUERADE_IPSEC) [N/y/?] m
    - OPTIONAL: This option allows for some forms of IPSEC tunnels to be
           masquraded

  * IP: IPSEC masq table lifetime (minutes) (CONFIG_IP_MASQUERADE_IPSEC_EXPIRE) * [30] (NEW) 
    - OPTIONAL: This feature allows to change the MASQ table timeouts so that
      idle IPSEC tunnels won't be prematurely disconnected.

  * IP: Disable inbound ESP destination guessing * (CONFIG_IP_MASQUERADE_IPSEC_NOGUESS) [N/y/?] n
    - OPTIONAL: This feature allows the kernel to guess where the fully encrypted IPSEC VPN 
           might be going and add it to the MASQ table.

  * IP: IPSEC masq debugging (DEBUG_IP_MASQUERADE_IPSEC) [N/y/?] ? n
    - OPTIONAL:  NOT recommended : This is not required for IP MASQ or MASQing IPSEC 
           connections unless you need additional troubleshooting help.  If enabled, 
           this can fill up your logs quickly.

  * IP: IPSEC masq verbose debugging (DEBUG_IP_MASQUERADE_IPSEC_VERBOSE) [N/y/?] (NEW) n
    - OPTIONAL: NOT Recommended : If you enabled the DEBUG_IP_MASQUERADE_IPSEC
           option above, this will make the logging even more verbose.


  * IP: ICMP masquerading (CONFIG_IP_MASQUERADE_ICMP) [Y/n/?]
    - YES: Enable support for masquerading ICMP packets. Though thought of as 
           optional, many programs will NOT function properly with out ICMP 
           support.

  * IP: transparent proxy support (EXPERIMENTAL) (CONFIG_IP_TRANSPARENT_PROXY) [N/y/?] n
    - OPTIONAL:  Not needed for normal MASQ functionality though people who 
           want to do transparent proxy via Squid will want this.  Please note
           that there is a PERFORMANCE PENALTY enabling this feature.

  * IP: loose UDP port managing (EXPERIMENTAL) (CONFIG_IP_MASQ_LOOSE_UDP) [Y/n/?] 
    - YES: This option is ONLY AVAILABLE VIA A PATCH for the 2.0.x kernels.
           With this option, internally masqueraded computers can play 
           NAT-friendly games over the Internet.  Explicit details are given 
           in the FAQ section of this HOWTO.

  * IP: always defragment (CONFIG_IP_ALWAYS_DEFRAG) [Y/n/?]
    - YES:  This feature optimizes IP MASQ connections

  == Non-MASQ options skipped
  ==   (Accounting)


  * IP: optimize as router not host (CONFIG_IP_ROUTER) [Y/n/?] 
    - YES:  This optimizes the kernel for the network subsystem 

  == Non-MASQ options skipped
  ==   (Tunneling, Mcast routing, RARP, PMTU, etc.)


  * IP: Drop source routed frames (CONFIG_IP_NOSR) [Y/n/?]
    - YES: HIGHLY recommended for basic network security

  == Non-MASQ options skipped
  ==   (IPX, Bridging, SCSI, etc.)

    == Don't forget to compile in support for hardware that you might need:
    ==   SCSI controllers, HDs, CDROMs, etc.


[ Network device support ]

  * Network device support (CONFIG_NETDEVICES) [Y/n/?]
    - YES: Enables the Linux Network device sublayer 


  == Non-MASQ options skipped
  ==   (Dummy, EQL, PPP, SLIP, NICs, Wireless, etc.) 

    == Don't forget to compile in support for hardware that you might need:
    ==   NICs:   eth, tr, etc.
    ==   MODEMs: ppp and/or slip
    ==   WANs:   T1, T3, ISDN, etc.
    ==   ISDN:   for internal ISDN modems


[ File systems ]

  == Non-MASQ options skipped
  ==   (Quota, ISO9660, Codepages, NTFS, etc )


  * /proc filesystem support (CONFIG_PROC_FS) [Y/n/?]
    - YES:  Required to dynamically configure the Linux forwarding 
            and NATing systems
  

 [ Character devices ]

  == Non-MASQ options skipped
  ==   (multi-port serial, parallel, mice, Ftape, Sound, etc. )

    == Don't forget to compile in serial port support for modem users
    == Don't forget to compile in mouse support


</Screen>
</para>

<para>
So go ahead and "exit" and you should be prompted to save your config. 
</para>

<para>
NOTE: These are only components for IP Masquerade functionality. You may need 
to also select additional options to match your specific network and hardware setup.  
</para>

<ItemizedList>
 <listitem>
  <para>
   Now compile the kernel (make dep; make clean; make bzImage; make modules; 
   make modules_install) , etc.  Again, it is beyond the scope of this HOWTO
   if you have problems compiling your kernel.  Please see 
   <XRef LinkEnd="kernel-2.0.x-Requirements"> for URLs to the KERNEL howto, etc.
  </para>
 </listitem>

 <listitem>
  <para>
   You will then have move over the kernel binary, update your bootloader 
   (LILO, Grub, etc.), and reboot.  If you have questions about kernel compiling, 
   I highly recommend to consult some of the URLs above in this section.
  </para>
 </listitem>


</ItemizedList>
</Sect2>

</Sect1>

<Sect1 id="Addressing-the-LAN">
<Title>Assigning Private Network IP Addresses to the Internal LAN</Title>

<para>
Since all <Emphasis role="strong">INTERNAL MASQed</Emphasis> machines should 
NOT have official Internet assigned addressees, there must be a specific and 
accepted way to allocate addresses to those machines without conflicting with 
anyone else's Internet address. 
</para>

<para>
From the original IP Masquerade FAQ:
</para>

<para>
<ULink URL="http://www.cis.ohio-state.edu/cgi-bin/rfc/INDEX.rfc.html">RFC 
1918</ULink> is the official document on which IP addresses are to be used in 
a non-connected or "private" network.  There are 3 blocks of numbers set aside 
specifically for this purpose.
</para>

<para>
<Screen>
Section 3: Private Address Space

The Internet Assigned Numbers Authority (IANA) has reserved the
following three blocks of the IP address space for private networks:

              10.0.0.0        -   10.255.255.255
              172.16.0.0      -   172.31.255.255
              192.168.0.0     -   192.168.255.255

We will refer to the first block as "24-bit block", the second as "20-bit 
block", and the third as "16-bit" block".  Note that the first block is 
nothing but a single class A network number, while the second block is a set 
of 16 continuous class B network numbers, and the third block is a set of 255 
continuous class C network numbers.
</Screen>
</para>

<para>
For the record, my preference is to use the 192.168.0.0 network with a 
255.255.255.0 Class-C subnet mask and thus this HOWTO reflects this.  Any of 
the above private networks are valid, but just be SURE to use the correct 
subnet-mask.
</para>

<para>
So, if you're using a Class-C network, you should number your TCP/IP enabled 
machines as 192.168.0.1, 192.168.0.2, 192.168.0.3, .., 192.168.0.x 
</para>

<para>
192.168.0.1 is usually set as the internal gateway or Linux MASQ machine which 
reaches the external network.  Please note that 192.168.0.0 and 192.168.0.255 
are the Network and Broadcast address respectively (these addresses are 
RESERVED). Avoid using these addresses on your machines or your network will 
not function properly. 
</para>

</Sect1>

<Sect1 id="firewall-examples">
<Title>Configuring IP Forwarding Policies</Title>

<para>
At this point, you should have your kernel and other required packages 
installed.  All network IP addresses, gateway, and DNS addresses should be 
configured on your Linux MASQ server.  If you don't know how to configure your 
Linux network cards, please consult the HOWTOs listed in either the 2.4.x 
<XRef LinkEnd="kernel-2.4.x-Requirements">, the 2.2.x 
<XRef LinkEnd="kernel-2.2.x-Requirements">, or the 2.0.x 
<XRef LinkEnd="kernel-2.0.x-Requirements">.
</para>

<para>
Now, the only thing left to do is to configure the IP firewalling tools to 
both FORWARD and MASQUERADE the appropriate packets to the correct machine.
</para>

<para>
<Emphasis role="strong">** This section ONLY provides the user with the 
bare minimum firewall ruleset to get IP Masquerading working.  </Emphasis>
</para>
<para>
Once IP MASQ has been successfully tested (as described later in this HOWTO), 
please refer to the Stronger IPTABLES ruleset for 2.4.x kernels in 
<XRef LinkEnd="rc.firewall-iptables-stronger">, the Stronger IPCHAINS ruleset
for 2.2.x kernels in <XRef LinkEnd="rc.firewall-ipchains-stronger">, and
the Stronger IPFWADM ruleset for 2.0.x kernels in 
<XRef LinkEnd="rc.firewall-ipfwadm-stronger">.  Please note that these
stronger firewall rulesets are more of a template than anything else.
For truly secure firewall rulesets, check out the the requirements section
of the HOWTO ( 2.4.x - <XRef LinkEnd="kernel-2.4.x-Requirements">, 2.2.x - 
<XRef LinkEnd="kernel-2.2.x-Requirements">, 2.0.x - 
<XRef LinkEnd="kernel-2.0.x-Requirements"> ).
</para>

<para>
Instead of manually typing one of these files by hand, I recommend to simply 
<ULink
URL="http://www.ecst.csuchico.edu/~dranch/LINUX/ipmasq/examples/">browse
the Example directory</Ulink> or 
<ULink
URL="http://www.ecst.csuchico.edu/~dranch/LINUX/ipmasq/examples/rc.firewall-examples.tar.gz">
download an archive of all of these rc.firewall-* files</Ulink>.
</para>

<Sect2 id="rc.firewall-iptables">
<Title>Configuring IP Masquerade on Linux 2.6.x and 2.4.x Kernels</Title>

<para>
Please note that IPCHAINS is <Emphasis role="strong">no longer the primary 
firewall configuration tool </Emphasis> for the 2.6.x and 2.4.x kernels.  The 
new kernels now use the IPTABLES toolkit though the new 2.4.x kernels CAN 
still run most old IPCHAINS or IPFWADM rulesets via a compatiblity 
module.  It should also be noted that when running in this compatibility mode, 
NO IPTABLES modules can be loaded.  The reason for this is that none of the 
2.2.x IPMASQ modules are compatible with 2.4.x kernels.  For a more detailes 
for these changes, please see the <XRef LinkEnd="ipchains-on-2.4.x"> section.
</para>

<para>
Ok, as mentioned before, the <literal>/etc/rc.d/rc.local-*</literal> script
can be loaded once after every reboot.  The mechanism to load the script varies
between different Linux distros (please see below for some exampels).  The 
rc.firewall-iptables script will load all required IPMASQ modules as well as 
enable the final IPMASQ functionality.  For advanced setups, this same file 
would contain very secure firewall rulesets as well.
</para>

<para>
Anyway, create the file /etc/rc.d/rc.firewall-iptables with the following 
initial SIMPLE ruleset:
</para>


<para>
&lt;rc.firewall-iptables START&gt;
<Screen>
#!/bin/sh
#
# rc.firewall-iptables
FWVER=0.76
#
#               Initial SIMPLE IP Masquerade test for 2.6 / 2.4 kernels
#               using IPTABLES.  
#
#               Once IP Masquerading has been tested, with this simple 
#               ruleset, it is highly recommended to use a stronger 
#               IPTABLES ruleset either given later in this HOWTO or 
#               from another reputable resource.
#
#
#
# Log:
#       0.76 - Added comments on why the default policy is ACCEPT
#       0.75 - Added more kernel modules to the comments section
#       0.74 - the ruleset now uses modprobe vs. insmod
#       0.73 - REJECT is not a legal policy yet; back to DROP
#       0.72 - Changed the default block behavior to REJECT not DROP
#       0.71 - Added clarification that PPPoE users need to use
#              "ppp0" instead of "eth0" for their external interface
#       0.70 - Added commented option for IRC nat module
#            - Added additional use of environment variables 
#            - Added additional formatting
#       0.63 - Added support for the IRC IPTABLES module
#       0.62 - Fixed a typo on the MASQ enable line that used eth0
#              instead of $EXTIF
#       0.61 - Changed the firewall to use variables for the internal
#              and external interfaces.
#       0.60 - 0.50 had a mistake where the ruleset had a rule to DROP
#              all forwarded packets but it didn't have a rule to ACCEPT
#              any packets to be forwarded either
#            - Load the ip_nat_ftp and ip_conntrack_ftp modules by default
#       0.50 - Initial draft
#

echo -e "\n\nLoading simple rc.firewall-iptables version $FWVER..\n"


# The location of the iptables and kernel module programs
#
#   If your Linux distribution came with a copy of iptables, 
#   most likely all the programs will be located in /sbin.  If 
#   you manually compiled iptables, the default location will
#   be in /usr/local/sbin
#
# ** Please use the "whereis iptables" command to figure out 
# ** where your copy is and change the path below to reflect 
# ** your setup
#
#IPTABLES=/sbin/iptables
IPTABLES=/usr/local/sbin/iptables
DEPMOD=/sbin/depmod
MODPROBE=/sbin/modprobe


#Setting the EXTERNAL and INTERNAL interfaces for the network
#
#  Each IP Masquerade network needs to have at least one
#  external and one internal network.  The external network
#  is where the natting will occur and the internal network
#  should preferably be addressed with a RFC1918 private address
#  scheme.
#
#  For this example, "eth0" is external and "eth1" is internal"
#
#
#  NOTE:  If this doesnt EXACTLY fit your configuration, you must 
#         change the EXTIF or INTIF variables above. For example: 
#
#            If you are a PPPoE or analog modem user:
#
#               EXTIF="ppp0" 
#
#
EXTIF="eth0"
INTIF="eth1"
echo "   External Interface:  $EXTIF"
echo "   Internal Interface:  $INTIF"


#======================================================================
#== No editing beyond this line is required for initial MASQ testing ==


echo -en "   loading modules: "

# Need to verify that all modules have all required dependencies
#
echo "  - Verifying that all kernel modules are ok"
$DEPMOD -a

# With the new IPTABLES code, the core MASQ functionality is now either
# modular or compiled into the kernel.  This HOWTO shows ALL IPTABLES
# options as MODULES.  If your kernel is compiled correctly, there is
# NO need to load the kernel modules manually.  
#
#  NOTE: The following items are listed ONLY for informational reasons.
#        There is no reason to manual load these modules unless your
#        kernel is either mis-configured or you intentionally disabled
#        the kernel module autoloader.
#

# Upon the commands of starting up IP Masq on the server, the
# following kernel modules will be automatically loaded:
#
# NOTE:  Only load the IP MASQ modules you need.  All current IP MASQ 
#        modules are shown below but are commented out from loading.
# ===============================================================

echo "----------------------------------------------------------------------"

#Load the main body of the IPTABLES module - "iptable"
#  - Loaded automatically when the "iptables" command is invoked
#
#  - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "ip_tables, "
$MODPROBE ip_tables


#Load the IPTABLES filtering module - "iptable_filter" 
#  - Loaded automatically when filter policies are activated


#Load the stateful connection tracking framework - "ip_conntrack"
#
# The conntrack  module in itself does nothing without other specific 
# conntrack modules being loaded afterwards such as the "ip_conntrack_ftp"
# module
#
#  - This module is loaded automatically when MASQ functionality is 
#    enabled 
#
#  - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "ip_conntrack, "
$MODPROBE ip_conntrack


#Load the FTP tracking mechanism for full FTP tracking
#
# Enabled by default -- insert a "#" on the next line to deactivate
#
echo -en "ip_conntrack_ftp, "
$MODPROBE ip_conntrack_ftp


#Load the IRC tracking mechanism for full IRC tracking
#
# Enabled by default -- insert a "#" on the next line to deactivate
#
echo -en "ip_conntrack_irc, "
$MODPROBE ip_conntrack_irc


#Load the general IPTABLES NAT code - "iptable_nat"
#  - Loaded automatically when MASQ functionality is turned on
# 
#  - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "iptable_nat, "
$MODPROBE iptable_nat


#Loads the FTP NAT functionality into the core IPTABLES code
# Required to support non-PASV FTP.
#
# Enabled by default -- insert a "#" on the next line to deactivate
#
echo -en "ip_nat_ftp,