02.08.2013 Views

Linux IP Masquerade HOWTO - The Linux Documentation Project

Linux IP Masquerade HOWTO - The Linux Documentation Project

Linux IP Masquerade HOWTO - The Linux Documentation Project

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

David A. Ranch<br />

<br />

November 13, 2005<br />

November 13, 2005<br />

This document describes how to enable the <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> feature on a given <strong>Linux</strong> host. <strong>IP</strong><br />

<strong>Masquerade</strong> is a form of Network Address Translation or NAT which NAT allows internally connected<br />

computers that do not have one or more registered Internet <strong>IP</strong> addresses to communicate to the Internet via the<br />

<strong>Linux</strong> server's Internet <strong>IP</strong> address.


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Table of Contents<br />

Chapter 1. Introduction......................................................................................................................................1<br />

1.1. Introduction to <strong>IP</strong> Masquerading or <strong>IP</strong> MASQ.................................................................................1<br />

1.2. Foreword, Feedback & Credits.........................................................................................................1<br />

1.3. Copyright & Disclaimer....................................................................................................................2<br />

Chapter 2. Background Knowledge..................................................................................................................3<br />

2.1. What is <strong>IP</strong> <strong>Masquerade</strong>?...................................................................................................................3<br />

2.2. Current Status...................................................................................................................................3<br />

2.3. Who Can Benefit From <strong>IP</strong> <strong>Masquerade</strong>?..........................................................................................4<br />

2.4. Who Doesn't Need <strong>IP</strong> <strong>Masquerade</strong>?.................................................................................................4<br />

2.5. How does <strong>IP</strong> <strong>Masquerade</strong> Work?.....................................................................................................4<br />

2.6. Requirements for <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.4.x.............................................................................6<br />

2.7. Requirements for <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.2.x.............................................................................9<br />

2.8. Requirements for <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.0.x...........................................................................11<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong>............................................................................................................13<br />

3.1. Compiling a new kernel if needed..................................................................................................13<br />

3.2. Checking your existing kernel for MASQ functionality.................................................................13<br />

3.2.1. Compiling <strong>Linux</strong> 2.4.x Kernels.............................................................................................15<br />

3.2.2. Compiling <strong>Linux</strong> 2.2.x Kernels.............................................................................................25<br />

3.2.3. Compiling <strong>Linux</strong> 2.0.x Kernels.............................................................................................31<br />

3.3. Assigning Private Network <strong>IP</strong> Addresses to the Internal LAN......................................................35<br />

3.4. Configuring <strong>IP</strong> Forwarding Policies...............................................................................................36<br />

3.4.1. Configuring <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.6.x and 2.4.x Kernels.............................................36<br />

3.4.2. Configuring <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.2.x Kernels............................................................45<br />

3.4.3. Configuring <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.0.x Kernels............................................................53<br />

Chapter 4. Configuring the other internal to−be MASQed machines.........................................................60<br />

4.1. Configuring Microsoft Windows 95 and OSR2.............................................................................60<br />

4.2. Configuring Windows NT..............................................................................................................62<br />

4.3. Configuring Windows for Workgroup 3.11....................................................................................62<br />

4.4. Configuring UNIX Based Systems.................................................................................................63<br />

4.5. Configuring DOS using NCSA Telnet package.............................................................................63<br />

4.6. Configuring MacOS Based System Running MacTCP..................................................................64<br />

4.7. Configuring MacOS Based System Running Open Transport.......................................................64<br />

4.8. Configuring Novell network using DNS........................................................................................65<br />

4.9. Configuring OS/2 Warp..................................................................................................................66<br />

4.10. Configuring OS/400 on a IBM AS/400........................................................................................67<br />

4.11. Configuring Other Systems..........................................................................................................67<br />

Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong>.................................................................................................................68<br />

5.1. Loading up the rc.firewall ruleset...................................................................................................68<br />

5.2. Testing internal MASQ client PC connectivity..............................................................................69<br />

5.3. Testing internal MASQ client to MASQ server connectivity.........................................................69<br />

5.4. Testing internal MASQ server connectivity...................................................................................70<br />

5.5. Testing internal MASQ server to MASQ client connectivity.........................................................70<br />

5.6. Testing External MASQ server Internet connectivity....................................................................71<br />

5.7. Testing internal MASQ client to external MASQ server connectivity...........................................72<br />

i


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Table of Contents<br />

Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong><br />

5.8. Testing external MASQ ICMP forwarding.....................................................................................73<br />

5.9. Testing MASQ functionality without DNS....................................................................................74<br />

5.10. Testing MASQ functionality with DNS resolution......................................................................75<br />

5.11. Testing more MASQ functionality with DNS..............................................................................75<br />

5.12. Any remaining functional, performance, etc. issues....................................................................76<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support..................................................................77<br />

6.1. Problems with <strong>IP</strong> <strong>Masquerade</strong>........................................................................................................77<br />

6.2. Incoming services...........................................................................................................................77<br />

6.3. Supported Client Software and Other Setup Notes.........................................................................77<br />

6.3.1. Network Clients that −Work− with <strong>IP</strong> <strong>Masquerade</strong>..............................................................77<br />

6.3.2. Clients that do not have full support in <strong>IP</strong> MASQ:...............................................................80<br />

6.4. Stronger firewall rulesets to run after initial testing.......................................................................80<br />

6.4.1. Stronger <strong>IP</strong> Firewall (<strong>IP</strong>TABLES) rulesets...........................................................................80<br />

6.4.2. Stronger <strong>IP</strong> Firewall (<strong>IP</strong>CHAINS) rulesets...........................................................................90<br />

6.4.3. Stronger <strong>IP</strong> Firewall (<strong>IP</strong>FWADM) Rulesets.........................................................................97<br />

6.5. <strong>IP</strong> Masquerading multiple internal networks................................................................................103<br />

6.5.1. iptables support for multiple internal lans...........................................................................103<br />

6.5.2. ipchains support for multiple internal lans..........................................................................103<br />

6.5.3. ipfwadm support for multiple internal lans.........................................................................103<br />

6.6. <strong>IP</strong> <strong>Masquerade</strong> and Dial−on−Demand Connections.....................................................................104<br />

6.7. Port Forwarding with <strong>IP</strong>TABLES or external tools like <strong>IP</strong>PORTFW, <strong>IP</strong>MASQADM,<br />

<strong>IP</strong>AUTOFW, REDIR, UDPRED, and other Port Forwarding tools...................................................104<br />

6.7.1. <strong>IP</strong>TABLES−based PORTFWD'ing: Using <strong>IP</strong>TABLES's PREROUTING option for<br />

2.6.x and 2.4.x kernels...........................................................................................................106<br />

6.7.2. <strong>IP</strong>MASQADM−based PORTFWD'ing: Using <strong>IP</strong>MASQADM with 2.2.x kernels............108<br />

6.7.3. <strong>IP</strong>PORTFW−based PORTFWD'ing: Using <strong>IP</strong>PORTFW on 2.0.x kernels.........................110<br />

6.8. CU−SeeMe and <strong>Linux</strong> <strong>IP</strong>−<strong>Masquerade</strong>........................................................................................113<br />

6.9. Mirabilis ICQ................................................................................................................................113<br />

6.10. Gamers: <strong>The</strong> LooseUDP patch...................................................................................................116<br />

Chapter 7. Frequently Asked Questions.......................................................................................................118<br />

7.1. ( Distro ) − What <strong>Linux</strong> Distributions support <strong>IP</strong> Masquerading?...............................................118<br />

7.2. ( Requirements ) − What are the minimum hardware requirements and any limitations for <strong>IP</strong><br />

<strong>Masquerade</strong>? How well does it perform?...........................................................................................119<br />

7.3. ( Errors ) − When I run my specific rc.firewall−* ruleset, I get "command not found" errors.<br />

Why?...................................................................................................................................................120<br />

7.4. ( Still wont work ) − I've checked all my configurations, I still can't get <strong>IP</strong> <strong>Masquerade</strong> to<br />

work. What should I do?.....................................................................................................................120<br />

7.5. ( Email list ) − How do I join or view the <strong>IP</strong> <strong>Masquerade</strong> and/or <strong>IP</strong> Masqurade Developers<br />

mailing lists and archives?..................................................................................................................120<br />

7.6. ( NAT vs. Proxy ) − How does <strong>IP</strong> <strong>Masquerade</strong> differ from Proxy or NAT services?..................121<br />

7.7. ( GUI ) − Are there any GUI firewall creation/management tools?.............................................123<br />

7.8. ( MASQ and Dynamic <strong>IP</strong>s ) − Does <strong>IP</strong> <strong>Masquerade</strong> work with dynamically assigned <strong>IP</strong><br />

addresses?...........................................................................................................................................123<br />

7.9. ( MASQ and various networks ) − Can I use a cable modem (both bi−directional and with<br />

modem returns), DSL, satellite link, etc. to connect to the Internet and use <strong>IP</strong> <strong>Masquerade</strong>?...........124<br />

ii


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Table of Contents<br />

Chapter 7. Frequently Asked Questions<br />

7.10. ( Dial on Demand ) − Can I use Diald or the Dial−on−Demand feature of PPPd with <strong>IP</strong><br />

MASQ?...............................................................................................................................................124<br />

7.11. ( Apps ) − What applications are supported with <strong>IP</strong> <strong>Masquerade</strong>?............................................124<br />

7.12. ( Distro Setup ) − How can I get <strong>IP</strong> <strong>Masquerade</strong> running on Redhat, Debian, Slackware,<br />

etc.?.....................................................................................................................................................125<br />

7.13. ( Timeouts ) − Connections seem to break if I don't use them often. Why is that?....................125<br />

7.14. ( Odd Behavior ) − When my Internet connection first comes up, nothing works. If I try<br />

again, everything then works fine. Why is this?.................................................................................125<br />

7.15. ( MTU ) − <strong>IP</strong> MASQ seems to be working fine but some sites don't work. This usually<br />

happens with WWW and some FTP sites..........................................................................................126<br />

7.15.1. Enabling PMTU Clamping for PPPoE and some PPP Users:...........................................127<br />

7.15.2. Clamping the MSS via <strong>IP</strong>TABLES:..................................................................................127<br />

7.15.3. Changing the External MTU of the MASQ server:..........................................................128<br />

7.15.4. Changing the MTU of various operating systems:............................................................128<br />

7.16. ( FTP ) − MASQed FTP clients don't work................................................................................132<br />

7.17. ( Performance ) − <strong>IP</strong> Masquerading seems slow........................................................................132<br />

7.18. ( PORTFW ) − <strong>IP</strong> Masquerading with PORTFWing seems to break when my line is idle<br />

for long periods...................................................................................................................................134<br />

7.19. ( PORTFW − Locally ) − I can't reach my PORTFWed server from the INTERNAL lan........134<br />

7.20. ( Logs ) − Now that I have <strong>IP</strong> Masquerading up, I'm getting all sorts of weird notices and<br />

errors in the SYSLOG log files. How do I read the <strong>IP</strong>TABLES/<strong>IP</strong>CHAINS/<strong>IP</strong>FWADM firewall<br />

errors?.................................................................................................................................................135<br />

7.21. ( Log Reduction ) − My logs are filling up with packet hits due to the new "stronger"<br />

rulesets. How can I fix this?................................................................................................................140<br />

7.22. ( MASQ Security ) − Can I configure <strong>IP</strong> MASQ to allow Internet users to directly contact<br />

internal MASQed servers?..................................................................................................................140<br />

7.23. ( Free Ports ) − I'm getting "kernel: ip_masq_new(proto=UDP): no free ports." in my<br />

SYSLOG files. Whats up?..................................................................................................................140<br />

7.24. ( SETSOCKOPT ) − I'm getting "ipfwadm: setsockopt failed: Protocol not available"<br />

when I try to use <strong>IP</strong>PORTFW!............................................................................................................141<br />

7.25. ( SAMBA ) − Microsoft File and Print Sharing and Microsoft Domain clients don't work<br />

through <strong>IP</strong> Masq!................................................................................................................................141<br />

7.26. ( IDENT ) − IRC won't work properly for MASQed IRC users. Why?.....................................142<br />

7.27. ( IRC DCC ) − mIRC doesn't work with DCC Sends.................................................................142<br />

7.28. ( <strong>IP</strong> Aliasing ) − Can <strong>IP</strong> <strong>Masquerade</strong> work with only ONE Ethernet network card?.................142<br />

7.29. ( Multiple−LANs ) − I have two MASQed LANs but they cannot communicate with each<br />

other!...................................................................................................................................................143<br />

7.30. ( SHAPING ) − I want to be able to limit the speed of specific types of traffic.........................143<br />

7.31. ( ACCOUNTING ) − I need to do accounting on who is using the network.............................143<br />

7.32. ( MULT<strong>IP</strong>LE <strong>IP</strong>s − DMZ segments) − I have several EXTERNAL <strong>IP</strong> addresses that I<br />

want to PORTFW to several internal machines. How do I do this?...................................................144<br />

7.33. ( 1:1 NAT ) − I'd like to do 1:1 NAT but I can't figure out how to do it....................................145<br />

7.34. ( Netstat ) − I'm trying to use the NETSTAT command to show my <strong>Masquerade</strong>d<br />

connections but its not working..........................................................................................................146<br />

7.35. ( VPNs ) − I would like to get Microsoft PPTP (GRE tunnels) and/or <strong>IP</strong>SEC (<strong>Linux</strong><br />

SWAN) tunnels running through <strong>IP</strong> MASQ.......................................................................................146<br />

7.36. ( Games ) − I want to get the XYZ network game to work through <strong>IP</strong> MASQ but it won't<br />

iii


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Table of Contents<br />

Chapter 7. Frequently Asked Questions<br />

work. Help!.........................................................................................................................................146<br />

7.37. ( Stops working ) − <strong>IP</strong> MASQ works fine for a while but then it stops working. A reboot<br />

seems to fix this. Why?.......................................................................................................................146<br />

7.38. ( SMTP Relay ) − Internal MASQed computers cannot send SMTP or POP−3 mail!...............146<br />

7.39. ( Source Routing ) − I need different internal MASQed networks to exit on different<br />

external <strong>IP</strong> addresses...........................................................................................................................147<br />

7.40. ( <strong>IP</strong>CHAINS rulesets on 2.4.x kernels ) − What the ipchains.o module can do on 2.4.x<br />

kernels.................................................................................................................................................148<br />

7.41. ( <strong>IP</strong>TABLES vs. <strong>IP</strong>CHAINS vs. <strong>IP</strong>FWADM ) − Why do the 2.4.x, 2.2.x, and 2.0.x kernels<br />

use different firewall systems?............................................................................................................149<br />

7.42. ( Upgrades ) − I've just upgraded to the x.y.z kernel, why isn't <strong>IP</strong> <strong>Masquerade</strong> working?........149<br />

7.43. ( EQL ) − I need help with EQL connections and <strong>IP</strong> Masq........................................................150<br />

7.44. ( Wussing out ) − I can't get <strong>IP</strong> <strong>Masquerade</strong> to work! What options do I have for Windows<br />

Platforms?...........................................................................................................................................150<br />

7.45. ( Developers ) − I want to help with <strong>IP</strong> <strong>Masquerade</strong> development. What can I do?..................151<br />

7.46. ( More INFO ) − Where can I find more information on <strong>IP</strong> <strong>Masquerade</strong>?.................................151<br />

7.47. ( Translators ) − I want to translate this <strong>HOWTO</strong> to another language, what should I do?.......151<br />

7.48. ( Updates ) − This <strong>HOWTO</strong> seems out of date, are you still maintaining it? Can you<br />

include more information on ...? Are there any plans for making this better?...................................152<br />

7.49. ( Thanks ) − I got <strong>IP</strong> <strong>Masquerade</strong> working, it's great! I want to thank you guys, what can I<br />

do?.......................................................................................................................................................152<br />

Chapter 8. Miscellaneous...............................................................................................................................153<br />

8.1. Useful Resources..........................................................................................................................153<br />

8.2. <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> Resource....................................................................................................153<br />

8.3. Thanks to the following supporters..............................................................................................154<br />

8.4. Reference......................................................................................................................................155<br />

8.5. ChangeLOG..................................................................................................................................155<br />

iv


Chapter 1. Introduction<br />

1.1. Introduction to <strong>IP</strong> Masquerading or <strong>IP</strong> MASQ<br />

This document describes how to enable the <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> feature on a given <strong>Linux</strong> host. <strong>IP</strong><br />

<strong>Masquerade</strong>, called "<strong>IP</strong>MASQ" or "MASQ" for short, is a form of Network Address Translation (NAT) which<br />

allows internally connected computers that do not have one or more registered Internet <strong>IP</strong> addresses to<br />

communicate to the Internet via the <strong>Linux</strong> server's Internet <strong>IP</strong> address. Since <strong>IP</strong>MASQ is a generic<br />

technology, you can connect the <strong>Linux</strong> server's internal and external to other computers through LAN<br />

technologies like Ethernet, TokenRing, and FDDI, as well as dialup connections line PPP or SL<strong>IP</strong> links. This<br />

document primarily uses Ethernet and PPP connections in examples because it is most commonly used with<br />

DSL / Cablemodems and dialup connections.<br />

"This document is intended for systems running stable <strong>Linux</strong> kernels like 2.4.x, 2.2.x, and 2.0.x preferably<br />

on an IBM−compatible PC. <strong>IP</strong> <strong>Masquerade</strong> does work on other <strong>Linux</strong>−supported platforms like Sparc,<br />

Alpha, PowerPC, etc. but this <strong>HOWTO</strong> doesn't cover them in as much detail. Beta kernels such as 2.5.x,<br />

2.3.x, 2.1.x, and ANY kernels less than 2.0.x are NOT covered in this document. <strong>The</strong> primary reason for<br />

this is because many of the older kernels are considered broken. If you are using an older kernel version, it<br />

is highly advisable to upgrade to one of the stable <strong>Linux</strong> kernels before using <strong>IP</strong> Masquerading. "<br />

1.2. Foreword, Feedback & Credits<br />

From the original <strong>IP</strong>MASQ <strong>HOWTO</strong> author:<br />

"As a new user, I found it very confusing to setup <strong>IP</strong> masquerade on the <strong>Linux</strong> kernel, (back then, its was a<br />

1.2.x kernel). Although there was a FAQ and a mailing list, there was no documentation dedicated to this.<br />

<strong>The</strong>re was also some requests on the mailing list for a <strong>HOWTO</strong> manual. So, I decided to write this <strong>HOWTO</strong><br />

as a starting point for new users and possibly create a building block for other knowledgeable users. If you,<br />

the reader, have any additional ideas, corrections, or questions about this document, please feel free to contact<br />

us. "<br />

This document was originally written by Ambrose Au back in August, 1996, based on the 1.x kernel <strong>IP</strong>MASQ<br />

FAQ written by Ken Eves and numerous helpful messages from the original <strong>IP</strong> <strong>Masquerade</strong> mailing list. In<br />

particular, a mailing list message from Matthew Driver inspired Ambrose to set up <strong>IP</strong> <strong>Masquerade</strong> and<br />

eventually write version 0.80 of this <strong>HOWTO</strong>. In April 1997, Ambrose created the <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong><br />

Resource Web site at http://ipmasq.webhop.net which has provided up−to−date information on <strong>Linux</strong> <strong>IP</strong><br />

Masquerading ever since. In February 1999, David Ranch took over maintenance of the <strong>HOWTO</strong>. David then<br />

re−wrote the <strong>HOWTO</strong> and added a substantial number of sections to the document. Today, the <strong>HOWTO</strong> is<br />

still maintained by David where he constantly updates it and fixes any reported bugs, etc.<br />

Please feel free to send any feedback or comments regarding this <strong>HOWTO</strong> to dranch@trinnet.net if you have<br />

any corrections or if any information/URLs/etc. is missing. Your invaluable feedback will certainly influence<br />

the future of this <strong>HOWTO</strong>!<br />

This <strong>HOWTO</strong> is meant to be a fairly comprehensive guide to getting your <strong>Linux</strong> <strong>IP</strong> Masquerading system<br />

working in the shortest time possible. David only plays a technical writer on T.V. so you might find the<br />

information in this document not as general and/or objective as it could be. If you think a section could be<br />

clearer, etc.. please let David know. <strong>The</strong> latest version of the MASQ <strong>HOWTO</strong> can be found at Dranch's <strong>Linux</strong><br />

Page. Additional news, mirrors of the <strong>HOWTO</strong>, and information regarding <strong>IP</strong>MASQ can be found at the <strong>IP</strong><br />

Chapter 1. Introduction 1


<strong>Masquerade</strong> Resource web page. If you have any technical questions on <strong>IP</strong> <strong>Masquerade</strong>, please join the <strong>IP</strong><br />

<strong>Masquerade</strong> Mailing List instead of sending email to David or Ambrose. Most MASQ problems are<br />

−common− for ALL MASQ users and can be easily solved by users on the list. In addition to this, the<br />

response time of the <strong>IP</strong> MASQ email list will be much faster than a reply from either David or Ambrose.<br />

<strong>The</strong> latest version of this document can be found at the following sites which also contains HTML, Postscript,<br />

PDF, etc. versions<br />

• Dranch's <strong>Linux</strong> page<br />

• http://ipmasq.webhop.net/: <strong>The</strong> <strong>IP</strong> <strong>Masquerade</strong> Resources<br />

• http://ipmasq2.webhop.net/: <strong>The</strong> <strong>IP</strong> <strong>Masquerade</strong> Resources MIRROR<br />

• <strong>The</strong> <strong>Linux</strong> <strong>Documentation</strong> <strong>Project</strong><br />

• Also refer to <strong>IP</strong> <strong>Masquerade</strong> Resource Mirror Sites Listing for other local mirrored sites.<br />

1.3. Copyright & Disclaimer<br />

This document is copyrighted(c) 2003,2002,2001,2000 for David A. Ranch and it is a<br />

FREE document. You may redistribute it under the terms of the GNU General Public License (GPL).<br />

<strong>The</strong> information herein this document is, to the best of David's knowledge, correct. However, the <strong>Linux</strong> <strong>IP</strong><br />

<strong>Masquerade</strong> feature is written by humans and thus, the chance of mistakes, bugs, etc. might occur from time<br />

to time.<br />

No person, group, or other body is responsible for any damage on your computer(s) and any other losses by<br />

using the information on this document. i.e.<br />

"THE AUTHORS AND ALL MAINTAINERS ARE NOT RESPONSIBLE FOR ANY DAMAGES INCURRED<br />

DUE TO ACTIONS TAKEN BASED ON THE INFORMATION IN THIS DOCUMENT. "<br />

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

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 1. Introduction 2


Chapter 2. Background Knowledge<br />

2.1. What is <strong>IP</strong> <strong>Masquerade</strong>?<br />

<strong>IP</strong> <strong>Masquerade</strong> is a networking function in <strong>Linux</strong> similar to the one−to−many (1:Many) NAT (Network<br />

Address Translation) servers found in many commercial firewalls and network routers. For example, if a<br />

<strong>Linux</strong> host is connected to the Internet via PPP, Ethernet, etc., the <strong>IP</strong> <strong>Masquerade</strong> feature allows other<br />

"internal" computers connected to this <strong>Linux</strong> box (via PPP, Ethernet, etc.) to also reach the Internet as well.<br />

<strong>Linux</strong> <strong>IP</strong> Masquerading allows for this functionality even though these internal machines don't have an<br />

officially assigned <strong>IP</strong> address.<br />

MASQ allows a set of machines to invisibly access the Internet via the MASQ gateway. To other machines on<br />

the Internet, the outgoing traffic will appear to be from the <strong>IP</strong> MASQ <strong>Linux</strong> server itself. In addition to the<br />

added functionality, <strong>IP</strong> <strong>Masquerade</strong> provides the foundation to create a HEAVILY secured networking<br />

environment. With a well built firewall, breaking the security of a well configured masquerading system and<br />

internal LAN should be considerably difficult to accomplish.<br />

If you would like to know more on how MASQ (1:Many) differs from 1:1 (true) NAT and Proxy solutions,<br />

please see the Section 7.6 FAQ entry.<br />

2.2. Current Status<br />

<strong>IP</strong> <strong>Masquerade</strong> has been in the <strong>Linux</strong> kernels for several years now and is quite mature as the kernel enters the<br />

2.4.x stage. Kernels since <strong>Linux</strong> 1.3.x have had MASQ support built−in. Today, many individuals and<br />

commercial businesses are using it with excellent results.<br />

2.4.x kernel users:<br />

• <strong>The</strong> 2.4.x kernel hosts an entirely re−written set of NAT code which is both far superior, faster, and<br />

more secure than any previous versions written for <strong>Linux</strong>. Unfortunately, several kernel modules that<br />

were written for the 2.2.x kernel to support things like UDP−based RealAudio, etc. have not been<br />

ported to 2.4.x yet. Because of this, some people should consider NOT upgrading if these network<br />

applications are critical to them. But, at the same time, some of these programs have been updated and<br />

now use different, NAT−friendly protocols. Thus special NAT treatment is no longer required. As<br />

always, please see the http://ipmasq.webhop.net/: <strong>The</strong> <strong>IP</strong> <strong>Masquerade</strong> Resources site for updated<br />

news, etc.<br />

Common network functionalities like Web browsing, telnet, ssh, ping, traceroute, etc. work well over stock <strong>IP</strong><br />

<strong>Masquerade</strong> setups. Other network applications such as ftp, irc, and Real Audio work well with the<br />

appropriate additional <strong>IP</strong> MASQ modules loaded into the kernel as modules. Other network−specific<br />

programs like streaming audio (MP3s, True Speech, etc) should work too without any special module. Some<br />

users on the mailing list also had good results with video conferencing software.<br />

It should be noted that running <strong>IP</strong> <strong>Masquerade</strong> with only ONE network card (NIC) to MASQ between internal<br />

and external Ethernet networks is NOT recommended. For more details, please see Section 7.28 FAQ section.<br />

Anyways, please refer to Section 6.3 for a more complete listing of software supported by <strong>IP</strong> Maquerade all<br />

kernel versions.<br />

Chapter 2. Background Knowledge 3


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

<strong>IP</strong> <strong>Masquerade</strong> works well as a server to other 'client machines' running various operating systems and<br />

hardware platforms. Here is a sampling of successful reports with internal MASQed systems running :<br />

• UNIX: Sun Solaris, [Net,Free,Open,*i]−BSD, Hp−UX, <strong>Linux</strong>, IBM AIX, Digital UNIX, Ultrix, etc.<br />

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

package)<br />

• IBM OS/2<br />

• Apple Macintosh MacOS machines running either MacTCP or Open Transport<br />

• DOS−based systems with packet drivers and the NCSA Telnet package<br />

• VAXen<br />

• Compaq/Digital Alpha running <strong>Linux</strong> and NT<br />

• Amiga computers with AmiTCP or AS225−stack.<br />

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

<strong>Masquerade</strong>!<br />

2.3. Who Can Benefit From <strong>IP</strong> <strong>Masquerade</strong>?<br />

• If you have a <strong>Linux</strong> host connected to the Internet and..<br />

• if you have internal computers running TCP/<strong>IP</strong> connected that are connected to this <strong>Linux</strong> box via on<br />

a network, and/or<br />

• if your <strong>Linux</strong> host has more than one modem and acts as a PPP or SL<strong>IP</strong> server connected to other<br />

computers, and these machines do not have official or public assigned <strong>IP</strong> addresses (i.e. addressed<br />

with private TCP/<strong>IP</strong> numbers).<br />

• If you want those OTHER machines to communicate to the Internet without spending extra money to<br />

acquire additional Public / Official TCP/<strong>IP</strong> addresses from your ISP, then you should either configure<br />

<strong>Linux</strong> to be a router or purchase an external router.<br />

2.4. Who Doesn't Need <strong>IP</strong> <strong>Masquerade</strong>?<br />

• If your machine is a stand−alone <strong>Linux</strong> host connected to the Internet (setting up a firewall is a good<br />

idea though), or<br />

• if you already have multiple assigned public addresses for your OTHER machines, and<br />

• if you don't like the idea of a 'free ride' using <strong>Linux</strong> and feel more comfortable using expensive<br />

commercial tools to perform the exact same functionalities.<br />

2.5. How does <strong>IP</strong> <strong>Masquerade</strong> Work?<br />

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

PPP/ETH/etc. +−−−−−−−−−−−−+ +−−−−−−−−−−−−−+<br />

to ISP provider | <strong>Linux</strong> #1 | PPP/ETH/etc. | Anybox |<br />

| | | |<br />


Ethernet connection, etc.<br />

<strong>The</strong> second system (which does not need to be <strong>Linux</strong>) connects into the <strong>Linux</strong> #1 box and starts its network<br />

traffic to the Internet. This second machine does NOT have a publicly assigned <strong>IP</strong> address from the Internet,<br />

so it uses an RFC1918 private address, say 192.168.0.100. (see below for more info)<br />

With <strong>IP</strong> <strong>Masquerade</strong> and the routing configured properly, this second machine "Anybox" can interact with the<br />

Internet as if it was directly connected to the Internet with a few small exceptions [noted later].<br />

Quoting Pauline Middelink (the founder of <strong>Linux</strong>'s <strong>IP</strong>MASQ):<br />

"Do not forget to mention that the "ANYBOX" machine should have the <strong>Linux</strong> #1 box configured as its<br />

default gateway (whether it be the default route or just a subnet is no matter). If the "ANYBOX" machine is<br />

connected via a PPP or SL<strong>IP</strong> connection, the <strong>Linux</strong> #1 machine should be configured to support proxy arp for<br />

all routed addresses. But, the setup and configuration of proxy arp is beyond the scope of this document.<br />

Please see the PPP−<strong>HOWTO</strong> for more details."<br />

<strong>The</strong> following is an excerpt on how <strong>IP</strong>MASQ briefly works though this will be explained in more detail later.<br />

This short text is based from a previous post on comp.os.linux.networking which has been edited to match the<br />

names used in the above example:<br />

o I tell machine ANYBOX that my PPP or Ethernet connected <strong>Linux</strong> box is its<br />

gateway.<br />

o When a packet comes into the <strong>Linux</strong> box from ANYBOX, it will assign the<br />

packet to a new TCP/<strong>IP</strong> source port number and insert its own <strong>IP</strong> address<br />

inside the packet header, saving the originals. <strong>The</strong> MASQ server will<br />

then send the modified packet over the PPP/ETH interface onto the<br />

Internet.<br />

o When a packet returns from the Internet into the <strong>Linux</strong> box, <strong>Linux</strong><br />

examines if the port number is one of those ports that was assigned<br />

above. If so, the MASQ server will then take the original port and<br />

<strong>IP</strong> address, put them back in the returned packet header, and send<br />

the packet to ANYBOX.<br />

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

Another <strong>IP</strong> Masquerading Example:<br />

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

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Ethernet<br />

192.168.0.x<br />

+−−−−−−−−−−+<br />

| |<br />

| A−box |::::::<br />

| |.2 :<br />

+−−−−−−−−−−+ :<br />

: +−−−−−−−−−−+ PPP/ETH<br />

+−−−−−−−−−−+ : .1 | <strong>Linux</strong> | link<br />

| | :::::::| Masq−Gate|:::::::::::::::::::>> Internet<br />

| B−box |:::::: | | 111.222.121.212<br />

| |.3 : +−−−−−−−−−−+<br />

+−−−−−−−−−−+ :<br />

:<br />

+−−−−−−−−−−+ :<br />

Chapter 2. Background Knowledge 5


| | :<br />

| C−box |::::::<br />

| |.4<br />

+−−−−−−−−−−+<br />

| | | ><br />

| | | ><br />

| connected via an | | Connected from the ><br />

| Ethernet hub or | | <strong>Linux</strong> server to your ><br />

| switch | | Internet connection ><br />

In this example, there are (4) computer systems that we are concerned about. <strong>The</strong>re is also presumably<br />

something on the far right that your PPP/ETH connection to the Internet comes through (modem server, DSL<br />

DSLAM, Cablemodem router, etc.). Out on the Internet, there exists some remote host (very far off to the<br />

right of the page) that you are interested in communicating with). <strong>The</strong> <strong>Linux</strong> system named Masq−Gate is<br />

the <strong>IP</strong> Masquerading gateway for ALL internal networked machines. In this example, the machines A−box,<br />

B−box, and C−box would have to go through the Masq−Gate to reach the Internet. <strong>The</strong> internal network uses<br />

one of several RFC−1918 assigned private network addresses, where in this case, would be the Class−C<br />

network 192.168.0.0. If you aren't familiar with RFC1918, it is encouraged to read the first few chapters of the<br />

RFC but the jist of it is that the TCP/<strong>IP</strong> addresses 10.0.0.0/8, 172.16−31.0.0/12, and 192.168.0.0/16 are<br />

reserved. When we say "reserved", we mean that anyone can use these addresses as long as they aren't routed<br />

over the Internet. ISPs are even allowed to use this private addressing space as long as they keep these<br />

addresses within their own networks and NOT advertise them to other ISPs. Unfortunately, this isn't always<br />

the case but thats beyond the scope of this <strong>HOWTO</strong>.<br />

Anyway, the <strong>Linux</strong> box in the diagram above has the TCP/<strong>IP</strong> address 192.168.0.1 while the other systems has<br />

the addresses:<br />

• A−Box: 192.168.0.2<br />

• B−Box: 192.168.0.3<br />

• C−Box: 192.168.0.4<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

<strong>The</strong> three machines, A−box, B−box and C−box, can have any one of several operating systems, just as long<br />

as they can speak TCP/<strong>IP</strong>. Some such as Windows 95, Macintosh MacTCP or OpenTransport , or even<br />

another <strong>Linux</strong> box have the ability to connect to other machines on the Internet. When running the <strong>IP</strong><br />

<strong>Masquerade</strong>, the masquerading system or MASQ−gate converts all of these internal connections so that they<br />

appear to originate from the masq−gate itself. MASQ then arranges so that the data coming back to a<br />

masqueraded connection is relayed to the proper originating system. <strong>The</strong>refore, the systems on the internal<br />

network are only able to see a direct route to the internet and are unaware that their data is being<br />

masqueraded. This is called a "Transparent" connection.<br />

NOTE: Please see Chapter 7 for more details on topics such as:<br />

• <strong>The</strong> differences between NAT, MASQ, and Proxy servers.<br />

• How packet firewalls work<br />

2.6. Requirements for <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.4.x<br />

" ** Please refer to <strong>IP</strong> <strong>Masquerade</strong> Resource for the latest information. ** "<br />

• <strong>The</strong> newest 2.4.x kernels are now using both a completely new TCP/<strong>IP</strong> network stack as well as a new<br />

NAT sub−system called NetFilter. Within this NetFilter suite of tools, we now have a tool called<br />

Chapter 2. Background Knowledge 6


<strong>IP</strong>TABLES for the 2.4.x kernels much like there was <strong>IP</strong>CHAINS for the 2.2.x kernels and<br />

<strong>IP</strong>FWADM for the 2.0.x kernels. <strong>The</strong> new <strong>IP</strong>TABLES system is far more powerful (combines several<br />

functions into one place like true NAT functionality), offers better security (stateful inspection), and<br />

better performance with the new 2.4.x TCP/<strong>IP</strong> stack. But this new suite of tools can be a bit<br />

complicated in comparison to older generation kernels. Hopefully, if you follow along with this<br />

<strong>HOWTO</strong> carefully, setting up <strong>IP</strong>MASQ won't be too bad. If you find anything unclear, downright<br />

wrong, etc. please email David about it.<br />

Unlike the migration to <strong>IP</strong>CHAINS from <strong>IP</strong>FWADM, the new NetFilter tool has kernel modules that<br />

can actually support older <strong>IP</strong>CHAINS and <strong>IP</strong>FWADM rulesets with minimal changes. So re−writing<br />

your old MASQ or firewall ruleset scripts is not longer required. BUT.. with the 2.4.x kernels, you<br />

cannot use the old 2.2.x MASQ modules like ip_masq_ftp, ip_masq_irc, etc. AND <strong>IP</strong>CHAINS is<br />

incompatible with the new <strong>IP</strong>TABLES modules like ip_conntrack_ftp, etc. So, what does this mean?<br />

It basically means that if you want to use <strong>IP</strong>MASQ or PORTFW functionality under a 2.4.x kernel,<br />

you shouldn't use <strong>IP</strong>CHAINS rules but <strong>IP</strong>TABLES ones instead. Please also keep in mind that there<br />

might be several benefits in performing a full ruleset re−write to take advantage of the newer<br />

<strong>IP</strong>TABLES features like stateful tracking, etc. but that is dependant upon how much time you have to<br />

migrate your old rulesets. Please see Section 7.40 for additional details.<br />

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

PROs:<br />

CONs:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• Lots of new protocols modules like: amanda, eggdrop, ipsec, ipv6, portscan, pptp, quota, rsh, talk, and<br />

tftp<br />

• TRUE 1:1 NAT functionality for those who have TCP/<strong>IP</strong> addresses and subnets to use (no more<br />

iproute2 commands)<br />

• Stateful application level (FTP, IRC, etc.) and stateful protocol level (TCP/UDP/ICMP) network<br />

traffic inspection<br />

• Built−in PORT Forwarding (no more ipmasqadm or ipportfw commands)<br />

• <strong>The</strong> built−in PORTFW'ing support works for both external and internal traffic. This means that users<br />

that have PORTFW for external traffic and REDIR for internal port redirection do not need to use two<br />

tools any more!<br />

• PORT Forwarding of FTP traffic to internal hosts is now completely supported and is handled in the<br />

conn_trak_ftp module<br />

• Full Policy−Based routing features (source−based TCP/<strong>IP</strong> address routing)<br />

• Compatibility with <strong>Linux</strong>'s FastRoute feature for significantly faster packet forwarding (a.k.a <strong>Linux</strong><br />

network switching).<br />

Note that this feature is still not compatible with packet filtering for strong firewall rulesets.<br />

• Fully supports TCP/<strong>IP</strong> v4, v6, and even DECnet (ack!)<br />

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

• Supports filtering on both input and output INTERFACES (not just <strong>IP</strong> addresses)<br />

• Source Ethernet MAC filtering<br />

• Denial of Service (DoS) packet rate limiting<br />

• Packet REJECTs now have user−selectable return ICMP messages<br />

• Variable levels of logging (different packets can go to different SYSLOG levels)<br />

• Other features like traffic mirroring, securing traffic per login, etc.<br />

Chapter 2. Background Knowledge 7


•<br />

Netfilter is an entirely new architechure thus most of the older 2.2.x MASQ kernel modules written to<br />

make non−NAT friendly network applications work through <strong>IP</strong>MASQ need to be re−written for the<br />

2.4.x kernels. Because of this, if you specifically need functionality from some of these modules (see<br />

below), you should stay with a 2.2.x kernel until these modules have been either ported or the<br />

application has been updated to use NAT−friendly protocols. If you are curious on the porting status<br />

of a given module, please email the author of the module and NOT David or Ambrose. We don't<br />

code.. we just document. :−)<br />

Here is the status of the known <strong>IP</strong> Masq kernel modules or patches as found on the <strong>IP</strong>MASQ WWW<br />

site's Application Support Matrix. In addition, you should also setup out the Netfilter Patch−o−Matic<br />

URL as well. If you have the time and knowledge to help in the porting of code, your efforts would be<br />

highly appreciated:<br />

Status = Module name = Description and notes<br />

−−−−−−−−− −−−−−−−−−−− −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

Ported CuSeeme Used for Video conferencing<br />

NotPorted DirectPlay Used for online Microsoft−based games<br />

Ported FTP Used for file transfers<br />

− NOTEs: Built into the kernel and<br />

fully supports PORTFWed FTP<br />

ReWritten H.323 Used for Video conferencing<br />

NotPorted ICQ Used for Instant messaging<br />

* No longer required for modern ICQ clients<br />

Ported Irc Used for Online chat rooms<br />

Ported Quake Used for online Quake games<br />

Ported PPTP Allow for multiple clients to the same server<br />

NotPorted Real Audio Used for Streaming video / audio<br />

* No longer required for modern RealVideo clients<br />

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

<strong>Documentation</strong> on how to perform MASQ module porting is available at<br />

http://www.netfilter.org/documentation/<strong>HOWTO</strong>/netfilter−hacking−<strong>HOWTO</strong>.html. If you have the<br />

time and knowledge, your talent would highly be appreciated in porting these modules.<br />

If you'd like to read up more on NetFilter and <strong>IP</strong>Tables, please see:<br />

http://www.netfilter.org/documentation/index.html#<strong>HOWTO</strong> and more specifically<br />

http://www.netfilter.org/documentation/<strong>HOWTO</strong>//NAT−<strong>HOWTO</strong>.html<br />

<strong>Linux</strong> 2.4.x <strong>IP</strong> <strong>Masquerade</strong> requirements include:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• Any decent computer hardware. See Section 7.2 for more details.<br />

• <strong>The</strong> 2.4.x kernel source is available from http://www.kernel.org/.<br />

NOTE: Most modern <strong>Linux</strong> distributions, Section 7.1, that natively come with 2.4.x kernels are<br />

typically modular kernels and have all the <strong>IP</strong> <strong>Masquerade</strong> functionality already included. In such<br />

cases, there is no need to compile a new <strong>Linux</strong> kernel. If you are UPGRADING your kernel, you<br />

should be aware of other programs that might be required and/or need to be upgraded as well<br />

Chapter 2. Background Knowledge 8


•<br />

(mentioned later in this <strong>HOWTO</strong>).<br />

<strong>The</strong> program "iptables" version 1.2.4 or newer ( 1.2.7a or newer is highly recommended ) archive<br />

available from http://www.netfilter.org/<br />

♦<br />

NOTE #1: All versions of <strong>IP</strong>TABLES less than 1.2.3 have a FTP module issue that can<br />

bypass any existing firewall rulesets. ALL <strong>IP</strong>TABLES users are highly recommended to<br />

upgrade to the newest version. <strong>The</strong> URL is above.<br />

NOTE #2: All versions of <strong>IP</strong>TABLES less than 1.2.2 have a FTP "port" security vulnerability<br />

in the ip_conntrack_ftp module. All <strong>IP</strong>TABLES users are highly recommended to upgrade to<br />

the newest version. <strong>The</strong> URL is above.<br />

♦ This tool, much like the older <strong>IP</strong>CHAINS and <strong>IP</strong>FWADM tools enables the various<br />

Masquerding code, more advanced forms of NAT, packet filtering, etc. It also makes use of<br />

additional MASQ modules like the FTP and IRC modules. Additional information on version<br />

requirements for the newest <strong>IP</strong>TABLES howto, etc. is located at the Unreliable <strong>IP</strong>TABLES<br />

<strong>HOWTO</strong>s page.<br />

• Loadable kernel modules, preferably 2.1.121 or higher, are available from<br />

http://home.pi.se/blox/modutils/index.html or ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils<br />

• A properly configured and running TCP/<strong>IP</strong> network running on the <strong>Linux</strong> machine as covered in<br />

<strong>Linux</strong> NET <strong>HOWTO</strong> and the Network Administrator's Guide . Also check out the TrinityOS<br />

document which is also authored by David Ranch. TrinityOS is a very comprehensive guide for <strong>Linux</strong><br />

networking. Some topics include <strong>IP</strong> MASQ, security, DNS, DHCP, Sendmail, PPP, Diald, NFS,<br />

<strong>IP</strong>SEC−based VPNs, and performance sections, to name a few. <strong>The</strong>re are over Fifty sections in all!<br />

• Connectivity to the Internet for your <strong>Linux</strong> host covered in <strong>Linux</strong> ISP Hookup <strong>HOWTO</strong>, <strong>Linux</strong> PPP<br />

<strong>HOWTO</strong>, and TrinityOS. Other helpful <strong>HOWTO</strong>s could include: <strong>Linux</strong> DHCP mini−<strong>HOWTO</strong>, <strong>Linux</strong><br />

Cable Modem mini−<strong>HOWTO</strong> and http://www.tldp.org/<strong>HOWTO</strong>/DSL−<strong>HOWTO</strong>/index.html<br />

• Know how to configure, compile, and install a new <strong>Linux</strong> kernel as described in the <strong>Linux</strong> Kernel<br />

<strong>HOWTO</strong>. This <strong>HOWTO</strong> does cover kernel compiling but only for <strong>IP</strong> <strong>Masquerade</strong> related options.<br />

2.7. Requirements for <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.2.x<br />

" ** Please refer to <strong>IP</strong> <strong>Masquerade</strong> Resource for the latest information. ** "<br />

• Any decent computer hardware. See Section 7.2 for more details.<br />

• <strong>The</strong> 2.2.x kernel source is available from http://www.kernel.org/.<br />

•<br />

NOTE: Most modern <strong>Linux</strong> distributions, Section 7.1, that natively come with 2.2.x kernels are<br />

typically modular kernels and have all the <strong>IP</strong> <strong>Masquerade</strong> functionality already included. In such<br />

cases, there is no need to compile a new <strong>Linux</strong> kernel. If you are UPGRADING your kernel, you<br />

should be aware of other programs that might be required and/or need to be upgraded as well<br />

(mentioned later in this <strong>HOWTO</strong>).<br />

♦<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

NOTE #1: −−− UPDATE YOUR KERNEL −−− <strong>Linux</strong> 2.2.x kernels less than version 2.2.20<br />

contain several different security vulnerabilities (some were MASQ specific). Kernels less<br />

than 2.2.20 have a few local vulnerabilities. Kernel versions less than 2.2.16 have a TCP root<br />

exploit vulnerability and versions less than 2.2.11 have a <strong>IP</strong>CHAINS fragmentation bug.<br />

Because of these issues, users running a firewall with strong <strong>IP</strong>CHAINS rulesets are open to<br />

possible instrusion. Please upgrade your kernel to a fixed version.<br />

NOTE #2: Some newer Section 7.1 such as Redhat 5.2 might not be <strong>Linux</strong> 2.2.x ready (upgradable).<br />

Tools like DHCP, NetUtils, etc. will need to be upgraded. More details can be found later in the<br />

Chapter 2. Background Knowledge 9


<strong>HOWTO</strong>.<br />

• Loadable kernel modules, preferably 2.1.121 or higher, are available from<br />

http://home.pi.se/blox/modutils/index.html or ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils<br />

• A properly configured and running TCP/<strong>IP</strong> network running on the <strong>Linux</strong> machine as covered in<br />

<strong>Linux</strong> NET <strong>HOWTO</strong> and the Network Administrator's Guide . Also check out the TrinityOS<br />

document which is also authored by David Ranch. TrinityOS is a very comprehensive guide for <strong>Linux</strong><br />

networking. Some topics include <strong>IP</strong> MASQ, security, DNS, DHCP, Sendmail, PPP, Diald, NFS,<br />

<strong>IP</strong>SEC−based VPNs, and performance sections, to name a few. <strong>The</strong>re are over Fifty sections in all!<br />

• Connectivity to the Internet for your <strong>Linux</strong> host covered in <strong>Linux</strong> ISP Hookup <strong>HOWTO</strong>, <strong>Linux</strong> PPP<br />

<strong>HOWTO</strong>, and TrinityOS. Other helpful <strong>HOWTO</strong>s could include: <strong>Linux</strong> DHCP mini−<strong>HOWTO</strong>, <strong>Linux</strong><br />

Cable Modem mini−<strong>HOWTO</strong> and http://www.tldp.org/<strong>HOWTO</strong>/DSL−<strong>HOWTO</strong>/index.html<br />

• <strong>IP</strong> Chains 1.3.10 or newer are available from http://www.netfilter.org/ipchains/. Additional<br />

information on version requirements for the newest <strong>IP</strong>CHAINS <strong>HOWTO</strong>, etc is located at the <strong>Linux</strong><br />

<strong>IP</strong> Chains page (mirror at Samba.org)<br />

• Know how to configure, compile, and install a new <strong>Linux</strong> kernel as described in the <strong>Linux</strong> Kernel<br />

<strong>HOWTO</strong>. This <strong>HOWTO</strong> does cover kernel compiling but only for <strong>IP</strong> <strong>Masquerade</strong> related options.<br />

Other optional patches and tools for 2.2.x kernels<br />

• TCP/<strong>IP</strong> port−forwarding or re−directing:<br />

♦ <strong>IP</strong> PortForwarding (<strong>IP</strong>MASQADM) − RECOMMENDED − mirror<br />

• PORTFW FTP Solutions:<br />

•<br />

♦<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

<strong>The</strong>re are 2.2.x and 2.0.x kernel MASQ Module solutions for PORTFWed FTP to a MASQed<br />

machine (put an FTP server behind a MASQ server). Please see the Application Page on the<br />

<strong>IP</strong>MASQ WWW site for full details. Please note that this is not required for 2.4.x kernels.<br />

<strong>The</strong>re is a full FTP proxy application from SuSe that will also allow PORTFWed−like<br />

functionality to reach an internal FTP server. For more details, please refer to the SuSe Proxy<br />

URL.<br />

<strong>IP</strong>ROUTE2 for True 1:1 NAT, Policy−based (source) routing, and Traffic Shaping:<br />

♦ ftp://ftp.inr.ac.ru/ip−routing<br />

♦ <strong>Documentation</strong> can be found at http://www.compendium.com.ar/policy−routing.txt<br />

♦ <strong>The</strong> Advanced Routing <strong>HOWTO</strong><br />

♦ Some source code mirrors are at:<br />

ftp://ftp.funet.fi/pub/mirrors/ftp.inr.ac.ru/ip−routing/ (STM1 to USA) −−−<br />

ftp://sunsite.icm.edu.pl/pub/<strong>Linux</strong>/iproute/<br />

ftp://ftp.sunet.se/pub/<strong>Linux</strong>/ip−routing/ −−− ftp://ftp.nvg.ntnu.no/pub/linux/ip−routing/<br />

ftp://ftp.crc.ca/pub/systems/linux/ip−routing/ −−− ftp://ftp.paname.org (France)<br />

Please see the <strong>IP</strong> <strong>Masquerade</strong> Resource page for more information available on these patches and possibly<br />

others as well.<br />

Chapter 2. Background Knowledge 10


2.8. Requirements for <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.0.x<br />

" ** Please refer to <strong>IP</strong> <strong>Masquerade</strong> Resource for the latest information. ** "<br />

• Any decent computer hardware. See Section 7.2 for more details.<br />

• <strong>The</strong> 2.0.x kernel source is available from http://www.kernel.org/.<br />

NOTE: Most modern <strong>Linux</strong> Section 7.1 that natively come with 2.0.x kernels are typically modular<br />

kernels and have all the <strong>IP</strong> <strong>Masquerade</strong> functionality already included. In such cases, there is no need<br />

to compile a new <strong>Linux</strong> kernel. If you are UPGRADING your kernel, you should be aware of other<br />

programs that might be required and/or need to be upgraded as well (mentioned later in this<br />

<strong>HOWTO</strong>).<br />

• Loadable kernel modules, preferably 2.1.85 or newer is available from<br />

http://home.pi.se/blox/modutils/index.html or ftp://ftp.kernel.org/pub/linux/utils/kernel/modutils<br />

(modules−1.3.57 is the minimal requirement)<br />

• A properly configured and running TCP/<strong>IP</strong> network running on the <strong>Linux</strong> machine as covered in<br />

<strong>Linux</strong> NET <strong>HOWTO</strong> and the Network Administrator's GuideAlso check out the TrinityOS document<br />

which is also authored by David Ranch. TrinityOS is a very comprehensive guide to <strong>Linux</strong><br />

networking. Topics include <strong>IP</strong> MASQ, security, DNS, DHCP, Sendmail, PPP, Diald, NFS,<br />

<strong>IP</strong>SEC−based VPNs, performance issues, and many more. <strong>The</strong>re exists over fifty sections in all!<br />

• Connectivity to the Internet for your <strong>Linux</strong> host is covered in <strong>Linux</strong> ISP Hookup <strong>HOWTO</strong>, <strong>Linux</strong><br />

PPP <strong>HOWTO</strong>, and TrinityOS. Other helpful <strong>HOWTO</strong>s could include: <strong>Linux</strong> DHCP mini−<strong>HOWTO</strong>,<br />

<strong>Linux</strong> Cable Modem mini−<strong>HOWTO</strong> and <strong>Linux</strong> DSL <strong>HOWTO</strong><br />

• Ipfwadm 2.3.0 or newer is available from http://www.xos.nl/linux/ipfwadm/download.html<br />

• More information on version requirements are on the <strong>Linux</strong> <strong>IP</strong>FWADM page<br />

• If you are interested in running <strong>IP</strong>CHAINS on a 2.0.x+ kernel, see Willy Tarreau's <strong>IP</strong>CHAINS<br />

enabler for 2.0.36+ or Rusty's <strong>IP</strong>CHAINS for 2.0.x kernels. Please note that these patches are NOT<br />

compatible with the <strong>IP</strong>PORTFW patches for the 2.0.x kernels. Unfortunately, its an either/or deal.<br />

• Know how to configure, compile, and install a new <strong>Linux</strong> kernel as described in the <strong>Linux</strong> Kernel<br />

<strong>HOWTO</strong>. This <strong>HOWTO</strong> does cover kernel compiling but only for <strong>IP</strong> <strong>Masquerade</strong> related options.<br />

Here is a list of <strong>IP</strong> Masquerading patches for 2.0.x kernels:<br />

• Steven Clarke's <strong>IP</strong> PortForwarding (<strong>IP</strong>PORTFW) − RECOMMENDED<br />

• <strong>IP</strong> AutoForward − NOT Recommended<br />

• REDIR for TCP (REDIR) − NOT Recommended unless required for internal PORTFW<br />

• UDP redirector (UDPRED) − NOT Recommended<br />

• PORTFWed FTP:<br />

•<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

♦ If you are going to port forward FTP traffic to an internal FTP server, you might need to<br />

download Fred Viles's FTP server patch <strong>The</strong> reason for "might" is that some users have had<br />

success without the use of these pathches, while others need it. Explicit details on this topic<br />

can be found in Section 6.7 of this <strong>HOWTO</strong>.<br />

X−Windows display forwarders:<br />

♦ X−windows forwarding (DXCP)<br />

• PPTP (GRE) and SWAN (<strong>IP</strong>SEC) VPNs tunneling forwarders:<br />

♦ If you plan connecting an internal MASQed PC to a remote PPTP server, you MUST<br />

INSTALL the PPTP−<strong>Masquerade</strong> kernel patch available from the URLsbelow. If you plan on<br />

Chapter 2. Background Knowledge 11


•<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

having external PPTP users connect to an internal masqueraded PPTP server, not only do you<br />

need the kernel patch installed but you also need PORTFW support enabled in the kernel.<br />

Please see the following URLs for the patches and more information:<br />

John Hardin's VPN <strong>Masquerade</strong> forwarders or the old patch for just PPTP Support.<br />

Game specific patches:<br />

♦ Glenn Lamb's LooseUDP for 2.0.36+ patch.<br />

Chapter 2. Background Knowledge 12


Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong><br />

3.1. Compiling a new kernel if needed<br />

If your private network contains any vital information, think carefully in terms of SECURITY before<br />

implementing <strong>IP</strong> <strong>Masquerade</strong>. By default, <strong>IP</strong> MASQ becomes a GATEWAY for you to get onto the Internet,<br />

but it also can allow someone from the Internet to possibly get into your internal network.<br />

Once you have <strong>IP</strong> MASQ functioning, it is HIGHLY recommended for the user to implement a STRONG<br />

<strong>IP</strong>FWADM/<strong>IP</strong>CHAINS firewall ruleset. Please see Section 6.4.1, Section 6.4.2 and Section 6.4.3 located<br />

below for more details.<br />

3.2. Checking your existing kernel for MASQ functionality<br />

Almost ALL modern <strong>Linux</strong> distributions come MASQ−Ready these days but its always good to check your<br />

system before you try to set things up. Follow these few steps for your kernel to see if your kernel is MASQ<br />

ready.<br />

To see which kernel your system is running, run the following command:<br />

uname −a<br />

• Just for clarity: 2.4.x kernels run <strong>IP</strong>TABLES :: 2.2.x kernels run <strong>IP</strong>CHAINS :: 2.0.x kernels run<br />

<strong>IP</strong>FWADM<br />

• In general, you must have kernel support for:<br />

♦ <strong>IP</strong> forwarding<br />

♦ <strong>IP</strong> masquerading<br />

♦ <strong>IP</strong> Firewalling<br />

♦ etc.<br />

You will also need to have most MASQ−related modules compiled (most modular kernels will already have<br />

all you need already done. <strong>The</strong>n you will NOT need to re−compile the kernel. If you AREN'T SURE if your<br />

<strong>Linux</strong> distribution is MASQ ready, do the following:<br />

• 2.4.x kernels (look for most of the following entries out of the much longer list):<br />

♦<br />

Run the command "ls /proc/sys/net/ipv4" while logged into the <strong>Linux</strong> box. <strong>The</strong>se<br />

items are required and should be present regardless if your kernel built <strong>IP</strong>MASQ as modules<br />

or statically.<br />

◊ ip_dynaddr<br />

ip_forward<br />

♦ To check if <strong>IP</strong>MASQ was compiled statically into the kernel, run the command<br />

"/sbin/lsmod" and see if and modules like the ones shown below for the MODULE<br />

section are loaded. No? Ok, now run the command "ls /proc/net/" and see if you see<br />

additional /proc files such as:<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 13


◊ ip_masquerade<br />

ip_conntrack<br />

ip_tables_names<br />

If you see these /proc entries and there WEREN'T any kernel modules loaded (shown via the<br />

"lsmod" command mentioned above), then your kernel has the <strong>IP</strong>TABLES subsystem<br />

statically compiled into it and is ready to go to use <strong>IP</strong>MASQ on this system.<br />

♦ If your kernel uses <strong>IP</strong>TABLES via modules, most of the stuff listed above should have been<br />

missing (because the modules probably aren't loaded). Run the command "ls<br />

/lib/modules/`uname −r`/kernel/net/ipv4/netfilter/" where you<br />

should see files like:<br />

◊<br />

ip_conntrack.o, ip_conntrack_ftp.o, ip_conntrack_irc.o,<br />

ip_nat_ftp.o, ip_nat_irc.o<br />

ip_tables.o, ipt_MASQUERADE.o, iptable_nat.o,<br />

iptable_mangle.o, iptable_filter.o<br />

And some optional ones like: ipchains.o, ipt_REJECT.o, and<br />

ipt_tcpmss.o<br />

If you see those kernel files, <strong>IP</strong>TABLES was compiled using modules and things look ready<br />

to go to use <strong>IP</strong>MASQ on this system.<br />

• 2.2.x kernels (look for most of the following entries out of the much longer list): list):<br />

♦<br />

Run the command "ls /proc/sys/net/ipv4" while logged into the <strong>Linux</strong> box. <strong>The</strong>se<br />

items are required and should be present regardless if your kernel built <strong>IP</strong>MASQ as modules<br />

or statically.<br />

◊ ip_always_defrag<br />

ip_dynaddr<br />

ip_forward<br />

ip_masq_debug<br />

ip_masq_udp_dloose (some distros don't support this −− ignore it for now<br />

Other 2.2.x options can be checked by running "ls /proc/net/"<br />

⋅ ip_fwchains<br />

ip_fwnames<br />

ip_masquerade<br />

Even more 2.2.x options can be checked by running "ls /proc/net/"<br />

⋅ app<br />

icmp<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 14


•<br />

icq<br />

mfw<br />

portfw<br />

tcp<br />

udp/<br />

2.0.x kernels (look for most of the following entries out of the much longer list):<br />

♦<br />

Run the command "ls /proc/sys/net/ipv4" while logged into the <strong>Linux</strong> box. <strong>The</strong>se<br />

items are required and should be present regardless if your kernel built <strong>IP</strong>MASQ as modules<br />

or statically.<br />

◊ ip_dynaddr<br />

ip_forward<br />

running "ls /proc/net"<br />

⋅ ip_forward<br />

ip_masq_app<br />

ip_masquerade<br />

ip_portfw<br />

Ultimately, it comes down to the fact if you see /proc files such as "iip_forward", "ip_masq_debug",<br />

"ip_masq_udp_dloose"(optional), and "ip_always_defrag" (optional) exist.<br />

So. Do most of the above /proc entries or kernel modules show up for your respective kernel? If so, thats<br />

good! If you cannot find any of the above entries or if you aren't sure if your distribution supports <strong>IP</strong><br />

Masquerading by default, ASSUME IT DOESN'T SUPPORT MASQ. You can do one last check by looking<br />

at the Section 7.1 section and see if your <strong>Linux</strong> Distribution is listed. Still not there? Sounds like you'll need to<br />

compile a kernel but don't worry.. it isn't hard.<br />

Regardless if your current kernel has MASQ support or not, reading the remainder of this section is still<br />

highly recommended as it contains other useful information.<br />

3.2.1. Compiling <strong>Linux</strong> 2.4.x Kernels<br />

•<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

First, you'll need to get some 2.4.x kernel sources (preferably the latest kernel version − NEWER<br />

*IS* BETTER IN LINUX LAND)<br />

♦ NOTE #1: As both the 2.4.x kernel train and the iptables program development progresses,<br />

the compile configurion options will change over time. As of this version of the <strong>IP</strong>MASQ<br />

howto, this section reflects the settings for <strong>IP</strong>TABLES 1.2.7a and the 2.4.20 kernel. If you are<br />

compiling against a newer or previous kernel or <strong>IP</strong>TABLES version, the dialogs and even<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 15


commands might look different. It is recommended that you update to the newest versions of<br />

both the kernel and <strong>IP</strong>TABLES for added capability, performance, and stability of the kernel.<br />

• Next, depending on the version of the <strong>Linux</strong> kernel and <strong>IP</strong>TABLES archive you downloaded, you<br />

might want to apply some <strong>IP</strong>TABLES "patch−o−matic" patches against the kernel. <strong>The</strong>se<br />

OPTIONAL patches might fix some known problems, add additional functionality you might need<br />

(H.323 protocol, specific issues with network games), etc. It should be noted that the Patch−O−Matic<br />

patches used to come with the <strong>IP</strong>TABLES archive. This is no longer the case and you have to<br />

download them (if any) seperately. You can find the the various URLs for downloading <strong>IP</strong>TABLES,<br />

the Patch−o−matic system, etc. Section 2.6.<br />

• If this is your first time compiling the kernel, don't be scared. In fact, it's rather easy and it's covered<br />

in several URLs found in Section 2.6. Please note that the instructions included here is just one way to<br />

do build a kernel. Please see the Kernel <strong>HOWTO</strong> for full details.<br />

NOTE: Please notice that it IS NOT recommended to put the new kernel sources into the<br />

/usr/src/linux directory. You should leave the original kernel sources that came with your <strong>Linux</strong><br />

distribution in /usr/src/linux. For more details on this topic, please read the "README" file in the top<br />

level directory of the kernel sources.<br />

• For this <strong>HOWTO</strong> example, create a directory called /usr/src/kernel. Next, "cd" into this<br />

directory and download the newest 2.4.x kernel sources into it. Once downloaded, issue the following<br />

command (if the file ends in a .tar.gz): tar xvzf linux−2.4.x.tar.gz or (if the file ends in a<br />

.tar.bzip2): tar xyvf linux−2.4.x.tar.bz2. Please substitute the "x" in the 2.4.x filename<br />

with the <strong>Linux</strong> 2.4 kernel version you downloaded.<br />

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

archives.<br />

Once uncompressed, I recommend that you rename the directory from the stock "linux" name to<br />

"linux−2.4.x" (replace the "x" with the specific version of your newly installed kernel) for clarity. To<br />

do this, run the command "mv linux linux−2.4.x". Next, make sure there is a directory or<br />

symbolic link pointing to "/usr/src/kernel/linux" ie. run the command:<br />

ln −s /usr/src/kernel/linux−2.4.x /usr/src/kernel/linux<br />

again subsituting the "x" for your proper kernel version.<br />

• As mentioned above, you might consider applying any appropriate or optional patches to the kernel's<br />

MASQ code BEFORE you compile the final kernel. <strong>The</strong> <strong>IP</strong> MASQ code found in the stock kernels is<br />

already very useful and does not require any specific patching in order for the system to work for<br />

NAT−friendly network applications. Many of these patches are only to fix possible known bugs, add<br />

new features (some are /very/ cool), etc. Please refer to Section 2.6 for URLs and the <strong>IP</strong> <strong>Masquerade</strong><br />

Resources for up−to−date information and patch URLs.<br />

• Applying <strong>IP</strong>TABLES and Patch−o−Matic kernel patches<br />

Download the iptables package and optional Patch−O−matics from the Section 2.6 and put it into a<br />

directory, say "/usr/src/archive/netfilter". Next, go into this new netfilter directory and<br />

uncompress the iptables archive with the command:<br />

tar xyvf iptables−x.y.z.tar.bz2<br />

tar xyvf patch−o−matic−x.tar.bz2<br />

Now, go into the new iptables−x.y.x directory (/usr/src/archive/netfilter/iptables−x.y.z) and run the<br />

command<br />

#For iptables v1.2.7a:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 16


•<br />

make KERNEL_DIR=/usr/src/kernel/linux<br />

#For iptables v1.2.4 (when Patch−o−matic was built−in):<br />

make pending−patches KERNEL_DIR=/usr/src/kernel/linux<br />

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

directory.<br />

NOTE #2: If you append a "/" to the end of the above command line, you will get an error stating:<br />

"make: *** [/usr/src/kernel/linux/include/asm/socket.h] Error 1".<br />

Remove the trailing "/" and try again.<br />

Here is an example of compiling <strong>IP</strong>TABLES v1.2.7a. Your output might look different depending on<br />

what version you are trying to use.<br />

# make KERNEL_DIR=/usr/src/kernel/linux<br />

Extensions found:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

cc −O2 −Wall −Wunused −I/usr/src/kernel/linux/include −Iinclude/<br />

−D<strong>IP</strong>TABLES_VERSION=\"1.2.7a\" −fPIC −o extensions/libipt_ah_sh.o −c<br />

extensions/libipt_ah.c<br />

ld −shared −o extensions/libipt_ah.so extensions/libipt_ah_sh.o<br />

cc −O2 −Wall −Wunused −I/usr/src/kernel/linux/include −Iinclude/<br />

−D<strong>IP</strong>TABLES_VERSION=\"1.2.7a\" −fPIC −o extensions/libipt_conntrack_sh.o −c<br />

extensions/libipt_conntrack.c<br />

ld −shared −o extensions/libipt_conntrack.so extensions/libipt_conntrack_sh.o<br />

cc −O2 −Wall −Wunused −I/usr/src/kernel/linux/include −Iinclude/<br />

−D<strong>IP</strong>TABLES_VERSION=\"1.2.7a\" −fPIC −o extensions/libipt_dscp_sh.o −c<br />

extensions/libipt_dscp.c<br />

extensions/libipt_dscp_helper.c:69: warning: `dscp_to_name' defined but not<br />

used<br />

ld −shared −o extensions/libipt_dscp.so extensions/libipt_dscp_sh.o<br />

.<br />

.<br />

.<br />

cc −O2 −Wall −Wunused −I/usr/src/kernel/linux/include −Iinclude/<br />

−D<strong>IP</strong>TABLES_VERSION=\"1.2.7a\" −c −o libipulog/libipulog.o<br />

libipulog/libipulog.c<br />

ar rv libipulog/libipulog.a libipulog/libipulog.o<br />

a − libipulog/libipulog.o<br />

rm libiptc/libip6tc.o libiptc/libip4tc.o libipulog/libipulog.o libipq/libipq.o<br />

• Ok, hopefully the <strong>IP</strong>TABLES program compiled up for you. Now, you need to install it. To do this,<br />

directory and run the command<br />

make install KERNEL_DIR=/usr/src/kernel/linux<br />

• Here is an example of installing <strong>IP</strong>TABLES v1.2.7a. Your output might look different depending on<br />

what version you are trying to use.<br />

• # make install KERNEL_DIR=/usr/src/kernel/linux<br />

cp iptables /usr/local/sbin/iptables<br />

cp iptables−save /usr/local/sbin/iptables−save<br />

cp iptables−restore /usr/local/sbin/iptables−restore<br />

cp ip6tables /usr/local/sbin/ip6tables<br />

cp extensions/libipt_ah.so /usr/local/lib/iptables/libipt_ah.so<br />

cp extensions/libipt_conntrack.so /usr/local/lib/iptables/libipt_conntrack.so<br />

cp extensions/libipt_dscp.so /usr/local/lib/iptables/libipt_dscp.so<br />

cp extensions/libipt_ecn.so /usr/local/lib/iptables/libipt_ecn.so<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 17


cp extensions/libipt_esp.so /usr/local/lib/iptables/libipt_esp.so<br />

cp extensions/libipt_helper.so /usr/local/lib/iptables/libipt_helper.so<br />

.<br />

.<br />

.<br />

cp extensions/libip6t_udp.so /usr/local/lib/iptables/libip6t_udp.so<br />

cp extensions/libip6t_LOG.so /usr/local/lib/iptables/libip6t_LOG.so<br />

cp extensions/libip6t_MARK.so /usr/local/lib/iptables/libip6t_MARK.so<br />

Next, if you are interested in applying a Patch−O−Matic patch set, go into the patch−o−matic−X directory<br />

(/usr/src/archive/netfilter/patch−o−matic−X) and run the command<br />

•<br />

#For Patch−O−Matic later than the release of iptables v1.2.7a:<br />

KERNEL_DIR=/usr/src/kernel/linux<br />

./runme pending<br />

NOTE #1: <strong>The</strong> use of the "pending" batch is the most common for <strong>IP</strong>MASQ functionality but there<br />

are several others. See below.<br />

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

directory.<br />

NOTE #3: If you append a "/" to the end of the command line, you will get an error stating:<br />

"make: *** [/usr/src/kernel/linux/include/asm/socket.h] Error 1".<br />

Remove the trailing "/" and try again.<br />

Here is an example of the Patch−O−Matic prompts you might receive for a 2.4.20 kernel with the<br />

"20030107" Patch−O−Matic set. You can also run the "runme" program in a batch mode to speed<br />

things up, add experimental patches, etc. if you'd like. To better understand your options, simply run<br />

the "./runme" command by itself. Please note that these prompts WILL CHANGE over time.<br />

• Welcome to Rusty's Patch−o−matic!<br />

Each patch is a new feature: many have minimal impact, some do not.<br />

Almost every one has bugs, so I don't recommend applying them all!<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

Already applied: submitted/01_2.4.19<br />

submitted/02_2.4.20<br />

submitted/ipt_ULOG−mac_len−fix<br />

submitted/ipt_multiport−invfix<br />

pending/01_ip_conntrack_proto_tcp−lockfix<br />

pending/02_newnat−udp−helper<br />

pending/03_REJECT−fwspotting−phrack60−fix<br />

pending/04_ftp−conntrack−msg−fix<br />

Testing... 05_ECN−tcpchecksum−littleendian−fix.patch NOT APPLIED (1 rejects out<br />

of 1 hunks)<br />

<strong>The</strong> pending/05_ECN−tcpchecksum−littleendian−fix patch:<br />

Author: Patrick McHardy<br />

Status: Pending for kernel inclusion<br />

<strong>The</strong> 2.4.20 kernel included the new iptables 'ECN' target, enabling a<br />

selective<br />

ECN disable mechanism. Unfortunately there was a bug in the incremental<br />

TCP<br />

checksum update, resulting in broken TCP checksums on little endian<br />

machines.<br />

This patch fixes the Bug.<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 18


•<br />

Testing patch pending/05_ECN−tcpchecksum−littleendian−fix.patch...<br />

Patch pending/05_ECN−tcpchecksum−littleendian−fix.patch applied cleanly.<br />

Applying patch pending/05_ECN−tcpchecksum−littleendian−fix.patch...<br />

Patch pending/05_ECN−tcpchecksum−littleendian−fix.patch applied cleanly.<br />

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

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

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

towards the bottom of the screen. Beyond that, you don't have to install anything at this point. <strong>The</strong><br />

next step is to compile the new PATCHED kernel.<br />

• Ok, now the new kernel is ready to be compiled but you should make sure that you also have the<br />

proper matching iptables program on your machine too (just to make sure). Run the command:<br />

♦ whereis iptables<br />

and make sure its installed on the machine (the default place is in<br />

/usr/local/sbin/iptables. If you cannot find it or patched up your kernel sources as shown<br />

above, I recommend you just re−compile it up as shown above.<br />

Now that the kernel sources are patched up, you need to configure it to know what kinds of features you need<br />

(HD support, Networking support, MASQ support, etc.). Here are the MINIMUM kernel configuration<br />

options required to enable <strong>IP</strong> <strong>Masquerade</strong> functionality. Please understand that this <strong>HOWTO</strong> illustrates just<br />

ONE way to configure and compile a kernel (modules vs static). <strong>The</strong> main difference from this example vs. an<br />

example given by a different MASQ guide is that some people might wish to compile kernel components<br />

either as modules OR monolithically into the kernel. Basically, compiling things as modules gives you added<br />

flexibility to what is or isn't installed into the kernel (reduces unneeded memory use for things you aren't /<br />

won't use and modules also allow for drop−in software upgrades [usually no need to reboot the machine]). On<br />

the flip side, kernel modules add more complexity to your configuration and sometimes the kernel<br />

auto−loader might make mistakes (not that I've ever seen this happen). Compiling things directly into the<br />

kernel makes things simpler BUT you loose a huge level of flexibility. <strong>The</strong> following kernel configuration<br />

example is a mixture of both a selection of kernel modules and building them in monolithically (you probably<br />

will ALWAYS need MASQ functionality ready to go).<br />

• Side Note: It is assumed that you will also configure the kernel to use your other installed hardware<br />

such as USB printers, Ethernet network interfaces, SCSI and IDE HD controllers, etc. as well. Please<br />

refer to the <strong>Linux</strong> Kernel <strong>HOWTO</strong> and the kernel source's "README" file and "<strong>Documentation</strong>/"<br />

directory for detailed help on compiling a kernel.<br />

You will need to answer either YES, NO, or MODULE to the following program. Not all options will be<br />

available without the proper kernel patches described later in this <strong>HOWTO</strong>. This shouldn't be an issue as most<br />

3rd party patches are only needed for a very select group of users.<br />

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

• cd /usr/src/kernel/linux<br />

• make menuconfig<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Please note the following kernel prompts reflect a 2.4.14 kernel (with some of the optional Patch−O−Matic<br />

additions. Please read the following carefully for recommendations:<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 19


[ Code maturity level options ]<br />

* Prompt for development and/or incomplete code/drivers (CONFIG_EXPERIMENTAL) [Y/n/?]<br />

− YES: though not required for <strong>IP</strong> MASQ, this option allows the kernel to create<br />

the MASQ modules and enable the option for port forwarding<br />

* Enable loadable module support (CONFIG_MODULES) [Y/n/?]<br />

− YES: allows you to load kernel <strong>IP</strong> MASQ modules<br />

* Set version information on all module symbols (CONFIG_MODVERSIONS) [Y/n/?]<br />

− YES: allows newer kernels to load older modules if possible<br />

* Kernel module loader (CONFIG_KMOD) [Y/n/?]<br />

− OPTIONAL: Recommended : allows the kernel to load various kernel modules as it needs them<br />

== Non−MASQ options skipped<br />

== (CPU type, memory, SMP, FPU, specific stuff)<br />

[ General setup ]<br />

* Networking support (CONFIG_NET) [Y/n/?]<br />

− YES: Enables the network subsystem<br />

== Non−MASQ options skipped<br />

== (specific hardware, PCI, kernel binaries, PCMCIA, etc.)<br />

* Sysctl support (CONFIG_SYSCTL) [Y/n/?]<br />

− YES: Enables the ability to enable disable options such as forwarding,<br />

dynamic <strong>IP</strong>s, etc. via the /proc interface<br />

[ Block devices ]<br />

== Non−MASQ options skipped<br />

== (kernel binaries, power management, PnP, RAID, etc.)<br />

== Don't forget to compile in support for hardware that you might need:<br />

== IDE controllers, HDs, CDROMs, etc.<br />

[ Networking options ]<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

* Packet socket (CONFIG_PACKET) [Y/m/n/?]<br />

− YES: Though this is OPTIONAL, this recommended feature will allow you<br />

to use TCPDUMP to debug any problems with <strong>IP</strong> MASQ<br />

* Packet socket: mmapped IO (CONFIG_PACKET_MMAP) [N/y/?] y<br />

− YES: Speed up the packet protocol<br />

* Kernel/User netlink socket (CONFIG_NETLINK) [Y/n/?]<br />

− OPTIONAL: Recommended : this feature will allow the logging of<br />

advanced firewall issues such as routing messages, etc<br />

* Routing messages (CONFIG_RTNETLINK) [N/y/?] (NEW) y<br />

− OPTIONAL: Allows for support of advanced kernel routing messages<br />

if you enabled the CONFIG_NETLINK option<br />

* Netlink device emulation (CONFIG_NETLINK_DEV) [N/y/m/?] (NEW)<br />

− NO: This option does not have anything to do with packet firewall<br />

logging<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 20


* Network packet filtering (replaces ipchains) (CONFIG_NETFILTER) [N/y/?] y<br />

− YES: Enable this option to let <strong>IP</strong>TABLES configure the TCP/<strong>IP</strong> subsection<br />

of the kernel. By enabling this, then you can turn on advanced<br />

routing mechanisms like <strong>IP</strong> Masq, packet filtering, etc.<br />

* Network packet filtering debugging (CONFIG_NETFILTER_DEBUG) [N/y/?] (NEW) n<br />

− NO: Not required for Masquerading functionality though it may help<br />

for troubleshooting. <strong>The</strong>re might be a performance penalty when<br />

enabling this.<br />

* Socket Filtering (CONFIG_FILTER) [Y/n/?]<br />

− OPTIONAL: Recommended : Though this doesn't have anything do with <strong>IP</strong>MASQ,<br />

if you plan on implimenting a DHCP server on the internal network, you WILL<br />

need to enable this option.<br />

* Unix domain sockets (CONFIG_UNIX) [Y/m/n/?]<br />

− YES: This enables the UNIX TCP/<strong>IP</strong> sockets mechanisms<br />

* TCP/<strong>IP</strong> networking (CONFIG_INET) [Y/n/?]<br />

− YES: Enables the TCP/<strong>IP</strong> protocol<br />

* <strong>IP</strong>: multicasting (CONFIG_<strong>IP</strong>_MULTICAST) [N/y/?]<br />

− OPTIONAL: You can enable this if you want to be able to receive<br />

Multicast traffic. Please note that your ISP must<br />

support Multicast as well for this all to work at all<br />

* <strong>IP</strong>: advanced router (CONFIG_<strong>IP</strong>_ADVANCED_ROUTER) [Y/n/?]<br />

− OPTIONAL: Though there is nothing in this section mandatory for<br />

<strong>Masquerade</strong>, some specific options might be useful<br />

== Non−MASQ options skipped<br />

== ( autoconf, tunneling )<br />

* <strong>IP</strong>: multicast routing (CONFIG_<strong>IP</strong>_MROUTE) [N/y/?] n<br />

− OPTIONAL: Though not needed for <strong>IP</strong>MASQ, enabling this feature will<br />

let you route multicast traffic through your <strong>Linux</strong> box.<br />

Please note that this requires that your ISP be multicast<br />

enabled as well.<br />

== Non−MASQ options skipped<br />

== (ARPd)<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

* <strong>IP</strong>: TCP Explicit Congestion Notification support (CONFIG_INET_ECN) [N/y/?] n<br />

− NO: Though enabling this option would be great, there are many Internet<br />

sites out there that will block this. Hit the "?" when configuring<br />

the kernel to learn more about it but it is recommended to say NO for<br />

now.<br />

* <strong>IP</strong>: TCP syncookie support (disabled per default) (CONFIG_SYN_COOKIES) [Y/n/?]<br />

− YES: Recommended : for basic TCP/<strong>IP</strong> network security<br />

[ Networking options −−> <strong>IP</strong>: Netfilter Configuration ]<br />

* Connection tracking (required for masq/NAT) (CONFIG_<strong>IP</strong>_NF_CONNTRACK) [N/y/m/?] (NEW) m<br />

− YES: (Module) This enables the kernel to track various network connections.<br />

This option is required for Masquerading support as well as to enable<br />

Stateful tracking for various filewall mechanisms. Please note that<br />

if you compile this directly into the kernel, you cannot enable<br />

the legacy <strong>IP</strong>CHAINS or <strong>IP</strong>FWADM compatibility modules.<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 21


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

* FTP protocol support (CONFIG_<strong>IP</strong>_NF_FTP) [M/n/?] (NEW) m<br />

− YES: (Module) This enables the proper Masquerading of FTP connections if<br />

CONFIG_<strong>IP</strong>_NF_CONNTRACK was enabled above<br />

* IRC protocol support (CONFIG_<strong>IP</strong>_NF_IRC) [M/n/?] (NEW) m<br />

− YES: (Module) This enables the proper Masquerading of IRC connections if<br />

CONFIG_<strong>IP</strong>_NF_CONNTRACK was enabled above<br />

* Userspace queueing via NETLINK (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_NF_QUEUE) [N/y/m/?] (NEW) m<br />

− OPTIONAL: Though this is OPTIONAL, this feature will allow <strong>IP</strong>TABLES to<br />

copy specific packets to UserSpace tools for additional checks<br />

* <strong>IP</strong> tables support (required for filtering/masq/NAT) (CONFIG_<strong>IP</strong>_NF_<strong>IP</strong>TABLES) [N/y/m/?] (NEW) m<br />

− YES: (Module) Enables <strong>IP</strong>TABLES support<br />

* limit match support (CONFIG_<strong>IP</strong>_NF_MATCH_LIMIT) [N/y/m/?] (NEW) y<br />

− OPTIONAL: (Module) Recommended : Though not required, this option can used to<br />

enable rate limiting of both traffic and loggin messages help slow down denial<br />

of service (DoS) attacks.<br />

* MAC address match support (CONFIG_<strong>IP</strong>_NF_MATCH_MAC) [N/y/m/?] (NEW) m<br />

− OPTIONAL: Though not required, the option can allow you to<br />

filter traffic based upon the SOURCE Ethernet MAC address.<br />

* netfilter MARK match support (CONFIG_<strong>IP</strong>_NF_MATCH_MARK) [N/y/m/?] (NEW) y<br />

− YES: (Module) Recommended : This enables <strong>IP</strong>TABLES to take action upon marked packets.<br />

This mechanism can allow for PORTFW functionality, TOS marking, etc.<br />

* Multiple port match support (CONFIG_<strong>IP</strong>_NF_MATCH_MULT<strong>IP</strong>ORT) [N/y/m/?] (NEW) y<br />

− YES: (Module) Recommended : This enables <strong>IP</strong>TABLES to accept mutliple SRC/DST port<br />

ranges (non−contiguous) instead of one port range per <strong>IP</strong>TABLES<br />

statement.<br />

* TOS match support (CONFIG_<strong>IP</strong>_NF_MATCH_TOS) [Y/m/n/?] n<br />

− OPTIONAL: This allows <strong>IP</strong>TABLES to match packets based upon their<br />

DIFFSERV settings.<br />

* LENGTH match support (CONFIG_<strong>IP</strong>_NF_MATCH_LENGTH) [N/m/?] (NEW) n<br />

− OPTIONAL: This allows <strong>IP</strong>TABLES to match packets based upon their<br />

packet length.<br />

* TTL match support (CONFIG_<strong>IP</strong>_NF_MATCH_TTL) [N/m/?] (NEW) ? n<br />

− OPTIONAL: This allows <strong>IP</strong>TABLES to match packets based upon their<br />

TTL settings.<br />

* tcpmss match support (CONFIG_<strong>IP</strong>_NF_MATCH_TCPMSS) [N/y/m/?] m<br />

− OPTIONAL: (Module) Recommended : This option allows users to examine the MSS value in<br />

TCP SYN packets. This is an advanced knob but can be very valuable in<br />

troubleshooting MTU problems.<br />

* Connection state match support (CONFIG_<strong>IP</strong>_NF_MATCH_STATE) [M/n/?] m<br />

− YES: (Module) Recommended : This option allows for Stateful tracking of network<br />

connections.<br />

* Unclean match support (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_NF_MATCH_UNCLEAN) [N/y/m/?] y<br />

− YES: (Module) Recommended : This option allows for connection tracking on odd packets.<br />

It cal also help in the detection of possibly malicious packets.<br />

This can be a valuable tool in tracking hostile people on the network.<br />

* Owner match support (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_NF_MATCH_OWNER) [N/y/m/?] n<br />

− OPTIONAL: This option allows <strong>IP</strong>TABLES to match traffic based upon the<br />

user login, group, etc. who created the traffic.<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 22


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

* Packet filtering (CONFIG_<strong>IP</strong>_NF_FILTER) [N/y/m/?] ? y<br />

− YES: (Module) This option allows for the kernel to be able filter traffic at<br />

the INPUT, FORWARDING, and OUTPUT traffic points.<br />

* REJECT target support (CONFIG_<strong>IP</strong>_NF_TARGET_REJECT) [N/y/m/?] (NEW) y<br />

− YES: (Module) With this option, a packet firewall can send an ICMP Reject packet<br />

back to the originator when a packet is blocked.<br />

* MIRROR target support (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_NF_TARGET_MIRROR) [N/y/m/?] (NEW) n<br />

− OPTIONAL: This option allows the packet firewall to mirror the exact same<br />

network packet back to the originator when it is supposed to be<br />

blocked. This is similar to the REJECT option above but it actually<br />

sends the original packet back to the originator. i.e. a<br />

hostile user could actually portscan themselves.<br />

* Full NAT (CONFIG_<strong>IP</strong>_NF_NAT) [M/n/?] m<br />

− YES: (Module) This option enables the future menus to enable Masquerading,<br />

PORTFWing, Full (1:1) NAT, etc.<br />

* MASQUERADE target support (CONFIG_<strong>IP</strong>_NF_TARGET_MASQUERADE) [M/n/?] (NEW) m<br />

− YES: (Module) This option specifically enables <strong>Masquerade</strong> into the<br />

kernel<br />

* REDIRECT target support (CONFIG_<strong>IP</strong>_NF_TARGET_REDIRECT) [N/y/m/?] n<br />

− OPTIONAL: Not needed for normal MASQ functionality though people who<br />

want to do transparent proxy via Squid will want this.<br />

* Basic SNMP−ALG support (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_NF_NAT_SNMP_BASIC) [N/m/?] n<br />

− OPTIONAL: This enables <strong>IP</strong>TABLES to properly NAT internal SNMP packets so<br />

that machines with duplicate addressing ranges can be properly<br />

managed.<br />

* Packet mangling (CONFIG_<strong>IP</strong>_NF_MANGLE) [N/y/m/?] y<br />

− YES: (Module) This option allows for advanced <strong>IP</strong>TABLES packet manipulation<br />

options.<br />

* TOS target support (CONFIG_<strong>IP</strong>_NF_TARGET_TOS) [N/y/m/?] (NEW) n<br />

− OPTIONAL: Enables the kernel to modify the TOS field in a packet<br />

before routing it on<br />

* MARK target support (CONFIG_<strong>IP</strong>_NF_TARGET_MARK) [N/y/m/?] (NEW) m<br />

− OPTIONAL: (Module) Recommended : This enables the kernel to manipulate<br />

packets based upon the MARK field. This can be used for PORTFW<br />

as well as many other things.<br />

* LOG target support (CONFIG_<strong>IP</strong>_NF_TARGET_LOG) [N/y/m/?] m<br />

− YES: (Module) This allows for the logging of packets before they are accepted,<br />

denied, rejected, etc.<br />

* TCPMSS target support (CONFIG_<strong>IP</strong>_NF_TARGET_TCPMSS) [N/y/m/?] ? m<br />

− YES: (Module) This option help some people with MTU problems. Typically,<br />

most users have to set their Internet connection's MTU to<br />

1500 as well as ALL internal machines to 1500. With this<br />

option, this whole MTU issue might be finally solved.<br />

* ipchains (2.2−style) support (CONFIG_<strong>IP</strong>_NF_COMPAT_<strong>IP</strong>CHAINS) [N/y/m/?] m<br />

− OPTIONAL: (Module) Recommended : If you have an existing <strong>IP</strong>CHAINS ruleset<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 23


(2.2.x kernels) and enable this option, you can continue to use the<br />

<strong>IP</strong>CHAINS program and the majority of your old ruleset except for the<br />

use of any 2.2.x kernel−specific modules. Please note that if this<br />

<strong>IP</strong>CHAINS module is loaded, ALL <strong>IP</strong>TABLES modules will be non−<br />

operational. This is an either/or deal only intended for legacy<br />

rulesets.<br />

* ipfwadm (2.0−style) support (CONFIG_<strong>IP</strong>_NF_COMPAT_<strong>IP</strong>FWADM) [N/y/m/?] n<br />

− OPTIONAL: If you have an existing <strong>IP</strong>FWADM ruleset (2.0.x kernels) and<br />

enable this option, you can continue to use the <strong>IP</strong>FWADM program and<br />

the majority of your old ruleset except for the use of any 2.0.x<br />

kernel−specific modules. Please note that if this <strong>IP</strong>FWADM module<br />

is loaded, ALL <strong>IP</strong>TABLES modules will be non operational. This is<br />

an either/or deal only intended to support legacy rulesets.<br />

== Non−MASQ options skipped<br />

== (<strong>IP</strong>v6, khttpd, ATM, <strong>IP</strong>X, AppleTalk, etc.) −−<br />

* Fast switching (read help!) (CONFIG_NET_FASTROUTE) [N/y/?] n<br />

− NO: This performance optimization is NOT compatible with <strong>IP</strong> MASQ and/or<br />

packet filtering<br />

== Non−MASQ options skipped<br />

== (QoS, Telephony, IDE, SCSI, 1394FW, I2O, etc)<br />

== Don't forget to compile in support for hardware that you might need:<br />

== IDE: HDs, CDROMs, etc.<br />

== SCSI: HDs, CDROMs, etc.<br />

[ Network device support ]<br />

* Network device support (CONFIG_NETDEVICES) [Y/n/?]<br />

− YES: Enables the <strong>Linux</strong> Network device sublayer<br />

== Non−MASQ options skipped<br />

== (Arcnet)<br />

* Dummy net driver support (CONFIG_DUMMY) [M/n/y/?]<br />

− YES: Though OPTIONAL, this option can help when debugging problems<br />

== Non−MASQ options skipped<br />

== (EQL, etc..)<br />

== Don't forget to compile in support for hardware that you might need:<br />

== NICs: eth, tr, etc.<br />

== MODEMs: ppp (ppp async) and/or slip<br />

== WANs: T1, T3, ISDN, etc.<br />

== ISDN: for internal ISDN modems<br />

== Non−MASQ options skipped<br />

== (Amateur Radio, IrDA, ISDN, USB, etc.)<br />

[ Character devices ]<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

== Don't forget to compile in serial port support if you are a modem user<br />

== Don't forget to compile in mouse support<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 24


== Non−MASQ options skipped<br />

== (I2C, Watchdog cards, Ftape, Video for <strong>Linux</strong>, etc. )<br />

[ File systems ]<br />

== Non−MASQ options skipped<br />

== (Quota, ISO9660, NTFS, etc )<br />

* /proc filesystem support (CONFIG_PROC_FS) [Y/n/?]<br />

− YES: Required to dynamically configure the <strong>Linux</strong> forwarding<br />

and NATing systems<br />

== Non−MASQ options skipped<br />

== (Console drivers, Sound, USB, Kernel Hacking)<br />

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

NOTE: <strong>The</strong>se are just the kernel components you need for <strong>IP</strong> <strong>Masquerade</strong> networking support. You will need<br />

to select whatever other options needed for your specific setup. If you want more information on what each<br />

one of these kernel modules does, please see the FAQ section of this <strong>HOWTO</strong> for details.<br />

• Now compile the kernel (make dep; make clean; make bzImage; make modules; make<br />

modules_install) , etc. Again, it is beyond the scope of this <strong>HOWTO</strong> if you have problems compiling<br />

your kernel. Please see Section 2.6 for URLs to the KERNEL howto, etc.<br />

• You will then have move over the kernel binary, update your bootloader (LILO, Grub, etc.), and<br />

reboot. If you have questions about kernel compiling, I highly recommend to consult some of the<br />

URLs mentioned above in this section.<br />

3.2.2. Compiling <strong>Linux</strong> 2.2.x Kernels<br />

Please see Section 2.7 for any required software, patches, etc.<br />

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

•<br />

♦ NOTE #1: −−− UPDATE YOUR KERNEL −−− <strong>Linux</strong> 2.2.x kernels less than version 2.2.20<br />

contain several different security vulnerabilities (some were MASQ specific). Kernels less<br />

than 2.2.20 have a few local vulnerabilities. Kernel versions less than 2.2.16 have a TCP root<br />

exploit vulnerability and versions less than 2.2.11 have a <strong>IP</strong>CHAINS fragmentation bug.<br />

Because of these issues, users running a firewall with strong <strong>IP</strong>CHAINS rulesets are open to<br />

possible instrusion. Please upgrade your kernel to a fixed version.<br />

♦ NOTE #2: As the 2.2.x train progressed, the compile−time options keep on changing. As of<br />

this version, this section reflects the settings for a 2.2.20 kernel.<br />

If you are running either a newer or older kernel version, the dialogs will look different. It is<br />

recommended that you update to the newest kernel for added capability and stability of the<br />

system.<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

If this is your first time compiling the kernel, don't be scared. In fact, it's rather easy and it's covered<br />

in several URLs found in Section 2.7. Please note that the instructions included here is just one way to<br />

do build a kernel. Please see the Kernel <strong>HOWTO</strong> for full details.<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 25


•<br />

NOTE: Please notice that it isn't recommended to put the new kernel sources into /usr/src/linux. You<br />

should leave the original kernel sources that came with your <strong>Linux</strong> distribution in /usr/src/linux. For<br />

more details on this topic, please read the "README" file in the top level directory of your kernel<br />

sources.<br />

For this <strong>HOWTO</strong> example, create a directory called /usr/src/kernel. Next, "cd" into this<br />

directory and download the newest 2.2.x kernel sources into it. Once downloaded, issue the following<br />

command (if the file ends in a .tar.gz): tar xvzf linux−2.2.x.tar.gz or (if the file ends in a<br />

.tar.bzip2): tar xyvf linux−2.2.x.tar.bz2. Please substitute the "x" in the 2.2.x filename<br />

with the <strong>Linux</strong> 2.2 kernel version you downloaded.<br />

NOTE: Some <strong>Linux</strong> distributions use the "I" option instead of the "y" option to decompress bzip2<br />

archives.<br />

Once uncompressed, I recommend that you rename the directory from "linux" to "linux−2.2.x" for<br />

clarity. To do this, run the command mv linux linux−2.2.x. Next, make sure there is a<br />

directory or symbolic link pointing to /usr/src/kernel/linux ie. run the command: ln −s<br />

/usr/src/kernel/linux−2.2.x /usr/src/kernel/linuxo again subsituting the "x"<br />

for your proper kernel version.<br />

• Apply any appropriate or optional patches to the kernel source code. By default, stock <strong>Linux</strong> kernels<br />

do not require any specific patching in order for the system to work. Features like PPTP/<strong>IP</strong>SEC<br />

masqurading are already built−in in the newest kernels but other tools like Xwindows forwarders are<br />

optional. Please refer to Section 2.7 for URLs and the <strong>IP</strong> <strong>Masquerade</strong> Resources for up−to−date<br />

information and patch URLs.<br />

• Now that the kernel is patched up (if required), here are the MINIMUM kernel configuration options<br />

required to enable <strong>IP</strong> <strong>Masquerade</strong> functionality. Please understand that this <strong>HOWTO</strong> illustrates just<br />

ONE way to compile a kernel. <strong>The</strong> main difference from this method vs. a different one is some<br />

people wish to compile things either as modules OR monolithically right into the kernel. Basically,<br />

compiling things as modules gives you added flexibility to what is or isn't installed into the kernel<br />

(reduces unneeded memory use and allow for drop−in upgrades [no need to reboot]) BUT they add<br />

more complexity to your configuration. On the flip side, compiling things directly into the kernel<br />

makes things simpler BUT you loose a level of flexibility. <strong>The</strong> following example is a mixture of both<br />

built−in AND modules.<br />

Side Note: It is assumed that you will also configure the kernel to use your other installed hardware<br />

such as network interfaces, optional SCSI controllers, etc. as well. Please refer to the <strong>Linux</strong> Kernel<br />

<strong>HOWTO</strong> and the kernel source's README file and <strong>Documentation</strong>/ directory for detailed help on<br />

compiling a kernel.<br />

Please note the YES or NO ANSWERS to the following. Not all options will be available without the proper<br />

kernel patches described later in this <strong>HOWTO</strong>.<br />

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

• cd /usr/src/kernel/linux<br />

• make menuconfig<br />

<strong>The</strong> following kernel prompts reflect a 2.2.20 kernel:<br />

[ Code maturity level options ]<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

* Prompt for development and/or incomplete code/drivers (CONFIG_EXPERIMENTAL) [Y/n/?]<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 26


− YES: though not entirely required for <strong>IP</strong> MASQ, this option allows the kernel<br />

to create possible additional MASQ modules such as PORTFW, etc.<br />

== Non−MASQ options skipped<br />

== (CPU, memory, MTRR, SMP, etc.)<br />

[ Loadable module support ]<br />

* Enable loadable module support (CONFIG_MODULES) [Y/n/?] y<br />

− YES: allows you to load kernel <strong>IP</strong> MASQ modules<br />

* Set version information on all symbols for modules (CONFIG_MODVERSIONS) [N/y/?] y<br />

− YES: allows newer kernels to load older modules if possible<br />

* Kernel module loader (CONFIG_KMOD) [Y/n/?] y<br />

− OPTIONAL: Recommended : allows the kernel to load various kernel modules as<br />

it needs them<br />

[ General setup ]<br />

* Networking support (CONFIG_NET) [Y/n/?]<br />

− YES: This enables the network subsystem<br />

== Non−MASQ options skipped<br />

== (PCI, kernel binaries, specific hardware options, etc.)<br />

* Sysctl support (CONFIG_SYSCTL) [Y/n/?]<br />

− YES: Enables the ability to enable disable options such as forwarding,<br />

dynamic <strong>IP</strong>s, etc. via the /proc interface<br />

[ Block devices ]<br />

== Non−MASQ options skipped<br />

== (kernel binaries, power management, PnP, IDE, SCSI, etc.)<br />

== Don't forget to compile in support for hardware that you might need:<br />

== IDE controllers, HDs, CDROMs, etc.<br />

[ Networking options ]<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

* Packet socket (CONFIG_PACKET) [Y/m/n/?] y<br />

− YES: Though this is OPTIONAL, this recommended feature will allow you<br />

to use TCPDUMP to debug any problems with <strong>IP</strong> MASQ<br />

* Kernel/User netlink socket (CONFIG_NETLINK) [Y/n/?] y<br />

− OPTIONAL: Recommended : This feature will allow the logging of<br />

advanced firewall issues such as routing messages, etc<br />

* Routing messages (CONFIG_RTNETLINK) [Y/n/?] y<br />

− OPTIONAL: If you enabled the CONFIG_NETLINK option above, this option<br />

will send routing messages and other information to SYSLOG.<br />

* Netlink device emulation (CONFIG_NETLINK_DEV) [N/y/m/?] (NEW) n<br />

− NO: This option does not have anything to do with packet firewall<br />

logging<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 27


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

* Network firewalls (CONFIG_FIREWALL) [Y/n/?] y<br />

− YES: Enables the kernel to be comfigured by the <strong>IP</strong>CHAINS firewall tool<br />

* Socket Filtering (CONFIG_FILTER) [Y/n/?] y<br />

− OPTIONAL: Though this doesn't have anything do with <strong>IP</strong>MASQ, if you<br />

plan on implimenting a DHCP server on the internal network, you<br />

WILL need this option.<br />

* Unix domain sockets (CONFIG_UNIX) [Y/m/n/?] y<br />

− YES: This enables the UNIX TCP/<strong>IP</strong> sockets mechanisms<br />

* TCP/<strong>IP</strong> networking (CONFIG_INET) [Y/n/?] y<br />

− YES: Enables the TCP/<strong>IP</strong> protocol<br />

* <strong>IP</strong>: multicasting (CONFIG_<strong>IP</strong>_MULTICAST) [N/y/?] y<br />

− OPTIONAL: You can enable this if you want to be able to receive<br />

Multicast traffic. Please note that your ISP must<br />

support Multicast as well for this all to work<br />

* <strong>IP</strong>: advanced router (CONFIG_<strong>IP</strong>_ADVANCED_ROUTER) [Y/n/?] n<br />

− OPTIONAL: Though there is nothing in this section mandatory for<br />

<strong>Masquerade</strong>, some specific options might be useful<br />

* <strong>IP</strong>: kernel level autoconfiguration (CONFIG_<strong>IP</strong>_PNP) [N/y/?] ?<br />

− NO: Not needed for normal MASQ functionality<br />

* <strong>IP</strong>: firewalling (CONFIG_<strong>IP</strong>_FIREWALL) [Y/n/?] y<br />

− YES: This enables the kernel to support packet filtering, NAT, etc.<br />

* <strong>IP</strong>: firewall packet netlink device (CONFIG_<strong>IP</strong>_FIREWALL_NETLINK) [Y/n/?] n<br />

− OPTIONAL: Though this is OPTIONAL, this feature will allow <strong>IP</strong>CHAINS to<br />

copy some packets to UserSpace tools for additional checks<br />

* <strong>IP</strong>: transparent proxy support (CONFIG_<strong>IP</strong>_TRANSPARENT_PROXY) [N/y/?] n<br />

− OPTIONAL: Not needed for normal MASQ functionality though people who<br />

want to do transparent proxy via Squid will want this. Please note<br />

that there is a PERFORMANCE PENALTY enabling this feature.<br />

* <strong>IP</strong>: masquerading (CONFIG_<strong>IP</strong>_MASQUERADE) [Y/n/?] y<br />

− YES: Enable <strong>IP</strong> <strong>Masquerade</strong> to re−address specific internal to external<br />

TCP/<strong>IP</strong> packets<br />

* <strong>IP</strong>: ICMP masquerading (CONFIG_<strong>IP</strong>_MASQUERADE_ICMP) [Y/n/?] y<br />

− YES: Enable support for masquerading ICMP ping packets (ICMP error<br />

codes will be MASQed regardless). This is an important feature<br />

for troubleshooting connections.<br />

* <strong>IP</strong>: masquerading special modules support (CONFIG_<strong>IP</strong>_MASQUERADE_MOD) [Y/n/?] y<br />

− YES: Though OPTIONAL, this enables the option to later enable other<br />

modules like the PORTFW to give external computers a directly<br />

connection to specified internal MASQed machines.<br />

* <strong>IP</strong>: ipautofw masq support (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_MASQUERADE_<strong>IP</strong>AUTOFW) [N/y/m/?] n<br />

− NO: NOT recommended : <strong>IP</strong>autofw is a legacy method of port forwarding. It<br />

is mainly old code and has been found to have some issues.<br />

* <strong>IP</strong>: ipportfw masq support (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_MASQUERADE_<strong>IP</strong>PORTFW) [Y/m/n/?] y<br />

− OPTIONAL: Recommended : This enables PORTFW which allows external computers<br />

on the Internet to directly communicate to specified internal MASQed<br />

machines. This feature is typically used to allow access to internal<br />

SMTP, TELNET, and WWW servers. Please note that FTP port forwarding<br />

needs an additional patch, as described in the FAQ section of the MASQ<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 28


<strong>HOWTO</strong>. Please see the this FAQ section in the <strong>HOWTO</strong> for additional<br />

information.<br />

* <strong>IP</strong>: ip fwmark masq−forwarding support (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_MASQUERADE_MFW) [Y/m/n/?] y<br />

− OPTIONAL: This is a NEW method of performing PORTFW−like functionality which is<br />

similar to how the new 2.4.x kernels do things. With this option, <strong>IP</strong>CHAINS<br />

can mark packets that should have additional work done upon it. Using a<br />

UserSpace tool, much like <strong>IP</strong>MASQADM or <strong>IP</strong>PORFW, <strong>IP</strong>CHAINS would then<br />

do things like re−address the packets, change their TOS value, etc.<br />

Currently, this code is less tested than PORTFW but it looks promising.<br />

For now, this <strong>HOWTO</strong> recommends to use <strong>IP</strong>MASQADM and <strong>IP</strong>PORTFW. If you<br />

have specific thoughts or comments on MFW, please email dranch.<br />

* <strong>IP</strong>: optimize as a router not host (CONFIG_<strong>IP</strong>_ROUTER) [Y/n/?] y<br />

− YES: This optimizes the kernel for the network subsystem, though it<br />

isn't well known if this makes a siginificant performance difference<br />

or not.<br />

== Non−MASQ options skipped<br />

== ( autoconf, tunneling, GRE )<br />

* <strong>IP</strong>: multicast routing (CONFIG_<strong>IP</strong>_MROUTE) [N/y/?] n<br />

− OPTIONAL: Though not needed for <strong>IP</strong>MASQ, enabling this feature will<br />

let you route multicast traffic through your <strong>Linux</strong> box.<br />

Please note that this requires that your ISP be multicast<br />

enabled as well.<br />

== Non−MASQ options skipped<br />

== (Aliasing, ARPd)<br />

* <strong>IP</strong>: TCP syncookie support (disabled per default) (CONFIG_SYN_COOKIES) [Y/n/?]<br />

− YES: Recommended : for basic TCP/<strong>IP</strong> network security<br />

* <strong>IP</strong>: GRE tunnels over <strong>IP</strong> (CONFIG_NET_<strong>IP</strong>GRE) [N/y/m/?]<br />

− NO: This OPTIONAL selection is to enable PPTP and GRE tunnels through<br />

the <strong>IP</strong> MASQ box<br />

== Non−MASQ options skipped<br />

== (aliasing, ARPd)<br />

* <strong>IP</strong>: TCP syncookie support (not enabled per default) (CONFIG_SYN_COOKIES) [Y/n/?]<br />

− YES: HIGHLY recommended for basic TCP/<strong>IP</strong> network security<br />

== Non−MASQ options skipped<br />

== (RARP)<br />

* <strong>IP</strong>: Allow large windows (not recommended if


== (Slow CPU, Telephony, SCSI, I2O, etc. )<br />

== Don't forget to compile in support for hardware that you might need:<br />

== SCSI: HDs, CDROMs, etc.<br />

[ Network device support ]<br />

* Network device support (CONFIG_NETDEVICES) [Y/n/?]<br />

− YES: Enables the <strong>Linux</strong> Network device sublayer<br />

== Non−MASQ options skipped<br />

== (Arcnet)<br />

* Dummy net driver support (CONFIG_DUMMY) [M/n/y/?]<br />

− YES: Though OPTIONAL, this option can help when debugging problems<br />

== Non−MASQ options skipped<br />

== (EQL, NICs, Wireless, IrDA, ISDN, etc..)<br />

== Don't forget to compile in support for hardware that you might need:<br />

== NICs: eth, tr, etc.<br />

== MODEMs: ppp and/or slip<br />

== WANs: T1, T3, ISDN, etc.<br />

== ISDN: for internal ISDN modems<br />

[ Character devices ]<br />

== Don't forget to compile in serial port support for modem users<br />

== Don't forget to compile in mouse support<br />

== Non−MASQ options skipped<br />

== (I2C, Watchdog cards, Ftape, Video for <strong>Linux</strong>, USB, etc. )<br />

[ File systems ]<br />

== Non−MASQ options skipped<br />

== (Quota, ISO9660, NTFS, etc )<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

* /proc filesystem support (CONFIG_PROC_FS) [Y/n/?]<br />

− YES: Required to dynamically configure the <strong>Linux</strong> forwarding<br />

and NATing systems<br />

== Non−MASQ options skipped<br />

== (network fs, NLS, video section, sound, kernel hacking)<br />

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

NOTE: <strong>The</strong>se are just the components you need for <strong>IP</strong> <strong>Masquerade</strong>. You will need to select whatever other<br />

options needed for your specific setup.<br />

• Now compile the kernel (make dep; make clean; make bzImage; make modules; make<br />

modules_install) , etc. Again, it is beyond the scope of this <strong>HOWTO</strong> if you have problems compiling<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 30


your kernel. Please see Section 2.7 for URLs to the KERNEL howto, etc.<br />

• You will then have move over the kernel binary, update your bootloader (LILO, Grub, etc.), and<br />

reboot. If you have questions about kernel compiling, I highly recommend to consult some of the<br />

URLs above in this section.<br />

3.2.3. Compiling <strong>Linux</strong> 2.0.x Kernels<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Please see Section 2.8 for any required software, patches, etc.<br />

• First of all, you need the kernel source for 2.0.x (preferably the latest kernel version)<br />

♦ As the 2.0.x train progress, the compile−time options keep on changing. As of this version,<br />

this section reflects the settings for a 2.0.39 kernel.<br />

• If this is your first time compiling the kernel, don't be scared. In fact, it's rather easy and it's covered<br />

in several URLs found in Section 2.8. Please note that the instructions included here is just one way to<br />

do build a kernel. Please see the Kernel <strong>HOWTO</strong> for full details.<br />

NOTE: Please notice that it isn't recommended to put the new kernel sources into /usr/src/linux. You<br />

should leave the original kernel sources that came with your <strong>Linux</strong> distribution in /usr/src/linux. For<br />

more details on this topic, please read the "README" file in the top level directory of your kernel<br />

sources.<br />

• For this <strong>HOWTO</strong> example, create a directory called /usr/src/kernel. Next, "cd" into this<br />

directory and download the newest 2.0.x kernel sources into it. Once downloaded, issue the following<br />

command: tar xvzf linux−2.0.x.tar.gz . Please substitute the "x" in the 2.0.x filename<br />

with the <strong>Linux</strong> 2.0 kernel version you downloaded.<br />

Once uncompressed, I recommend that you rename the directory from "linux" to "linux−2.0.x" for<br />

clarity. To do this, run the command mv linux linux−2.0.x. Next, make sure there is a<br />

directory or symbolic link pointing to /usr/src/kernel/linux ie. run the command: ln −s<br />

/usr/src/kernel/linux−2.0.x /usr/src/kernel/linuxo again subsituting the "x"<br />

for your proper kernel version.<br />

• Apply any appropriate or optional patches to the kernel source code. By default, stock <strong>Linux</strong> kernels<br />

do not require any specific patching in order for the system to work. Features like <strong>IP</strong>PORTFW, PPTP,<br />

and Xwindows forwarders are optional but very useful. Please refer to Section 2.8 for URLs and the<br />

<strong>IP</strong> <strong>Masquerade</strong> Resources for up−to−date information and patch URLs.<br />

• Now that the kernel is patched up (if required), here are the MINIMUM kernel configuration options<br />

required to enable <strong>IP</strong> <strong>Masquerade</strong> functionality. Please understand that this <strong>HOWTO</strong> illustrates just<br />

ONE way to compile a kernel. <strong>The</strong> main difference from this method vs. a different one is some<br />

people wish to compile things either as modules OR monolithically right into the kernel. Basically,<br />

compiling things as modules gives you added flexibility to what is or isn't installed into the kernel<br />

(reduces unneeded memory use and allow for drop−in upgrades [no need to reboot]) BUT they add<br />

more complexity to your configuration. On the flip side, compiling things directly into the kernel<br />

makes things simpler BUT you loose a level of flexibility. <strong>The</strong> following example is a mixture of both<br />

built−in AND modules.<br />

Side Note: It is assumed that you will also configure the kernel to use your other installed hardware<br />

such as network interfaces, optional SCSI controllers, etc. as well. Please refer to the <strong>Linux</strong> Kernel<br />

<strong>HOWTO</strong> and the kernel source's "README" file and "<strong>Documentation</strong>/" directory for detailed<br />

help on compiling a kernel.<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 31


Please note the YES or NO ANSWERS to the following options. Not all options will be available without the<br />

proper kernel patches described later in this <strong>HOWTO</strong>:<br />

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

• cd /usr/src/kernel/linux<br />

• make menuconfig<br />

<strong>The</strong> following kernel prompts reflect a 2.0.39 kernel:<br />

[ Code maturity level options ]<br />

* Prompt for development and/or incomplete code/drivers (CONFIG_EXPERIMENTAL) [Y/n/?]<br />

− YES: this will allow you to later select the <strong>IP</strong> <strong>Masquerade</strong> feature code<br />

[ Loadable module support ]<br />

* Enable loadable module support (CONFIG_MODULES) [Y/n/?] y<br />

− YES: allows you to load kernel <strong>IP</strong> MASQ modules<br />

* Set version information on all module symbols (CONFIG_MODVERSIONS) [N/y/?] y<br />

− YES: allows newer kernels to load older modules if possible<br />

* Kernel daemon support (e.g. autoload of modules) (CONFIG_KERNELD) [N/y/?] y<br />

− OPTIONAL: Recommended : allows the kernel to load various kernel modules as<br />

it needs them<br />

[ General setup ]<br />

== Non−MASQ options skipped<br />

== (FPU, memory)<br />

* Networking support (CONFIG_NET) [Y/n/?] y<br />

− YES: Enables the network subsystem<br />

== Non−MASQ options skipped<br />

== (memory, PCI, binary format, APM, etc.)<br />

== Don't forget to compile in support for hardware that you might need:<br />

== IDE controllers, HDs, CDROMs, etc.<br />

[ Networking options ]<br />

* Network firewalls (CONFIG_FIREWALL) [Y/n/?] y<br />

− YES: Enables the <strong>IP</strong>FWADM firewall tool<br />

== Non−MASQ options skipped<br />

== (Aliasing)<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

* TCP/<strong>IP</strong> networking (CONFIG_INET) [Y/n/?] y<br />

− YES: Enables the TCP/<strong>IP</strong> protocol<br />

* <strong>IP</strong>: forwarding/gatewaying (CONFIG_<strong>IP</strong>_FORWARD) [N/y/?] y<br />

− YES: Enables <strong>Linux</strong> network packet forwarding and routing<br />

− Controlled by <strong>IP</strong>FWADM<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 32


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

* <strong>IP</strong>: multicasting (CONFIG_<strong>IP</strong>_MULTICAST) [N/y/?] y<br />

− OPTIONAL: You can enable this if you want to be able to receive<br />

Multicast traffic. Please note that your ISP must<br />

support Multicast as well for this all to work<br />

* <strong>IP</strong>: syn cookies (CONFIG_SYN_COOKIES) [Y/n/?] y<br />

− YES: HIGHLY recommended for basic network security<br />

* <strong>IP</strong>: firewalling (CONFIG_<strong>IP</strong>_FIREWALL) [Y/n/?] y<br />

− YES: Enable the packet firewall features<br />

* <strong>IP</strong>: firewall packet logging (CONFIG_<strong>IP</strong>_FIREWALL_VERBOSE) [Y/n/?] y<br />

− YES: Allows the kernel to report back on various packets traversing<br />

the firewall.<br />

* <strong>IP</strong>: masquerading (CONFIG_<strong>IP</strong>_MASQUERADE [Y/n/?] y<br />

− YES: Enable the kernel to perform <strong>IP</strong> MASQ NAT functionality<br />

* <strong>IP</strong>: ipautofw masquerade support (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_MASQUERADE_<strong>IP</strong>AUTOFW) [Y/n/?] n<br />

− NO: NOT Recommended : <strong>IP</strong>autofw is a legacy method of TCP/<strong>IP</strong> port forwarding.<br />

Though <strong>IP</strong>autofw works, <strong>IP</strong>PORTFW is a better choice.<br />

* <strong>IP</strong>: ipportfw masq support (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_MASQUERADE_<strong>IP</strong>PORTFW) [Y/n/?] y<br />

− YES: This option is ONLY AVAILABLE VIA A PATCH for the 2.0.x kernels.<br />

With this option, external computers on the Internet can directly<br />

communicate to specified internal MASQed machines. This feature is<br />

typically used to access internal SMTP, TELNET, and WWW servers.<br />

FTP port forwarding sometimes might require an additional patch as<br />

described in the FAQ section. Additional information on port<br />

forwarding is available in the Forwards section of this <strong>HOWTO</strong>.<br />

* <strong>IP</strong>: MS PPTP masq support (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_MASQUERADE_PPTP) [N/y/?] (NEW) n<br />

− OPTIONAL: Enabling this feature will allow internal MASQ clients to<br />

properly connect to PPTP servers on the Internet.<br />

* <strong>IP</strong>: MS PPTP Call ID masq support (CONFIG_<strong>IP</strong>_MASQUERADE_PPTP_MULTICLIENT) [N/y/?] (NEW) n<br />

− OPTIONAL: If you enabled the CONFIG_<strong>IP</strong>_MASQUERADE_PPTP above, this<br />

option will allow for multiple internal PPTP clients behind the MASQ<br />

server to communicate to the same PPTP server.<br />

* <strong>IP</strong>: MS PPTP masq debugging (DEBUG_<strong>IP</strong>_MASQUERADE_PPTP) [N/y/?] n<br />

− OPTIONAL: NOT recommended : This is not required for <strong>IP</strong> MASQ or MASQing PPTP<br />

connections unless you need additional troubleshooting help. If enabled,<br />

this can fill up your logs quickly.<br />

* <strong>IP</strong>: MS PPTP masq verbose debugging (DEBUG_<strong>IP</strong>_MASQUERADE_PPTP_VERBOSE) [N/y/?] (NEW) n<br />

− OPTIONAL: NOT Recommended : If you enabled the DEBUG_<strong>IP</strong>_MASQUERADE_PPTP<br />

option above, this will make the logging even more verbose.<br />

* <strong>IP</strong>: <strong>IP</strong>SEC ESP & ISAKMP masq support (EXPERIMENTAL) * (CONFIG_<strong>IP</strong>_MASQUERADE_<strong>IP</strong>SEC) [N/y/?] m<br />

− OPTIONAL: This option allows for some forms of <strong>IP</strong>SEC tunnels to be<br />

masquraded<br />

* <strong>IP</strong>: <strong>IP</strong>SEC masq table lifetime (minutes) (CONFIG_<strong>IP</strong>_MASQUERADE_<strong>IP</strong>SEC_EXPIRE) * [30] (NEW)<br />

− OPTIONAL: This feature allows to change the MASQ table timeouts so that<br />

idle <strong>IP</strong>SEC tunnels won't be prematurely disconnected.<br />

* <strong>IP</strong>: Disable inbound ESP destination guessing * (CONFIG_<strong>IP</strong>_MASQUERADE_<strong>IP</strong>SEC_NOGUESS) [N/y/?] n<br />

− OPTIONAL: This feature allows the kernel to guess where the fully encrypted <strong>IP</strong>SEC VPN<br />

might be going and add it to the MASQ table.<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 33


* <strong>IP</strong>: <strong>IP</strong>SEC masq debugging (DEBUG_<strong>IP</strong>_MASQUERADE_<strong>IP</strong>SEC) [N/y/?] ? n<br />

− OPTIONAL: NOT recommended : This is not required for <strong>IP</strong> MASQ or MASQing <strong>IP</strong>SEC<br />

connections unless you need additional troubleshooting help. If enabled,<br />

this can fill up your logs quickly.<br />

* <strong>IP</strong>: <strong>IP</strong>SEC masq verbose debugging (DEBUG_<strong>IP</strong>_MASQUERADE_<strong>IP</strong>SEC_VERBOSE) [N/y/?] (NEW) n<br />

− OPTIONAL: NOT Recommended : If you enabled the DEBUG_<strong>IP</strong>_MASQUERADE_<strong>IP</strong>SEC<br />

option above, this will make the logging even more verbose.<br />

* <strong>IP</strong>: ICMP masquerading (CONFIG_<strong>IP</strong>_MASQUERADE_ICMP) [Y/n/?]<br />

− YES: Enable support for masquerading ICMP packets. Though thought of as<br />

optional, many programs will NOT function properly with out ICMP<br />

support.<br />

* <strong>IP</strong>: transparent proxy support (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_TRANSPARENT_PROXY) [N/y/?] n<br />

− OPTIONAL: Not needed for normal MASQ functionality though people who<br />

want to do transparent proxy via Squid will want this. Please note<br />

that there is a PERFORMANCE PENALTY enabling this feature.<br />

* <strong>IP</strong>: loose UDP port managing (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_MASQ_LOOSE_UDP) [Y/n/?]<br />

− YES: This option is ONLY AVAILABLE VIA A PATCH for the 2.0.x kernels.<br />

With this option, internally masqueraded computers can play<br />

NAT−friendly games over the Internet. Explicit details are given<br />

in the FAQ section of this <strong>HOWTO</strong>.<br />

* <strong>IP</strong>: always defragment (CONFIG_<strong>IP</strong>_ALWAYS_DEFRAG) [Y/n/?]<br />

− YES: This feature optimizes <strong>IP</strong> MASQ connections<br />

== Non−MASQ options skipped<br />

== (Accounting)<br />

* <strong>IP</strong>: optimize as router not host (CONFIG_<strong>IP</strong>_ROUTER) [Y/n/?]<br />

− YES: This optimizes the kernel for the network subsystem<br />

== Non−MASQ options skipped<br />

== (Tunneling, Mcast routing, RARP, PMTU, etc.)<br />

* <strong>IP</strong>: Drop source routed frames (CONFIG_<strong>IP</strong>_NOSR) [Y/n/?]<br />

− YES: HIGHLY recommended for basic network security<br />

== Non−MASQ options skipped<br />

== (<strong>IP</strong>X, Bridging, SCSI, etc.)<br />

== Don't forget to compile in support for hardware that you might need:<br />

== SCSI controllers, HDs, CDROMs, etc.<br />

[ Network device support ]<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

* Network device support (CONFIG_NETDEVICES) [Y/n/?]<br />

− YES: Enables the <strong>Linux</strong> Network device sublayer<br />

== Non−MASQ options skipped<br />

== (Dummy, EQL, PPP, SL<strong>IP</strong>, NICs, Wireless, etc.)<br />

== Don't forget to compile in support for hardware that you might need:<br />

== NICs: eth, tr, etc.<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 34


== MODEMs: ppp and/or slip<br />

== WANs: T1, T3, ISDN, etc.<br />

== ISDN: for internal ISDN modems<br />

[ File systems ]<br />

== Non−MASQ options skipped<br />

== (Quota, ISO9660, Codepages, NTFS, etc )<br />

* /proc filesystem support (CONFIG_PROC_FS) [Y/n/?]<br />

− YES: Required to dynamically configure the <strong>Linux</strong> forwarding<br />

and NATing systems<br />

[ Character devices ]<br />

== Non−MASQ options skipped<br />

== (multi−port serial, parallel, mice, Ftape, Sound, etc. )<br />

== Don't forget to compile in serial port support for modem users<br />

== Don't forget to compile in mouse support<br />

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

NOTE: <strong>The</strong>se are only components for <strong>IP</strong> <strong>Masquerade</strong> functionality. You may need to also select additional<br />

options to match your specific network and hardware setup.<br />

• Now compile the kernel (make dep; make clean; make bzImage; make modules; make<br />

modules_install) , etc. Again, it is beyond the scope of this <strong>HOWTO</strong> if you have problems compiling<br />

your kernel. Please see Section 2.8 for URLs to the KERNEL howto, etc.<br />

• You will then have move over the kernel binary, update your bootloader (LILO, Grub, etc.), and<br />

reboot. If you have questions about kernel compiling, I highly recommend to consult some of the<br />

URLs above in this section.<br />

3.3. Assigning Private Network <strong>IP</strong> Addresses to the Internal<br />

LAN<br />

Since all INTERNAL MASQed machines should NOT have official Internet assigned addressees, there must<br />

be a specific and accepted way to allocate addresses to those machines without conflicting with anyone else's<br />

Internet address.<br />

From the original <strong>IP</strong> <strong>Masquerade</strong> FAQ:<br />

RFC 1918 is the official document on which <strong>IP</strong> addresses are to be used in a non−connected or "private"<br />

network. <strong>The</strong>re are 3 blocks of numbers set aside specifically for this purpose.<br />

Section 3: Private Address Space<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

<strong>The</strong> Internet Assigned Numbers Authority (IANA) has reserved the<br />

following three blocks of the <strong>IP</strong> address space for private networks:<br />

10.0.0.0 − 10.255.255.255<br />

172.16.0.0 − 172.31.255.255<br />

192.168.0.0 − 192.168.255.255<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 35


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

We will refer to the first block as "24−bit block", the second as "20−bit<br />

block", and the third as "16−bit" block". Note that the first block is<br />

nothing but a single class A network number, while the second block is a set<br />

of 16 continuous class B network numbers, and the third block is a set of 255<br />

continuous class C network numbers.<br />

For the record, my preference is to use the 192.168.0.0 network with a 255.255.255.0 Class−C subnet mask<br />

and thus this <strong>HOWTO</strong> reflects this. Any of the above private networks are valid, but just be SURE to use the<br />

correct subnet−mask.<br />

So, if you're using a Class−C network, you should number your TCP/<strong>IP</strong> enabled machines as 192.168.0.1,<br />

192.168.0.2, 192.168.0.3, .., 192.168.0.x<br />

192.168.0.1 is usually set as the internal gateway or <strong>Linux</strong> MASQ machine which reaches the external<br />

network. Please note that 192.168.0.0 and 192.168.0.255 are the Network and Broadcast address respectively<br />

(these addresses are RESERVED). Avoid using these addresses on your machines or your network will not<br />

function properly.<br />

3.4. Configuring <strong>IP</strong> Forwarding Policies<br />

At this point, you should have your kernel and other required packages installed. All network <strong>IP</strong> addresses,<br />

gateway, and DNS addresses should be configured on your <strong>Linux</strong> MASQ server. If you don't know how to<br />

configure your <strong>Linux</strong> network cards, please consult the <strong>HOWTO</strong>s listed in either the 2.4.x Section 2.6, the<br />

2.2.x Section 2.7, or the 2.0.x Section 2.8.<br />

Now, the only thing left to do is to configure the <strong>IP</strong> firewalling tools to both FORWARD and<br />

MASQUERADE the appropriate packets to the correct machine.<br />

** This section ONLY provides the user with the bare minimum firewall ruleset to get <strong>IP</strong> Masquerading<br />

working.<br />

Once <strong>IP</strong> MASQ has been successfully tested (as described later in this <strong>HOWTO</strong>), please refer to the Stronger<br />

<strong>IP</strong>TABLES ruleset for 2.4.x kernels in Section 6.4.1, the Stronger <strong>IP</strong>CHAINS ruleset for 2.2.x kernels in<br />

Section 6.4.2, and the Stronger <strong>IP</strong>FWADM ruleset for 2.0.x kernels in Section 6.4.3. Please note that these<br />

stronger firewall rulesets are more of a template than anything else. For truly secure firewall rulesets, check<br />

out the the requirements section of the <strong>HOWTO</strong> ( 2.4.x − Section 2.6, 2.2.x − Section 2.7, 2.0.x − Section 2.8<br />

).<br />

Instead of manually typing one of these files by hand, I recommend to simply browse the Example directory<br />

or download an archive of all of these rc.firewall−* files.<br />

3.4.1. Configuring <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.6.x and 2.4.x Kernels<br />

Please note that <strong>IP</strong>CHAINS is no longer the primary firewall configuration tool for the 2.6.x and 2.4.x<br />

kernels. <strong>The</strong> new kernels now use the <strong>IP</strong>TABLES toolkit though the new 2.4.x kernels CAN still run most old<br />

<strong>IP</strong>CHAINS or <strong>IP</strong>FWADM rulesets via a compatiblity module. It should also be noted that when running in<br />

this compatibility mode, NO <strong>IP</strong>TABLES modules can be loaded. <strong>The</strong> reason for this is that none of the 2.2.x<br />

<strong>IP</strong>MASQ modules are compatible with 2.4.x kernels. For a more detailes for these changes, please see the<br />

Section 7.40 section.<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 36


Ok, as mentioned before, the /etc/rc.d/rc.local−* script can be loaded once after every reboot. <strong>The</strong><br />

mechanism to load the script varies between different <strong>Linux</strong> distros (please see below for some exampels).<br />

<strong>The</strong> rc.firewall−iptables script will load all required <strong>IP</strong>MASQ modules as well as enable the final <strong>IP</strong>MASQ<br />

functionality. For advanced setups, this same file would contain very secure firewall rulesets as well.<br />

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

<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#!/bin/sh<br />

#<br />

# rc.firewall−iptables<br />

FWVER=0.76<br />

#<br />

# Initial SIMPLE <strong>IP</strong> <strong>Masquerade</strong> test for 2.6 / 2.4 kernels<br />

# using <strong>IP</strong>TABLES.<br />

#<br />

# Once <strong>IP</strong> Masquerading has been tested, with this simple<br />

# ruleset, it is highly recommended to use a stronger<br />

# <strong>IP</strong>TABLES ruleset either given later in this <strong>HOWTO</strong> or<br />

# from another reputable resource.<br />

#<br />

#<br />

#<br />

# Log:<br />

# 0.76 − Added comments on why the default policy is ACCEPT<br />

# 0.75 − Added more kernel modules to the comments section<br />

# 0.74 − the ruleset now uses modprobe vs. insmod<br />

# 0.73 − REJECT is not a legal policy yet; back to DROP<br />

# 0.72 − Changed the default block behavior to REJECT not DROP<br />

# 0.71 − Added clarification that PPPoE users need to use<br />

# "ppp0" instead of "eth0" for their external interface<br />

# 0.70 − Added commented option for IRC nat module<br />

# − Added additional use of environment variables<br />

# − Added additional formatting<br />

# 0.63 − Added support for the IRC <strong>IP</strong>TABLES module<br />

# 0.62 − Fixed a typo on the MASQ enable line that used eth0<br />

# instead of $EXTIF<br />

# 0.61 − Changed the firewall to use variables for the internal<br />

# and external interfaces.<br />

# 0.60 − 0.50 had a mistake where the ruleset had a rule to DROP<br />

# all forwarded packets but it didn't have a rule to ACCEPT<br />

# any packets to be forwarded either<br />

# − Load the ip_nat_ftp and ip_conntrack_ftp modules by default<br />

# 0.50 − Initial draft<br />

#<br />

echo −e "\n\nLoading simple rc.firewall−iptables version $FWVER..\n"<br />

# <strong>The</strong> location of the iptables and kernel module programs<br />

#<br />

# If your <strong>Linux</strong> distribution came with a copy of iptables,<br />

# most likely all the programs will be located in /sbin. If<br />

# you manually compiled iptables, the default location will<br />

# be in /usr/local/sbin<br />

#<br />

# ** Please use the "whereis iptables" command to figure out<br />

# ** where your copy is and change the path below to reflect<br />

# ** your setup<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 37


#<br />

#<strong>IP</strong>TABLES=/sbin/iptables<br />

<strong>IP</strong>TABLES=/usr/local/sbin/iptables<br />

DEPMOD=/sbin/depmod<br />

MODPROBE=/sbin/modprobe<br />

#Setting the EXTERNAL and INTERNAL interfaces for the network<br />

#<br />

# Each <strong>IP</strong> <strong>Masquerade</strong> network needs to have at least one<br />

# external and one internal network. <strong>The</strong> external network<br />

# is where the natting will occur and the internal network<br />

# should preferably be addressed with a RFC1918 private address<br />

# scheme.<br />

#<br />

# For this example, "eth0" is external and "eth1" is internal"<br />

#<br />

#<br />

# NOTE: If this doesnt EXACTLY fit your configuration, you must<br />

# change the EXTIF or INTIF variables above. For example:<br />

#<br />

# If you are a PPPoE or analog modem user:<br />

#<br />

# EXTIF="ppp0"<br />

#<br />

#<br />

EXTIF="eth0"<br />

INTIF="eth1"<br />

echo " External Interface: $EXTIF"<br />

echo " Internal Interface: $INTIF"<br />

#======================================================================<br />

#== No editing beyond this line is required for initial MASQ testing ==<br />

echo −en " loading modules: "<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# Need to verify that all modules have all required dependencies<br />

#<br />

echo " − Verifying that all kernel modules are ok"<br />

$DEPMOD −a<br />

# With the new <strong>IP</strong>TABLES code, the core MASQ functionality is now either<br />

# modular or compiled into the kernel. This <strong>HOWTO</strong> shows ALL <strong>IP</strong>TABLES<br />

# options as MODULES. If your kernel is compiled correctly, there is<br />

# NO need to load the kernel modules manually.<br />

#<br />

# NOTE: <strong>The</strong> following items are listed ONLY for informational reasons.<br />

# <strong>The</strong>re is no reason to manual load these modules unless your<br />

# kernel is either mis−configured or you intentionally disabled<br />

# the kernel module autoloader.<br />

#<br />

# Upon the commands of starting up <strong>IP</strong> Masq on the server, the<br />

# following kernel modules will be automatically loaded:<br />

#<br />

# NOTE: Only load the <strong>IP</strong> MASQ modules you need. All current <strong>IP</strong> MASQ<br />

# modules are shown below but are commented out from loading.<br />

# ===============================================================<br />

echo "−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−"<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 38


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#Load the main body of the <strong>IP</strong>TABLES module − "iptable"<br />

# − Loaded automatically when the "iptables" command is invoked<br />

#<br />

# − Loaded manually to clean up kernel auto−loading timing issues<br />

#<br />

echo −en "ip_tables, "<br />

$MODPROBE ip_tables<br />

#Load the <strong>IP</strong>TABLES filtering module − "iptable_filter"<br />

# − Loaded automatically when filter policies are activated<br />

#Load the stateful connection tracking framework − "ip_conntrack"<br />

#<br />

# <strong>The</strong> conntrack module in itself does nothing without other specific<br />

# conntrack modules being loaded afterwards such as the "ip_conntrack_ftp"<br />

# module<br />

#<br />

# − This module is loaded automatically when MASQ functionality is<br />

# enabled<br />

#<br />

# − Loaded manually to clean up kernel auto−loading timing issues<br />

#<br />

echo −en "ip_conntrack, "<br />

$MODPROBE ip_conntrack<br />

#Load the FTP tracking mechanism for full FTP tracking<br />

#<br />

# Enabled by default −− insert a "#" on the next line to deactivate<br />

#<br />

echo −en "ip_conntrack_ftp, "<br />

$MODPROBE ip_conntrack_ftp<br />

#Load the IRC tracking mechanism for full IRC tracking<br />

#<br />

# Enabled by default −− insert a "#" on the next line to deactivate<br />

#<br />

echo −en "ip_conntrack_irc, "<br />

$MODPROBE ip_conntrack_irc<br />

#Load the general <strong>IP</strong>TABLES NAT code − "iptable_nat"<br />

# − Loaded automatically when MASQ functionality is turned on<br />

#<br />

# − Loaded manually to clean up kernel auto−loading timing issues<br />

#<br />

echo −en "iptable_nat, "<br />

$MODPROBE iptable_nat<br />

#Loads the FTP NAT functionality into the core <strong>IP</strong>TABLES code<br />

# Required to support non−PASV FTP.<br />

#<br />

# Enabled by default −− insert a "#" on the next line to deactivate<br />

#<br />

echo −en "ip_nat_ftp, "<br />

$MODPROBE ip_nat_ftp<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 39


#Loads the IRC NAT functionality into the core <strong>IP</strong>TABLES code<br />

# Required to support NAT of IRC DCC requests<br />

#<br />

# Disabled by default −− remove the "#" on the next line to activate<br />

#<br />

#echo −e "ip_nat_irc"<br />

#$MODPROBE ip_nat_irc<br />

echo "−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−"<br />

# Just to be complete, here is a partial list of some of the other<br />

# <strong>IP</strong>TABLES kernel modules and their function. Please note that most<br />

# of these modules (the ipt ones) are automatically loaded by the<br />

# master kernel module for proper operation and don't need to be<br />

# manually loaded.<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

#<br />

# ip_nat_snmp_basic − this module allows for proper NATing of some<br />

# SNMP traffic<br />

#<br />

# iptable_mangle − this target allows for packets to be<br />

# manipulated for things like the TCPMSS<br />

# option, etc.<br />

#<br />

# −−<br />

#<br />

# ipt_mark − this target marks a given packet for future action.<br />

# This automatically loads the ipt_MARK module<br />

#<br />

# ipt_tcpmss − this target allows to manipulate the TCP MSS<br />

# option for braindead remote firewalls.<br />

# This automatically loads the ipt_TCPMSS module<br />

#<br />

# ipt_limit − this target allows for packets to be limited to<br />

# to many hits per sec/min/hr<br />

#<br />

# ipt_multiport − this match allows for targets within a range<br />

# of port numbers vs. listing each port individually<br />

#<br />

# ipt_state − this match allows to catch packets with various<br />

# <strong>IP</strong> and TCP flags set/unset<br />

#<br />

# ipt_unclean − this match allows to catch packets that have invalid<br />

# <strong>IP</strong>/TCP flags set<br />

#<br />

# iptable_filter − this module allows for packets to be DROPped,<br />

# REJECTed, or LOGged. This module automatically<br />

# loads the following modules:<br />

#<br />

# ipt_LOG − this target allows for packets to be<br />

# logged<br />

#<br />

# ipt_REJECT − this target DROPs the packet and returns<br />

# a configurable ICMP packet back to the<br />

# sender.<br />

#<br />

echo −e " Done loading modules.\n"<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 40


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#CRITICAL: Enable <strong>IP</strong> forwarding since it is disabled by default since<br />

#<br />

# Redhat Users: you may try changing the options in<br />

# /etc/sysconfig/network from:<br />

#<br />

# FORWARD_<strong>IP</strong>V4=false<br />

# to<br />

# FORWARD_<strong>IP</strong>V4=true<br />

#<br />

echo " Enabling forwarding.."<br />

echo "1" > /proc/sys/net/ipv4/ip_forward<br />

# Dynamic <strong>IP</strong> users:<br />

#<br />

# If you get your <strong>IP</strong> address dynamically from SL<strong>IP</strong>, PPP, or DHCP,<br />

# enable this following option. This enables dynamic−address hacking<br />

# which makes the life with Diald and similar programs much easier.<br />

#<br />

echo " Enabling DynamicAddr.."<br />

echo "1" > /proc/sys/net/ipv4/ip_dynaddr<br />

# Enable simple <strong>IP</strong> forwarding and Masquerading<br />

#<br />

# NOTE: In <strong>IP</strong>TABLES speak, <strong>IP</strong> Masquerading is a form of SourceNAT or SNAT.<br />

#<br />

# NOTE #2: <strong>The</strong> following is an example for an internal LAN address in the<br />

# 192.168.0.x network with a 255.255.255.0 or a "24" bit subnet mask<br />

# connecting to the Internet on external interface "eth0". This<br />

# example will MASQ internal traffic out to the Internet but not<br />

# allow non−initiated traffic into your internal network.<br />

#<br />

#<br />

# ** Please change the above network numbers, subnet mask, and your<br />

# *** Internet connection interface name to match your setup<br />

#<br />

#Clearing any previous configuration<br />

#<br />

# Unless specified, the defaults for INPUT and OUTPUT is ACCEPT<br />

# <strong>The</strong> default for FORWARD is DROP (REJECT is not a valid policy)<br />

#<br />

# Isn't ACCEPT insecure? To some degree, YES, but this is our testing<br />

# phase. Once we know that <strong>IP</strong>MASQ is working well, I recommend you run<br />

# the rc.firewall−*−stronger rulesets which set the defaults to DROP but<br />

# also include the critical additional rulesets to still let you connect to<br />

# the <strong>IP</strong>MASQ server, etc.<br />

#<br />

echo " Clearing any existing rules and setting default policy.."<br />

$<strong>IP</strong>TABLES −P INPUT ACCEPT<br />

$<strong>IP</strong>TABLES −F INPUT<br />

$<strong>IP</strong>TABLES −P OUTPUT ACCEPT<br />

$<strong>IP</strong>TABLES −F OUTPUT<br />

$<strong>IP</strong>TABLES −P FORWARD DROP<br />

$<strong>IP</strong>TABLES −F FORWARD<br />

$<strong>IP</strong>TABLES −t nat −F<br />

echo " FWD: Allow all connections OUT and only existing and related ones IN"<br />

$<strong>IP</strong>TABLES −A FORWARD −i $EXTIF −o $INTIF −m state −−state ESTABLISHED,RELATED −j ACCEPT<br />

$<strong>IP</strong>TABLES −A FORWARD −i $INTIF −o $EXTIF −j ACCEPT<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 41


$<strong>IP</strong>TABLES −A FORWARD −j LOG<br />

echo " Enabling SNAT (MASQUERADE) functionality on $EXTIF"<br />

$<strong>IP</strong>TABLES −t nat −A POSTROUTING −o $EXTIF −j MASQUERADE<br />

echo −e "\nrc.firewall−iptables v$FWVER done.\n"<br />

<br />

Once you are finished with editing this /etc/rc.d/rc.firewall−iptables ruleset, make it executable by typing in<br />

chmod 700 /etc/rc.d/rc.firewall−iptables<br />

Now that the firewall ruleset is ready, you need to let it run after every reboot. You could either do this by<br />

running it by hand everytime (such a pain) or add it to the boot scripts. We have covered two methods below:<br />

Redhat (SyS−V style) and Slackware (BSD style)<br />

1. Redhat and Redhat−derived distros:<br />

•<br />

<strong>The</strong>re are two ways to automatically load things in Redhat: /etc/rc.d/rc.local or a init script in<br />

/etc/rc.d/init.d/. <strong>The</strong> first method is the easiest but isn't doing things the SYS−V way. All you have to<br />

do is add the line:<br />

echo "Loading the rc.firewall−iptables ruleset.. "<br />

/etc/rc.d/rc.firewall−iptables<br />

to the end of the /etc/rc.d/rc.local file and thats it (as described earlier in the <strong>HOWTO</strong>).<br />

<strong>The</strong> problem with this approach is that the firewall isn't executed until the last stages of booting.<br />

• <strong>The</strong> preferred approach is to have the firewall loaded just after the networking subsystem is loaded.<br />

To do this, copy the following file into the /etc/rc.d/init.d directory:<br />

<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#!/bin/sh<br />

#<br />

# chkconfig: 2345 11 89<br />

#<br />

# description: Loads the rc.firewall−iptables ruleset.<br />

#<br />

# processname: firewall−iptables<br />

# pidfile: /var/run/firewall.pid<br />

# config: /etc/rc.d/rc.firewall−iptables<br />

# probe: true<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# v05/24/03<br />

#<br />

# Part of the copyrighted and trademarked TrinityOS document.<br />

# http://www.ecst.csuchico.edu/~dranch<br />

#<br />

# Written and Maintained by David A. Ranch<br />

# dranch@trinnet.net<br />

#<br />

# Updates<br />

# −−−−−−−<br />

# 05/24/03 − removed a old networking up check that had some<br />

# improper SGML ampersand conversions.<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 42


# Source function library.<br />

. /etc/rc.d/init.d/functions<br />

# Check that networking is up.<br />

[ "XXXX${NETWORKING}" = "XXXXno" ] && exit 0<br />

[ −x /sbin/ifconfig ] || exit 0<br />

# <strong>The</strong> location of various iptables and other shell programs<br />

#<br />

# If your <strong>Linux</strong> distribution came with a copy of iptables, most<br />

# likely it is located in /sbin. If you manually compiled<br />

# iptables, the default location is in /usr/local/sbin<br />

#<br />

# ** Please use the "whereis iptables" command to figure out<br />

# ** where your copy is and change the path below to reflect<br />

# ** your setup<br />

#<br />

<strong>IP</strong>TABLES=/usr/local/sbin/iptables<br />

# See how we were called.<br />

case "$1" in<br />

start)<br />

/etc/rc.d/rc.firewall−iptables<br />

;;<br />

stop)<br />

echo −e "\nFlushing firewall and setting default policies to DROP\n"<br />

$<strong>IP</strong>TABLES −P INPUT DROP<br />

$<strong>IP</strong>TABLES −F INPUT<br />

$<strong>IP</strong>TABLES −P OUTPUT DROP<br />

$<strong>IP</strong>TABLES −F OUTPUT<br />

$<strong>IP</strong>TABLES −P FORWARD DROP<br />

$<strong>IP</strong>TABLES −F FORWARD<br />

$<strong>IP</strong>TABLES −F −t nat<br />

# Delete all User−specified chains<br />

$<strong>IP</strong>TABLES −X<br />

#<br />

# Reset all <strong>IP</strong>TABLES counters<br />

$<strong>IP</strong>TABLES −Z<br />

;;<br />

restart)<br />

$0 stop<br />

$0 start<br />

;;<br />

status)<br />

$<strong>IP</strong>TABLES −L<br />

;;<br />

mlist)<br />

cat /proc/net/ip_conntrack<br />

;;<br />

*)<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

echo "Usage: firewall−iptables {start|stop|status|mlist}"<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 43


esac<br />

2. Slackware:<br />

•<br />

exit 1<br />

exit 0<br />

<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

With this script in place, all you need to do now is make it executable and then make it load upon<br />

reboot. First, make it executable by running:<br />

#Redhat−style<br />

#<br />

chmod 700 /etc/rc.d/init.d/firewall−iptables<br />

Now, enable the ruleset load upon reboot:<br />

#Redhat style<br />

#<br />

/sbin/chkconfig −−level=345 firewall−iptables on<br />

That's it! Now upon reboot, the firewall will be loaded automatically. Just to make sure, run the<br />

following command to see that the firewall should start upon reboot by running the command:<br />

#Redhat style<br />

#<br />

chkconfig −−list firewall−iptables<br />

#<strong>The</strong> output should look like:<br />

#<br />

firewall−iptables 0:off 1:off 2:off 3:on 4:on 5:on 6:off<br />

<strong>The</strong>re are two ways to load things in Slackware: /etc/rc.d/rc.local or editing the /etc/rc.d/rc.inet2 file.<br />

<strong>The</strong> first method is the easiest but isn't the most secure (see below). All you have to do is append the<br />

following lines to the /etc/rc.d/rc.local file:<br />

echo "Loading the rc.firewall−iptables ruleset.."<br />

/etc/rc.d/rc.firewall−iptables<br />

<strong>The</strong> problem with this approach is that if you are running a STRONG firewall ruleset, the firewall<br />

isn't executed until the last stages of booting. <strong>The</strong> preferred approach is to have the firewall loaded<br />

just after the networking subsystem is loaded. For now, the <strong>HOWTO</strong> only covers how to do so using<br />

/etc/rc.d/rc.local but if you know what you're doing (it's easy), go ahead and and modify the inet2<br />

startup script to load the /etc/rc.d/rc.firewall−iptables file just after the network is up. If you want a<br />

more detailed guide and/or a stronger firewall ruleset, I recommend you check out Section 10 of<br />

TrinityOS found in the links section at the bottom of this <strong>HOWTO</strong>.<br />

Notes on how users might want to change the above firewall ruleset:<br />

You could also have <strong>IP</strong> Masquerading enabled on a PER MACHINE basis instead of the above method,<br />

which is enabling an ENTIRE TCP/<strong>IP</strong> network. For example, say if I wanted only the 192.168.0.2 and<br />

192.168.0.8 hosts to have access to the Internet and NOT any of the other internal machines. I would change<br />

the in the "Enable simple <strong>IP</strong> forwarding and Masquerading" section (shown above) of the<br />

/etc/rc.d/rc.firewall−iptables ruleset.<br />

#!/bin/sh<br />

#<br />

# Partial <strong>IP</strong>TABLES config to enable simple <strong>IP</strong> forwarding and Masquerading<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 44


# v0.61<br />

#<br />

# NOTE: <strong>The</strong> following is an example to allow only <strong>IP</strong> Masquerading for the<br />

# 192.168.0.2 and 192.168.0.8 machines with a 255.255.255.0 or a<br />

# "/24" subnet mask connecting to the Internet on interface eth0.<br />

#<br />

# ** Please change the network number, subnet mask, and the Internet<br />

# ** connection interface name to match your internal LAN setup<br />

#<br />

echo " − Setting the default FORWARD policy to DROP"<br />

$<strong>IP</strong>TABLES −P FORWARD DROP<br />

echo " − Enabling SNAT (<strong>IP</strong>MASQ) functionality on $EXTIF"<br />

$<strong>IP</strong>TABLES −t nat −A POSTROUTING −o $EXTIF −s 192.168.0.2/32 −j MASQUERADE<br />

$<strong>IP</strong>TABLES −t nat −A POSTROUTING −o $EXTIF −s 192.168.0.8/32 −j MASQUERADE<br />

echo " − Setting the FORWARD policy to 'DROP' all incoming / unrelated traffic"<br />

$<strong>IP</strong>TABLES −A INPUT −i $EXTIF −m state −−state NEW,INVALID −j DROP<br />

$<strong>IP</strong>TABLES −A FORWARD −i $EXTIF −m state −−state NEW,INVALID −j DROP<br />

Common mistakes:<br />

It appears that a common mistake with new <strong>IP</strong> Masq users is to make the first command simply the following:<br />

<strong>IP</strong>TABLES:<br />

−−−−−−−−−<br />

iptables −t nat −A POSTROUTING −j MASQUERADE<br />

Do NOT make your default policy MASQUERADING. Otherwise, someone can manipulate their routing<br />

tables to tunnel straight back through your gateway, using it to masquerade their OWN identity!<br />

Again, you can add these lines to the /etc/rc.d/rc.firewall−iptables file, one of the other rc<br />

files you prefer, or do it manually every time you need <strong>IP</strong> <strong>Masquerade</strong>.<br />

Please see Section 6.4.1 for a detailed guide on a strong <strong>IP</strong>TABLES ruleset example. For additional details on<br />

<strong>IP</strong>TABLES usage, please refer to http://www.netfilter.org/ for the primary <strong>IP</strong>TABLES site.<br />

3.4.2. Configuring <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.2.x Kernels<br />

Please note that <strong>IP</strong>FWADM is no longer the firewall tool for manipulating <strong>IP</strong> Masquerading rules for both<br />

the 2.1.x and 2.2.x kernels. <strong>The</strong>se new kernels now use the <strong>IP</strong>CHAINS toolkit. For a more detailed reason for<br />

this change, please see Chapter 7.<br />

Create the file /etc/rc.d/rc.firewall−ipchains with the following initial SIMPLE ruleset:<br />

<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#!/bin/sh<br />

#<br />

# rc.firewall−ipchains<br />

#<br />

# − Initial SIMPLE <strong>IP</strong> <strong>Masquerade</strong> test for 2.1.x and 2.2.x kernels<br />

# using <strong>IP</strong>CHAINS.<br />

#<br />

# Once <strong>IP</strong> Masquerading has been tested, with this simple<br />

# ruleset, it is highly recommended to use a stronger<br />

# <strong>IP</strong>TABLES ruleset either given later in this <strong>HOWTO</strong> or<br />

# from another reputable resource.<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 45


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

FWVER="1.23"<br />

#<br />

# 1.23 − Added comments on why the default policy is ACCEPT<br />

# 1.22 − ruleset now uses modprobe instead of insmod<br />

# 1.21 − Added clarification that PPPoE users need to use<br />

# "ppp0" instead of "eth0" for their external interface<br />

# 1.20 − Updated the script to use environment vars<br />

# 1.01 − Original version<br />

echo −e "\n\nLoading simple rc.firewall−ipchains : version $FWVER..\n"<br />

# <strong>The</strong> location of the ipchains and kernel module programs<br />

#<br />

# If your <strong>Linux</strong> distribution came with a copy of ipchains,<br />

# most likely all the programs will be located in /sbin. If<br />

# you manually compiled ipchains, the default location will<br />

# be in /usr/local/sbin<br />

#<br />

# ** Please use the "whereis ipchains" command to figure out<br />

# ** where your copy is and change the path below to reflect<br />

# ** your setup<br />

#<br />

<strong>IP</strong>CHAINS=/sbin/ipchains<br />

#<strong>IP</strong>TABLES=/usr/local/sbin/ipchains<br />

DEPMOD=/sbin/depmod<br />

MODPROBE=/sbin/modprobe<br />

#Setting the EXTERNAL and INTERNAL interfaces for the network<br />

#<br />

# Each <strong>IP</strong> <strong>Masquerade</strong> network needs to have at least one<br />

# external and one internal network. <strong>The</strong> external network<br />

# is where the NATing will occur and the internal network<br />

# should preferably be addressed with a RFC1918 private addressing<br />

# scheme.<br />

#<br />

# For this example, "eth0" is external and "eth1" is internal"<br />

#<br />

# NOTE: If this doesnt EXACTLY fit your configuration, you must<br />

# change the EXTIF or INTIF variables above. For example:<br />

#<br />

# If you are a PPPoE or analog modem user:<br />

#<br />

# EXTIF="ppp0"<br />

#<br />

# ** Please change this to reflect your specific configuration **<br />

#<br />

EXTIF="eth0"<br />

INTIF="eth1"<br />

echo " External Interface: $EXTIF"<br />

echo " Internal Interface: $INTIF"<br />

# Network Address of the Internal Network<br />

#<br />

# This example rc.firewall−ipchains file uses the 192.168.0.0 network<br />

# with a /24 or 255.255.255.0 netmask.<br />

#<br />

# ** Change this variable to reflect your specific setup **<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 46


#<br />

INTLAN="192.168.0.0/24"<br />

echo −e " Internal Interface: $INTLAN\n"<br />

# Load all required <strong>IP</strong> MASQ modules<br />

#<br />

# NOTE: Only load the <strong>IP</strong> MASQ modules you need. All current <strong>IP</strong> MASQ modules<br />

# are shown below but are commented out from loading.<br />

echo " loading required <strong>IP</strong>MASQ kernel modules.."<br />

# Needed to initially load modules<br />

#<br />

$DEPMOD −a<br />

echo −en " Loading modules: "<br />

# Supports the proper masquerading of FTP file transfers using the PORT method<br />

#<br />

echo −en "FTP, "<br />

$MODPROBE ip_masq_ftp<br />

# Supports the masquerading of RealAudio over UDP. Without this module,<br />

# RealAudio WILL function but in TCP mode. This can cause a reduction<br />

# in sound quality<br />

#<br />

#echo −en "RealAudio, "<br />

$MODPROBE ip_masq_raudio<br />

# Supports the masquerading of IRC DCC file transfers<br />

#<br />

#echo −en "Irc, "<br />

#$MODPROBE ip_masq_irc<br />

# Supports the masquerading of Quake and QuakeWorld by default. This modules is<br />

# for for multiple users behind the <strong>Linux</strong> MASQ server. If you are going to<br />

# play Quake I, II, and III, use the second example.<br />

#<br />

# NOTE: If you get ERRORs loading the QUAKE module, you are running an old<br />

# −−−−− kernel that has bugs in it. Please upgrade to the newest kernel.<br />

#<br />

#echo −en "Quake, "<br />

#Quake I / QuakeWorld (ports 26000 and 27000)<br />

#$MODPROBE ip_masq_quake<br />

#<br />

#Quake I/II/III / QuakeWorld (ports 26000, 27000, 27910, 27960)<br />

#$MODPROBE ip_masq_quake 26000,27000,27910,27960<br />

# Supports the masquerading of the CuSeeme video conferencing software<br />

#<br />

#echo −en "CuSeeme, "<br />

#$MODPROBE ip_masq_cuseeme<br />

#Supports the masquerading of the VDO−live video conferencing software<br />

#<br />

#echo −en "VdoLive "<br />

#$MODPROBE ip_masq_vdolive<br />

echo ". Done loading modules."<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 47


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#CRITICAL: Enable <strong>IP</strong> forwarding since it is disabled by default since<br />

#<br />

# Redhat Users: you may try changing the options in<br />

# /etc/sysconfig/network from:<br />

#<br />

# FORWARD_<strong>IP</strong>V4=false<br />

# to<br />

# FORWARD_<strong>IP</strong>V4=true<br />

#<br />

echo " enabling forwarding.."<br />

echo "1" > /proc/sys/net/ipv4/ip_forward<br />

#CRITICAL: Enable automatic <strong>IP</strong> defragmenting since it is disabled by default<br />

# in 2.2.x kernels. This used to be a compile−time option but the<br />

# behavior was changed in 2.2.12<br />

#<br />

echo " enabling AlwaysDefrag.."<br />

echo "1" > /proc/sys/net/ipv4/ip_always_defrag<br />

# Dynamic <strong>IP</strong> users:<br />

#<br />

# If you get your <strong>IP</strong> address dynamically from SL<strong>IP</strong>, PPP, or DHCP, enable this<br />

# following option. This enables dynamic−ip address hacking in <strong>IP</strong> MASQ,<br />

# making the life with Diald and similar programs much easier.<br />

#<br />

#echo " enabling DynamicAddr.."<br />

#echo "1" > /proc/sys/net/ipv4/ip_dynaddr<br />

# Enable the LooseUDP patch which some Internet−based games require<br />

#<br />

# If you are trying to get an Internet game to work through your <strong>IP</strong> MASQ box,<br />

# and you have set it up to the best of your ability without it working, try<br />

# enabling this option (delete the "#" character). This option is disabled<br />

# by default due to possible internal machine UDP port scanning<br />

# vulnerabilities.<br />

#<br />

#echo " enabling LooseUDP.."<br />

#echo "1" > /proc/sys/net/ipv4/ip_masq_udp_dloose<br />

#Clearing any previous configuration<br />

#<br />

# Unless specified, the defaults for INPUT and OUTPUT is ACCEPT<br />

# <strong>The</strong> default for FORWARD is REJECT<br />

#<br />

# Isn't ACCEPT insecure? To some degree, YES, but this is our testing<br />

# phase. Once we know that <strong>IP</strong>MASQ is working well, I recommend you run<br />

# the rc.firewall−*−stronger rulesets which set the defaults to DROP but<br />

# also include the critical additional rulesets to still let you connect to<br />

# the <strong>IP</strong>MASQ server, etc.<br />

#<br />

echo " clearing any existing rules and setting default policy.."<br />

$<strong>IP</strong>CHAINS −P input ACCEPT<br />

$<strong>IP</strong>CHAINS −P output ACCEPT<br />

$<strong>IP</strong>CHAINS −P forward REJECT<br />

$<strong>IP</strong>CHAINS −F input<br />

$<strong>IP</strong>CHAINS −F output<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 48


$<strong>IP</strong>CHAINS −F forward<br />

# MASQ timeouts<br />

#<br />

# 2 hrs timeout for TCP session timeouts<br />

# 10 sec timeout for traffic after the TCP/<strong>IP</strong> "FIN" packet is received<br />

# 160 sec timeout for UDP traffic (Important for MASQ'ed ICQ users)<br />

#<br />

echo " setting default timers.."<br />

$<strong>IP</strong>CHAINS −M −S 7200 10 160<br />

# DHCP: For people who receive their external <strong>IP</strong> address from either DHCP or<br />

# BOOTP for connctions such as DSL or Cablemodem users, it is necessary<br />

# to use the following before the deny command.<br />

#<br />

# This example is currently commented out.<br />

#<br />

#<br />

#$<strong>IP</strong>CHAINS −A input −j ACCEPT −i $EXTIF −s 0/0 67 −d 0/0 68 −p udp<br />

# Enable simple <strong>IP</strong> forwarding and Masquerading<br />

#<br />

# NOTE: <strong>The</strong> following is an example for an internal LAN address in the<br />

# 192.168.0.x network with a 255.255.255.0 or a "24" bit subnet mask<br />

# connecting to the Internet on interface eth0.<br />

#<br />

# ** Please change this network number, subnet mask, and your Internet<br />

# ** connection interface name to match your internal LAN setup<br />

#<br />

echo " enabling <strong>IP</strong>MASQ functionality on $EXTIF"<br />

$<strong>IP</strong>CHAINS −P forward DENY<br />

$<strong>IP</strong>CHAINS −A forward −i $EXTIF −s $INTLAN −j MASQ<br />

echo −e "\nrc.firewall−ipchains v$FWVER done.\n"<br />

<br />

Once you are finished with editing the /etc/rc.d/rc.firewall−ipchains ruleset, make it executable by typing in<br />

chmod 700 /etc/rc.d/rc.firewall−ipchains<br />

Now that the firewall ruleset is ready, you need to let it run after every reboot. You could either do this by<br />

running it by hand everytime (such a pain) or add it to the boot scripts. We have covered two methods below:<br />

Redhat (SyS−V style) and Slackware (BSD style)<br />

1. Redhat and Redhat−derived distros:<br />

•<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

<strong>The</strong>re are two ways to automatically load things in Redhat: /etc/rc.d/rc.local or a init script in<br />

/etc/rc.d/init.d/. <strong>The</strong> first method is the easiest but isn't doing things the Sys−V way. All you have to<br />

do is add the line:<br />

echo "Loading the rc.firewall ruleset.."<br />

/etc/rc.d/rc.firewall−ipchains<br />

to the end of the /etc/rc.d/rc.local file and thats it (as described earlier in the <strong>HOWTO</strong>).<br />

<strong>The</strong> problem with this approach is that the firewall isn't executed until the last stages of booting. <strong>The</strong><br />

preferred approach is to have the firewall loaded just after the networking subsystem is loaded. To do<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 49


this, copy the following file into the /etc/rc.d/init.d directory:<br />

<br />

#!/bin/sh<br />

#<br />

# chkconfig: 2345 11 89<br />

#<br />

# description: Loads the rc.firewall−ipchains ruleset.<br />

#<br />

# processname: firewall−ipchains<br />

# pidfile: /var/run/firewall.pid<br />

# config: /etc/rc.d/rc.firewall−ipchains<br />

# probe: true<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# v08/29/02<br />

#<br />

# Part of the copyrighted and trademarked TrinityOS document.<br />

# http://www.ecst.csuchico.edu/~dranch<br />

#<br />

# Written and Maintained by David A. Ranch<br />

# dranch@trinnet.net<br />

#<br />

# Updates<br />

# −−−−−−−<br />

#<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# Source function library.<br />

. /etc/rc.d/init.d/functions<br />

# Check that networking is up.<br />

# This line no longer work with bash2<br />

#[ ${NETWORKING} = "no" ] && exit 0<br />

# This should be OK.<br />

[ "XXXX${NETWORKING}" = "XXXXno" ] && exit 0<br />

[ −x /sbin/ifconfig ] || exit 0<br />

# <strong>The</strong> location of various iptables and other shell programs<br />

#<br />

# If your <strong>Linux</strong> distribution came with a copy of iptables, most<br />

# likely it is located in /sbin. If you manually compiled<br />

# iptables, the default location is in /usr/local/sbin<br />

#<br />

# ** Please use the "whereis iptables" command to figure out<br />

# ** where your copy is and change the path below to reflect<br />

# ** your setup<br />

#<br />

<strong>IP</strong>CHAINS=/sbin/ipchains<br />

# See how we were called.<br />

case "$1" in<br />

start)<br />

/etc/rc.d/rc.firewall−ipchains<br />

;;<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 50


2. Slackware:<br />

stop)<br />

echo −e "\nFlushing firewall and setting default policies to REJECT\n"<br />

$<strong>IP</strong>CHAINS −P input REJECT<br />

$<strong>IP</strong>CHAINS −P output REJECT<br />

$<strong>IP</strong>CHAINS −P forward REJECT<br />

$<strong>IP</strong>CHAINS −F input<br />

$<strong>IP</strong>CHAINS −F output<br />

$<strong>IP</strong>CHAINS −F forward<br />

;;<br />

restart)<br />

$0 stop<br />

$0 start<br />

;;<br />

status)<br />

$<strong>IP</strong>CHAINS −L<br />

;;<br />

mlist)<br />

$<strong>IP</strong>CHAINS −M −L<br />

;;<br />

*)<br />

echo "Usage: firewall−ipchains {start|stop|status|mlist}"<br />

exit 1<br />

esac<br />

exit 0<br />

<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

With this script in place, all you need to do now is make it executable and then make it load upon<br />

reboot. First, make it executable by running:<br />

#Redhat−style<br />

#<br />

chmod 700 /etc/rc.d/init.d/firewall−ipchains<br />

Now, make the ruleset load upon reboot:<br />

#Redhat style<br />

#<br />

chkconfig −−level=345 firewall−ipchains on<br />

That's it! Now upon boot, the firewall will be loaded automatically. Just to make sure, run the<br />

command to see that the firewall should start upon reboot by running the command:<br />

#Redhat style<br />

#<br />

chkconfig −−list firewall−ipchains<br />

#<strong>The</strong> output should look like:<br />

#<br />

firewall−ipchains 0:off 1:off 2:off 3:on 4:on 5:on 6:off<br />

• <strong>The</strong>re are two ways to load things in Slackware: /etc/rc.d/rc.local or editing the /etc/rc.d/rc.inet2 file.<br />

<strong>The</strong> first method is the easiest but isn't the most secure (see below). All you have to do is append the<br />

following lines to the /etc/rc.d/rc.local file:<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 51


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

echo "Loading the rc.firewall−ipchains ruleset.."<br />

/etc/rc.d/rc.firewall−ipchains<br />

<strong>The</strong> problem with this approach is that if you are running a STRONG firewall ruleset, the firewall<br />

isn't executed until the last stages of booting. <strong>The</strong> preferred approach is to have the firewall loaded<br />

just after the networking subsystem is loaded. For now, the <strong>HOWTO</strong> only covers how to do so using<br />

/etc/rc.d/rc.local but if you know what you're doing (it's easy), go ahead and and modify the inet2<br />

startup script to load the /etc/rc.d/rc.firewall−ipchains file just after the network is up. If you want a<br />

more detailed guide and/or a stronger firewall ruleset, I recommend you check out Section 10 of<br />

TrinityOS found in the links section at the bottom of this <strong>HOWTO</strong>.<br />

Notes on how users might want to change the above firewall ruleset:<br />

You could also have <strong>IP</strong> Masquerading enabled on a PER MACHINE basis instead of the above method,<br />

which is enabling an ENTIRE TCP/<strong>IP</strong> network. For example, say if I wanted only the 192.168.0.2 and<br />

192.168.0.8 hosts to have access to the Internet and NOT any of the other internal machines. I would change<br />

the in the "Enable simple <strong>IP</strong> forwarding and Masquerading" section (shown above) of the<br />

/etc/rc.d/rc.firewall−ipchains ruleset.<br />

#!/bin/sh<br />

#<br />

# Enable simple <strong>IP</strong> forwarding and Masquerading<br />

# v1.01<br />

#<br />

# NOTE: <strong>The</strong> following is an example used in addition to the simple<br />

# <strong>IP</strong>CHAINS ruleset anove to allow only <strong>IP</strong> Masquerading for the<br />

# 192.168.0.2 and 192.168.0.8 machines with a 255.255.255.0 or a<br />

# "24" bit subnet mask connecting to the Internet on interface $EXTIF.<br />

#<br />

# ** Please change the network number, subnet mask, and the Internet<br />

# ** connection interface name to match your internal LAN setup<br />

#<br />

$<strong>IP</strong>CHAINS −P forward DENY<br />

$<strong>IP</strong>CHAINS −A forward −i $EXTIF −s 192.168.0.2/32 −j MASQ<br />

$<strong>IP</strong>CHAINS −A forward −i $EXTIF −s 192.168.0.8/32 −j MASQ<br />

Common mistakes:<br />

What appears to be a common mistake with new <strong>IP</strong> MASQ users is to make the first command:<br />

$<strong>IP</strong>CHAINS −P forward masquerade<br />

Do NOT make your default policy MASQUERADING. Otherwise, someone can manipulate their routing<br />

tables to tunnel straight back through your gateway, using it to masquerade their OWN identity!<br />

Again, you can add these lines to the /etc/rc.d/rc.firewall−ipchains file, one of the other rc<br />

files you prefer, or do it manually every time you need <strong>IP</strong> <strong>Masquerade</strong>.<br />

Please see Section 6.4.2 for a detailed guide on <strong>IP</strong>CHAINS and a strong <strong>IP</strong>CHAINS ruleset example. For<br />

additional details on <strong>IP</strong>CHAINS usage, please refer to http://www.netfilter.org/ipchains/ for the primary<br />

<strong>IP</strong>CHAINS site or the <strong>Linux</strong> <strong>IP</strong> CHAINS <strong>HOWTO</strong> Backup site<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 52


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

3.4.3. Configuring <strong>IP</strong> <strong>Masquerade</strong> on <strong>Linux</strong> 2.0.x Kernels<br />

Create the file /etc/rc.d/rc.firewall−ipfwadm with the following initial SIMPLE ruleset: <br />

#!/bin/sh<br />

#<br />

# rc.firewall−ipfwadm<br />

#<br />

# A Initial SIMPLE <strong>IP</strong> <strong>Masquerade</strong> setup for 2.0.x kernels using <strong>IP</strong>FWADM<br />

#<br />

FWVER="2.03"<br />

#<br />

# 2.03 − Added comments on why the default policy is ACCEPT<br />

# 2.02 − Added clarification that PPPoE users need to use<br />

# "ppp0" instead of "eth0" for their external interface<br />

#<br />

#<br />

# Once <strong>IP</strong> Masquerading has been tested, with this simple<br />

# ruleset, it is highly recommended to use a stronger<br />

# <strong>IP</strong>TABLES ruleset either given later in this <strong>HOWTO</strong> or<br />

# from another reputable resource.<br />

#<br />

echo −e "\n\nLoading simple rc.firewall−ipfwadm version $FWVER..\n"<br />

#Setting the EXTERNAL and INTERNAL interfaces for the network<br />

#<br />

# Each <strong>IP</strong> <strong>Masquerade</strong> network needs to have at least one<br />

# external and one internal network. <strong>The</strong> external network<br />

# is where the NATing will occur and the internal network<br />

# should preferably be addressed with a RFC1918 private addressing<br />

# scheme.<br />

#<br />

# For this example, "eth0" is external and "eth1" is internal"<br />

#<br />

# NOTE: If this doesnt EXACTLY fit your configuration, you must<br />

# change the EXTIF or INTIF variables above. For example:<br />

#<br />

# If you are a PPPoE or analog modem user:<br />

#<br />

# EXTIF="ppp0"<br />

#<br />

# ** Please change this to reflect your specific configuration **<br />

#<br />

EXTIF="eth0"<br />

INTIF="eth1"<br />

echo " External Interface: $EXTIF"<br />

echo " Internal Interface: $INTIF"<br />

# Network Address of the Internal Network<br />

#<br />

# This example rc.firewall−ipfwadm file uses the 192.168.0.0 network<br />

# with a /24 or 255.255.255.0 netmask.<br />

#<br />

# ** Change this variable to reflect your specific setup **<br />

#<br />

INTLAN="192.168.0.0/24"<br />

echo −e " Internal Interface: $INTLAN\n"<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 53


# Load all required <strong>IP</strong> MASQ modules<br />

#<br />

# NOTE: Only load the <strong>IP</strong> MASQ modules you need. All current available <strong>IP</strong><br />

# MASQ modules are shown below but are commented out from loading.<br />

echo −en "Loading modules: "<br />

# Needed to initially load modules<br />

#<br />

/sbin/depmod −a<br />

# Supports the proper masquerading of FTP file transfers using the PORT method<br />

#<br />

echo −en "FTP, "<br />

/sbin/modprobe ip_masq_ftp<br />

# Supports the masquerading of RealAudio over UDP. Without this module,<br />

# RealAudio WILL function but in TCP mode. This can cause a reduction<br />

# in sound quality<br />

#<br />

#echo −en "RealAudio, "<br />

#/sbin/modprobe ip_masq_raudio<br />

# Supports the masquerading of IRC DCC file transfers<br />

#<br />

#echo −en "Irc, "<br />

#/sbin/modprobe ip_masq_irc<br />

# Supports the masquerading of Quake and QuakeWorld by default. <strong>The</strong>se modules<br />

# are for multiple users behind the <strong>Linux</strong> MASQ server. If you are going to<br />

# play Quake I, II, and III, use the second example.<br />

#<br />

# NOTE: If you get ERRORs loading the QUAKE module, you are running an old<br />

# −−−−− kernel that has bugs in it. Please upgrade to the newest kernel.<br />

#<br />

#echo −en "Quake, "<br />

#Quake I / QuakeWorld (ports 26000 and 27000)<br />

#/sbin/modprobe ip_masq_quake<br />

#<br />

#Quake I/II/III / QuakeWorld (ports 26000, 27000, 27910, 27960)<br />

#/sbin/modprobe ip_masq_quake 26000,27000,27910,27960<br />

# Supports the masquerading of the CuSeeme video conferencing software<br />

#<br />

#echo −en "CuSeeme, "<br />

#/sbin/modprobe ip_masq_cuseeme<br />

#Supports the masquerading of the VDO−live video conferencing software<br />

#<br />

#echo −en "VdoLive, "<br />

#/sbin/modprobe ip_masq_vdolive<br />

echo ". Done loading modules."<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#CRITICAL: Enable <strong>IP</strong> forwarding since it is disabled by default<br />

#<br />

# Redhat Users: you may try changing the options in<br />

# /etc/sysconfig/network from:<br />

#<br />

# FORWARD_<strong>IP</strong>V4=false<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 54


# to<br />

# FORWARD_<strong>IP</strong>V4=true<br />

#<br />

echo " enabling forwarding.."<br />

echo "1" > /proc/sys/net/ipv4/ip_forward<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#CRITICAL: Enable automatic <strong>IP</strong> defragmenting since it is disabled by default<br />

#<br />

# This used to be a compile−time option but the behavior was changed<br />

# in 2.2.12. This option is required for both 2.0 and 2.2 kernels.<br />

#<br />

echo " enabling AlwaysDefrag.."<br />

echo "1" > /proc/sys/net/ipv4/ip_always_defrag<br />

# Dynamic <strong>IP</strong> users:<br />

#<br />

# If you get your Internet <strong>IP</strong> address dynamically from SL<strong>IP</strong>, PPP, or DHCP,<br />

# enable the following option. This enables dynamic−ip address hacking in<br />

# <strong>IP</strong> MASQ, making the life with DialD, PPPd, and similar programs much easier.<br />

#<br />

#echo " enabling DynamicAddr.."<br />

#echo "1" > /proc/sys/net/ipv4/ip_dynaddr<br />

#Clearing any previous configuration<br />

#<br />

# Unless specified, the defaults for INPUT and OUTPUT is ACCEPT<br />

# <strong>The</strong> default for FORWARD is REJECT<br />

#<br />

# Isn't ACCEPT insecure? To some degree, YES, but this is our testing<br />

# phase. Once we know that <strong>IP</strong>MASQ is working well, I recommend you run<br />

# the rc.firewall−*−stronger rulesets which set the defaults to DROP but<br />

# also include the critical additional rulesets to still let you connect to<br />

# the <strong>IP</strong>MASQ server, etc.<br />

#<br />

echo " clearing any existing rules and setting default policy.."<br />

/sbin/ipfwadm −I −p accept<br />

/sbin/ipfwadm −O −p accept<br />

/sbin/ipfwadm −F −p reject<br />

/sbin/ipfwadm −I −f<br />

/sbin/ipfwadm −O −f<br />

/sbin/ipfwadm −F −f<br />

# MASQ timeouts<br />

#<br />

# 2 hrs timeout for TCP session timeouts<br />

# 10 sec timeout for traffic after the TCP/<strong>IP</strong> "FIN" packet is received<br />

# 160 sec timeout for UDP traffic (Important for MASQ'ed ICQ users)<br />

#<br />

echo " setting default timers.."<br />

/sbin/ipfwadm −M −s 7200 10 160<br />

# DHCP: For people who receive their external <strong>IP</strong> address from either DHCP or<br />

# BOOTP such as DSL or Cablemodem users, it is necessary to use the<br />

# following before the deny command.<br />

#<br />

# This example is currently commented out.<br />

#<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 55


#<br />

#/sbin/ipfwadm −I −a accept −S 0/0 67 −D 0/0 68 −W $EXTIF −P udp<br />

# Enable simple <strong>IP</strong> forwarding and Masquerading<br />

#<br />

# NOTE: <strong>The</strong> following is an example for an internal LAN address in the<br />

# 192.168.0.x network with a 255.255.255.0 or a "24" bit subnet mask<br />

# connecting to the Internet on interface eth0.<br />

#<br />

# ** Please change this network number, subnet mask, and your Internet<br />

# ** connection interface name to match your internal LAN setup.<br />

#<br />

echo " enabling <strong>IP</strong>MASQ functionality on $EXTIF"<br />

/sbin/ipfwadm −F −p deny<br />

/sbin/ipfwadm −F −a m −W $EXTIF −S $INTLAN −D 0.0.0.0/0<br />

echo −e "\nrc.firewall−ipfwadm v$FWVER done.\n"<br />

<br />

Once you are finished with editing the /etc/rc.d/rc.firewall−ipfwadm ruleset, make it executable by typing in<br />

"chmod 700 /etc/rc.d/rc.firewall−ipfwadm"<br />

Now that the firewall ruleset is ready to go, you need to let it run after every reboot. You could either do this<br />

by running it by hand everytime (such a pain) or add it to the boot scripts. We have covered two methods<br />

below: Redhat (SyS−V style) and Slackware (BSD style)<br />

Redhat and Redhat−derived distros:<br />

•<br />

<strong>The</strong>re are two ways to automatically load things in Redhat: /etc/rc.d/rc.local or a init script in<br />

/etc/rc.d/init.d/. <strong>The</strong> first method is the easiest but isn't doing it the Sys−V way. All you have to do is<br />

add the line:<br />

echo "Loading the rc.firewall−ipfwadm ruleset.."<br />

/etc/rc.d/rc.firewall−ipfwadm<br />

<strong>The</strong> problem with this approach is that the firewall isn't executed until the last stages of booting. <strong>The</strong><br />

preferred approach is to have the firewall loaded just after the networking subsystem is loaded. To do<br />

this, copy the following file into the /etc/rc.d/init.d directory:<br />

<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#!/bin/sh<br />

#<br />

# chkconfig: 2345 11 89<br />

#<br />

# description: Loads the rc.firewall−ipfwadm ruleset.<br />

#<br />

# processname: firewall−ipfwadm<br />

# pidfile: /var/run/firewall.pid<br />

# config: /etc/rc.d/rc.firewall−ipfwadm<br />

# probe: true<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# v02/09/02<br />

#<br />

# Part of the copyrighted and trademarked TrinityOS document.<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 56


# http://www.ecst.csuchico.edu/~dranch<br />

#<br />

# Written and Maintained by David A. Ranch<br />

# dranch@trinnet.net<br />

#<br />

# Updates<br />

# −−−−−−−<br />

#<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# Source function library.<br />

. /etc/rc.d/init.d/functions<br />

# Check that networking is up.<br />

# This line no longer work with bash2<br />

#[ ${NETWORKING} = "no" ] && exit 0<br />

# This should be OK.<br />

[ "XXXX${NETWORKING}" = "XXXXno" ] && exit 0<br />

[ −x /sbin/ifconfig ] || exit 0<br />

# <strong>The</strong> location of various iptables and other shell programs<br />

#<br />

# If your <strong>Linux</strong> distribution came with a copy of iptables, most<br />

# likely it is located in /sbin. If you manually compiled<br />

# iptables, the default location is in /usr/local/sbin<br />

#<br />

# ** Please use the "whereis iptables" command to figure out<br />

# ** where your copy is and change the path below to reflect<br />

# ** your setup<br />

#<br />

<strong>IP</strong>FWADM=/sbin/ipfwadm<br />

# See how we were called.<br />

case "$1" in<br />

start)<br />

/etc/rc.d/rc.firewall−ipfwadm<br />

;;<br />

stop)<br />

echo −e "\nFlushing firewall and setting default policies to REJECT\n"<br />

$<strong>IP</strong>FWADM −I −p REJECT<br />

$<strong>IP</strong>FWADM −O −p REJECT<br />

$<strong>IP</strong>FWADM −F −p REJECT<br />

$<strong>IP</strong>FWADM −I −f<br />

$<strong>IP</strong>FWADM −O −f<br />

$<strong>IP</strong>FWADM −F −f<br />

;;<br />

restart)<br />

$0 stop<br />

$0 start<br />

;;<br />

status)<br />

$<strong>IP</strong>FWADM −l<br />

;;<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 57


Slackware:<br />

•<br />

mlist)<br />

$<strong>IP</strong>FWADM −M −l<br />

;;<br />

*)<br />

echo "Usage: firewall−ipfwadm {start|stop|status|mlist}"<br />

exit 1<br />

esac<br />

exit 0<br />

<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

With this script in place, all you need to do now is make it executable and then make it load upon<br />

reboot. First, make it executable by running:<br />

#Redhat−style<br />

#<br />

chmod 700 /etc/rc.d/init.d/firewall−ipfwadm<br />

Now, make the ruleset load upon reboot:<br />

#Redhat style<br />

#<br />

chkconfig −−level=345 firewall−ipfwadm on<br />

That's it! Now upon boot, the firewall will be loaded automatically. Just to make sure, run the<br />

command to see that the firewall should start upon reboot by running the command:<br />

#Redhat style<br />

#<br />

chkconfig −−list firewall−ipfwadm<br />

#<strong>The</strong> output should look like:<br />

#<br />

firewall−ipfwadm 0:off 1:off 2:off 3:on 4:on 5:on 6:off<br />

<strong>The</strong>re are two ways to automatically load things in Slackware: /etc/rc.d/rc.local or editing the<br />

/etc/rc.d/rc.inet2 file. <strong>The</strong> first method is the easiest but isn't the most secure (see below). All you<br />

have to do is append the following lines to the /etc/rc.d/rc.local file:<br />

echo "Loading the rc.firewall−ipfwadm ruleset.."<br />

/etc/rc.d/rc.firewall−ipfwadm<br />

<strong>The</strong> problem with this approach is that if you are running a STRONG firewall ruleset, the firewall<br />

isn't executed until the last stages of booting. <strong>The</strong> preferred approach is to have the firewall loaded<br />

just after the networking subsystem is loaded. For now, the <strong>HOWTO</strong> only covers how to do so using<br />

/etc/rc.d/rc.local but if you know what you're doing (it's easy), go ahead and and modify the inet2<br />

startup script to load the /etc/rc.d/rc.firewall−ipfwadm file just after the network is up. If you want a<br />

more detailed guide and/or a stronger firewall ruleset, I recommend you check out Section 10 of<br />

TrinityOS found in the links section at the bottom of this <strong>HOWTO</strong>.<br />

Notes on how users might want to change the above firewall ruleset:<br />

You could have also enabled <strong>IP</strong> Masquerading on a PER MACHINE basis instead of the above method<br />

enabling an ENTIRE TCP/<strong>IP</strong> network. For example, say if I wanted only the 192.168.0.2 and 192.168.0.8<br />

hosts to have access to the Internet and NOT any of the other internal machines. I would change the in the<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 58


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

"Enable simple <strong>IP</strong> forwarding and Masquerading" section (shown above) of the /etc/rc.d/rc.firewall−ipfwadm<br />

ruleset.<br />

# Enable simple <strong>IP</strong> forwarding and Masquerading<br />

# v2.01<br />

#<br />

# NOTE: <strong>The</strong> following is an example to only allow <strong>IP</strong> Masquerading for the<br />

# 192.168.0.2 and 192.168.0.8 machines with a 255.255.255.0 or a "24"<br />

# bit subnet mask connected to the Internet on interface eth0.<br />

#<br />

# ** Please change this network number, subnet mask, and your Internet<br />

# ** connection interface name to match your internal LAN setup<br />

#<br />

# Please use the following in ADDITION to the simple rulesets above for<br />

# specific MASQ networks.<br />

#<br />

/sbin/ipfwadm −F −p deny<br />

/sbin/ipfwadm −F −a m −W $EXTIF −S 192.168.0.2/32 −D 0.0.0.0/0<br />

/sbin/ipfwadm −F −a m −W $EXTIF −S 192.168.0.8/32 −D 0.0.0.0/0<br />

Common mistakes:<br />

What appears to be a common mistake with new <strong>IP</strong> Masq users is to make the first command:<br />

ipfwadm −F −p masquerade<br />

Do NOT make your default policy MASQUERADING. Otherwise, someone who has the ability to<br />

manipulate their routing tables will be able to tunnel straight back through your gateway, using it to<br />

masquerade their OWN identity!<br />

Again, you can add these lines to the /etc/rc.d/rc.firewall−ipfwadm file, one of the other rc files<br />

(if you prefer), or manually add those lines every time you need <strong>IP</strong> <strong>Masquerade</strong>.<br />

Please see Section 6.4.3 and Section 6.4.3for a detailed guide and stronger examples of <strong>IP</strong>CHAINS and<br />

<strong>IP</strong>FWADM ruleset examples.<br />

Chapter 3. Setting Up <strong>IP</strong> <strong>Masquerade</strong> 59


Chapter 4. Configuring the other internal to−be<br />

MASQed machines<br />

Besides setting the appropriate <strong>IP</strong> address for each internal MASQed machine (either statically or though<br />

DHCP), you should also set each internal machine with the appropriate gateway <strong>IP</strong> address of the <strong>Linux</strong><br />

MASQ server and required DNS servers. In general, this is rather straight forward. You simply enter the<br />

address of your <strong>Linux</strong> host (192.168.0.1 is used throughout this <strong>HOWTO</strong>) as the machine's gateway address.<br />

For the Domain Name Service (DNS), you add in any DNS servers that are available to you to use. <strong>The</strong> most<br />

apparent one(s) should be the DNS servers that your <strong>Linux</strong> server uses. You can optionally add any "domain<br />

search" suffix as well for quicker connections, etc.<br />

After you have properly reconfigured the internal MASQed machines, remember to restart their appropriate<br />

network services or reboot them if need be.<br />

<strong>The</strong> following configuration instructions assume that you are using a Class C network with 192.168.0.1 as<br />

your <strong>Linux</strong> MASQ server's address. Please note that 192.168.0.0 and 192.168.0.255 are reserved TCP/<strong>IP</strong><br />

address per RFC1918 for uses just like enabling <strong>IP</strong> <strong>Masquerade</strong> services.<br />

As it stands, the following Platforms have been tested as internal MASQed machines. This is only an<br />

EXAMPLE of all compatible OSes out there:<br />

• Apple Macintosh OS and OS−X (with MacTCP or Open Transport or the BSD TCP/<strong>IP</strong> stack)<br />

• AT&T Unix (Caldera)<br />

• *BSD systems including Free/Net/Open/BSDi/386/etc.<br />

• Commodore Amiga (with AmiTCP or AS225−stack)<br />

• Digital VAX Stations 3520 and 3100 with UCX (TCP/<strong>IP</strong> stack for VMS)<br />

• Digital Ultrix, Digital Unix (Compaq Tru/64)<br />

• HP HP/UX<br />

• IBM AIX running on RS/6000, PowerPC, etc.<br />

• IBM OS/2 (including Warp v3)<br />

• IBM OS400 running on a AS/400<br />

• <strong>Linux</strong> distributions from vendors like Caldera, Corel, Debian, Mandrake, Redhat, Slackware, SuSe,<br />

etc. running various kernels like 1.2.x, 1.3.x, 2.0.x, 2.1.x, 2.2.x, 2.3.x, 2.4.x, etc.<br />

• Microsoft DOS (with NCSA Telnet package, DOS Trumpet works partially)<br />

• Microsoft Windows 3.1 (with the Netmanage or FTP packages)<br />

• Microsoft Windows For Workgroup 3.11 (with a TCP/<strong>IP</strong> package)<br />

• Microsoft Windows 95, OSR2, 98, 98se, Me<br />

• Microsoft Windows NT 3.51, 4.0, 2000, XP − (both workstation (professional) and server versions)<br />

• Novell Netware 4.01, 5.x, etc. with the TCP/<strong>IP</strong> service<br />

• SCO Openserver (v3.2.4.2 and 5) and UnixWare (AT&T Unix)<br />

• Sun Solaris 2.51, 2.6, 7, 8<br />

• heheh.. what else am I missing?<br />

4.1. Configuring Microsoft Windows 95 and OSR2<br />

1. ** Please note that some prompts might be different based upon the build version of Windows95 you<br />

are running **<br />

Chapter 4. Configuring the other internal to−be MASQed machines 60


If you haven't installed your network card and adapter driver, do so now. Descriptions to perform this<br />

step is beyond the scope of this document and though it is fairly simple, if you haven't done this<br />

before, please seek assitance.<br />

2. Go to the 'Control Panel' −−> 'Network'.<br />

3. Click on Add −−> Protocol −−> Manufacture: Microsoft −−> Protocol: 'TCP/<strong>IP</strong> protocol' if you<br />

don't already have it installed.<br />

4. Highlight the TCP/<strong>IP</strong> item bound to your correct Windows95 network card e.g. (TCP/<strong>IP</strong> −−> Intel<br />

EtherExpress Pro/100+) and select 'Properties'. Here, you have two options: configure a static<br />

address or use DHCP. Static addresses are simple but require that you NEVER configure duplication<br />

<strong>IP</strong>s on different machines. <strong>The</strong> alternative is DHCP which automatically configures all<br />

DHCP−enabled workstations things like <strong>IP</strong> addresses, DNS servers, etc. from a central server<br />

(typically the <strong>Linux</strong> MASQ server).<br />

DHCP enabled:<br />

To use DHCP, simply click on the "Use DHCP to assign addresses" button. Please note that<br />

configuring a DHCP server is beyond the scope of this <strong>HOWTO</strong> but it is fully covered in TrinityOS<br />

and other <strong>Linux</strong> <strong>HOWTO</strong>s.<br />

Static Addresses:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Now goto the '<strong>IP</strong> Address' tab and set <strong>IP</strong> Address to 192.168.0.x, (1 < x < 255), and set the Subnet<br />

Mask to 255.255.255.0<br />

5. Now select the "Gateway" tab and add 192.168.0.1 as your gateway under 'Gateway' and hit "Add".<br />

6. Under the 'DNS Configuration' tab, make sure to put enter in a name for this machine and specify<br />

your official domain name. If you don't have your own domain, enter in the domain of your ISP.<br />

Next, you need to specify the DNS servers you plan on using.<br />

DHCP: No entries are required as this is configured dynamically via DHCP.<br />

STATIC: Add all of the DNS servers that your <strong>Linux</strong> MASQ server uses (usually found in<br />

/etc/resolv.conf). Usually these DNS servers are located at your ISP though you could be<br />

running either your own Caching or Authoritative DNS server on your <strong>Linux</strong> MASQ server as well.<br />

Again, setting up DNS services is beyond the scope of this <strong>HOWTO</strong> but it is covered by TrinityOS as<br />

well as the LDP's DNS <strong>HOWTO</strong>.<br />

Optionally, you can add any appropriate domain search suffixes as well. This allows users to simply<br />

type in the hostname of the destination computer instead of the fully qualified domain name (FQDN).<br />

This is similar to the PATH function for finding common Unix commands.<br />

7. Leave all of the other settings alone as they are unless (even dangerous) if you don't know what you're<br />

doing.<br />

8. Click 'OK' in all dialog boxes and restart your system.<br />

9. As an initial test, Ping the <strong>Linux</strong> MASQ server to test the network connection: 'Start/Run', type:<br />

ping 192.168.0.1(This is only an INTERNAL LAN connection test, you might not be able to<br />

ping the outside world yet.) If you don't see "replies" to your PINGs, please verify your network<br />

configuration.<br />

10. You can optionally create a HOSTS file in the C:\Windows directory so that you can ping the<br />

"hostname" of the machines on your LAN without the need for a DNS server. <strong>The</strong>re is an example<br />

called HOSTS.SAM in the C:\windows directory for an example.<br />

Chapter 4. Configuring the other internal to−be MASQed machines 61


4.2. Configuring Windows NT<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

1. If you haven't installed your network card and adapter driver, do so now. Descriptions to perform this<br />

task is beyond the scope of this document.<br />

2. Go to 'Control Panel' −−> 'Network' −−> Protocols<br />

3. Add the TCP/<strong>IP</strong> Protocol and related Components from the 'Add Software' menu if you don't have<br />

TCP/<strong>IP</strong> service installed already.<br />

4. Under 'Network Software and Adapter Cards' section, highlight the 'TCP/<strong>IP</strong> Protocol' in the<br />

'Installed Network Software' selection box.<br />

5. In 'TCP/<strong>IP</strong> Configuration', select the appropriate adapter, e.g. [1]Intel EtherExpress<br />

Pro/100+. <strong>The</strong>n set the <strong>IP</strong> Address to 192.168.0.x (1 < x < 255), then set the Subnet Mask to<br />

255.255.255.0 and Default Gateway to 192.168.0.1.<br />

6. Do not enable any of the following options (unless you know what you are doing):<br />

♦ 'Automatic DHCP Configuration' : Unless you have a DHCP server running on your<br />

network.<br />

♦ Put anything in the 'WINS Server' input areas : Unless you have setup one or more WINS<br />

servers.<br />

♦ Enable <strong>IP</strong> Forwardings : Unless you are routing on your NT machine and really<br />

−REALLY− know EXACTLY what you're doing.<br />

7. Click 'DNS', fill in the appropriate information that your <strong>Linux</strong> host uses (usually found in<br />

/etc/resolv.conf) and then click 'OK' when you're done.<br />

8. Click 'Advanced', be sure to DISABLE 'DNS for Windows Name Resolution' and 'Enable<br />

LMHOSTS lookup' unless you known what these options do. If you want to use a LMHOSTS file, it<br />

is stored in C:\winnt\system32\drivers\etc.<br />

9. Click 'OK' on all dialog boxes and restart the system.<br />

10. As an initial test, ping the <strong>Linux</strong> MASQ server to test the network connection:<br />

'File/Run', type: ping 192.168.0.1(This is only an INTERNAL LAN connection test, you you<br />

might not be able to ping the outside world yet.) If you don't see any "replies" to your PINGs, please<br />

verify your network configuration.<br />

4.3. Configuring Windows for Workgroup 3.11<br />

1. If you haven't installed your network card and adapter driver, do so now. Descriptions to perform this<br />

task is beyond the scope of this document.<br />

2. Install the TCP/<strong>IP</strong> 32b package if you haven't already.<br />

3. In 'Main'/'Windows Setup'/'Network Setup', click on 'Drivers'.<br />

4. Highlight 'Microsoft TCP/<strong>IP</strong>−32 3.11b' in the 'Network Drivers' section, click 'Setup'.<br />

5. Set the <strong>IP</strong> Address to 192.168.0.x (1 < x < 255), then set the Subnet Mask to 255.255.255.0 and<br />

Default Gateway to 192.168.0.1<br />

6. Do not enable any of the following options (unless you know what you are doing):<br />

♦ 'Automatic DHCP Configuration' : Unless you have a DHCP server running on your<br />

network.<br />

♦ Put anything in the 'WINS Server' input areas : Unless you have setup one or more WINS<br />

servers.<br />

7. Click 'DNS', fill in the appropriate information your <strong>Linux</strong> host uses (usually found in<br />

/etc/resolv.conf). <strong>The</strong>n click 'OK' when you're done with it.<br />

8. Click 'Advanced', check 'Enable DNS for Windows Name Resolution' and 'Enable LMHOSTS<br />

Chapter 4. Configuring the other internal to−be MASQed machines 62


lookup' found in c:\windows.<br />

9. Click 'OK' in all dialog boxes and restart the system.<br />

10. As an initial test, ping the linux box to test the network connection: 'File/Run', type: ping<br />

192.168.0.1 (This is only an INTERNAL LAN connection test so you might not be able to ping<br />

the outside world yet.) If you don't see "replies" to your PINGs, please verify your network<br />

configuration.<br />

4.4. Configuring UNIX Based Systems<br />

1. If you haven't installed your network card and either re−configured the network subsystem or<br />

recompiled your kernel with the appropriate adapter driver, do so now. Descriptions to perform this<br />

task is beyond the scope of this document but are covered in the Networking <strong>HOWTO</strong>.<br />

2. Install TCP/<strong>IP</strong> networking, such as the net−tools package, if you don't have it already.<br />

3. Set <strong>IP</strong>ADDR to 192.168.0.x (1 < x < 255), then set NETMASK to 255.255.255.0, GATEWAY to<br />

192.168.0.1, and BROADCAST to 192.168.0.255.<br />

♦ Redhat (Mandrake / Turbo<strong>Linux</strong> / etc): You can edit the<br />

/etc/sysconfig/network−scripts/ifcfg−eth0 file, or simply do so through the<br />

Control Panel (<strong>Linux</strong>conf).<br />

♦ Slackware: You need to edit the /etc/rc.d/rc.inet1 file to configure the network subsystem.<br />

♦ To Add: Debian, Suse, Caldera, etc. Please email dranch@trinnet.net if you can tell me what<br />

distro uses what files to configure the networking subsystem.<br />

Beyond this, most <strong>Linux</strong> distributions use significantly different network configuration mechanisms<br />

let alone other UNIXes such as SunOS, BSDi, Solaris, AIX, TruUnix, FreeBSD, etc.). Please refer to<br />

your specific UNIX documentation for more details.<br />

4. Add your domain name service (DNS) and domain search suffix in /etc/resolv.conf and for<br />

the appropreiate UNIX versions, edit the /etc/nsswitch.conf file to enable DNS services.<br />

5. You may also want to update your /etc/networks file depending on your version of UNIX and<br />

the system's settings.<br />

6. Restart the appropriate services, or simply restart your system.<br />

7. As an initial test, run the ping command: ping 192.168.0.1 to test the connection to your<br />

gateway machine. (This is only an INTERNAL LAN connection test, so you might not be able to<br />

ping the outside world yet.) If you don't see "replies" to your PINGs, please verify your network<br />

configuration.<br />

4.5. Configuring DOS using NCSA Telnet package<br />

1. If you haven't installed your network card, do so now. Descriptions to perform this task is beyond the<br />

scope of this document.<br />

2. Load the appropriate packet driver. For example: an NE2000 Ethernet card set for I/O port 300 and<br />

IRQ 10, would need to be issued nwpd 0x60 10 0x300<br />

3. Make a new directory, and then unpack the NCSA Telnet package: pkunzip tel2308b.zip<br />

4. Use a text editor to open the config.tel file<br />

5. Set myip=192.168.0.x (1 < x < 255), and netmask=255.255.255.0<br />

6. In this example, you should set hardware=packet, interrupt=10, ioaddr=60<br />

7. You should have at least one individual machine specified as the gateway, i.e. the <strong>Linux</strong> host:<br />

name=default<br />

host=yourlinuxhostname<br />

hostip=192.168.0.1<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 4. Configuring the other internal to−be MASQed machines 63


8.<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

gateway=1<br />

Have another specified as a domain name service:<br />

name=dns.domain.com ; hostip=123.123.123.123; nameserver=1<br />

Note: substitute the appropriate information about the DNS according what your <strong>Linux</strong> host uses<br />

9. Save your config.tel file<br />

10. As an initial test, ping the <strong>Linux</strong> MASQ server to test the network connection: ping<br />

192.168.0.1 If you don't receive any replies, please verify your network configuration.<br />

4.6. Configuring MacOS Based System Running MacTCP<br />

1. If you haven't installed the appropriate driver software for your Ethernet adapter, do so now.<br />

Descriptions to perform this task is beyond the scope of this document.<br />

2. Open the MacTCP control panel. Select the appropriate network driver (Ethernet, NOT EtherTalk)<br />

and click on the 'More...' button.<br />

3. Under 'Obtain Address:', click 'Manually'.<br />

4. Under '<strong>IP</strong> Address:', select class C from the popup menu. Ignore the rest of the dialog box sections.<br />

5. Fill in the appropriate information under 'Domain Name Server Information:'.<br />

6. Under 'Gateway Address:', enter 192.168.0.1<br />

7. Click 'OK' to save the settings. In the main window of the MacTCP control panel, enter the <strong>IP</strong><br />

address of your Mac (192.168.0.x, 1 < x < 255) in the '<strong>IP</strong> Address:' box.<br />

8. Close the MacTCP control panel. If a dialog box pops up, notifying you to do so, then restart the<br />

system.<br />

9. You may optionally ping the <strong>Linux</strong> box to test the network connection. If you have the freeware<br />

program MacTCP Watcher , click on the 'Ping' button, and enter the address of your <strong>Linux</strong> box<br />

(192.168.0.1) in the dialog window that pops up. (This is only an INTERNAL LAN connection test,<br />

you can't ping the outside world yet.) If you don't see "replies" to your PINGs, please verify your<br />

network configuration.<br />

10. You can optionally create a Hosts file in your System Folder so that you can use the hostnames of<br />

the machines on your LAN. <strong>The</strong> file should already exist in your System Folder, and should contain<br />

some (commented−out) sample entries which you can modify according to your needs.<br />

4.7. Configuring MacOS Based System Running Open<br />

Transport<br />

1. If you haven't installed the appropriate driver software for your Ethernet adapter, do so now.<br />

Descriptions to perform this task is beyond the scope of this document.<br />

2. Open the TCP/<strong>IP</strong> Control Panel and choose 'User Mode ...' from the Edit menu. Make sure the user<br />

mode is set to at least 'Advanced' and click the 'OK' button.<br />

3. Choose 'Configurations...' from the File menu. Select your 'Default' configuration and click the<br />

'Duplicate...' button. Enter '<strong>IP</strong> Masq' (or something to let you know that this is a special<br />

configuration) in the 'Duplicate Configuration' dialog, it will probably say something like 'Default<br />

copy'. <strong>The</strong>n click the 'OK' button, and the 'Make Active' button<br />

4. Select 'Ethernet' from the 'Connect via:' pop−up.<br />

5. Select the appropriate item from the 'Configure:' pop−up. If you don't know which option to choose,<br />

you probably should re−select your 'Default' configuration and quit. I use 'Manually'.<br />

6. Enter the <strong>IP</strong> address of your Mac (192.168.0.x, 1 < x < 255) in the '<strong>IP</strong> Address:' box.<br />

7. Enter 255.255.255.0 in the 'Subnet mask:' box.<br />

8. Enter 192.168.0.1 in the 'Router address:' box.<br />

Chapter 4. Configuring the other internal to−be MASQed machines 64


9. Enter the <strong>IP</strong> addresses of your domain name servers in the 'Name server addr.:' box.<br />

10. Enter the name of your Internet domain (e.g. 'microsoft.com') in the 'Starting domain name' box<br />

under 'Implicit Search Path:'.<br />

11. <strong>The</strong> following procedures are optional. Incorrect values may cause erratic behavior. If you're not sure,<br />

it's probably better to leave them blank, unchecked and/or un−selected. Remove any information from<br />

those fields, if necessary. As far as I know, there is no way to use the TCP/<strong>IP</strong> dialogs to tell the<br />

system not to use a previously selected alternate "Hosts" file. If you know, I would be interested.<br />

Check the '802.3' if your network requires 802.3 frame types.<br />

12. Click the 'Options...' button to make sure that the TCP/<strong>IP</strong> is active. I use the 'Load only when<br />

needed' option. If you continuously run and quit TCP/<strong>IP</strong> applications without rebooting your<br />

machine, you may find that unchecking the 'Load only when needed' option will prevent/reduce the<br />

effects on your machine's memory management. With the item unchecked, the TCP/<strong>IP</strong> protocol stacks<br />

are always loaded and available for use. If checked, the TCP/<strong>IP</strong> stacks are automatically loaded when<br />

needed and un−loaded when not. It's the loading and unloading process that can cause your machine's<br />

memory to become fragmented.<br />

13. You may ping the <strong>Linux</strong> box to test the network connection. If you have the freeware program<br />

MacTCP Watcher, click on the 'Ping' button, and enter the address of your <strong>Linux</strong> box (192.168.0.1)<br />

in the dialog box that pops up. (This is only an INTERNAL LAN connection test, you can't ping the<br />

outside world yet.) If you don't see "replies" to your PINGs, please verify your network configuration.<br />

14. You can optionally create a Hosts file in your System Folder so that you can use the hostnames of<br />

the machines on your LAN. <strong>The</strong> file may or may not already exist in your System Folder. If so, it<br />

should contain some (commented−out) sample entries which you can modify according to your needs.<br />

If not, you can get a copy of the file from a system running MacTCP, or just create your own (it<br />

follows a subset of the Unix /etc/hosts file format, described on RFC1035). Once you've created<br />

the file, open the TCP/<strong>IP</strong> control panel, click on the 'Select Hosts File...' button, and open the<br />

Hosts file.<br />

15. Click the close box or choose 'Close' or 'Quit' from the File menu, and then click the 'Save' button to<br />

save the changes you have made.<br />

16. <strong>The</strong> changes take effect immediately, but rebooting the system won't hurt.<br />

4.8. Configuring Novell network using DNS<br />

1. If you haven't installed the appropriate driver software for your Ethernet adapter, do so now.<br />

Descriptions to perform this task is beyond the scope of this document.<br />

2. Downloaded tcpip16.exe from <strong>The</strong> Novell LanWorkPlace page<br />

3. edit c:\nwclient\startnet.bat: (here is a copy of mine)<br />

SET NWLANGUAGE=ENGLISH<br />

LH LSL.COM<br />

LH KTC2000.COM<br />

LH <strong>IP</strong>XODI.COM<br />

LH tcpip<br />

LH VLM.EXE<br />

F:<br />

4. edit c:\nwclient\net.cfg: (change link driver to yours i.e. NE2000)<br />

Link Driver KTC2000<br />

Protocol <strong>IP</strong>X 0 ETHERNET_802.3<br />

Frame ETHERNET_802.3<br />

Frame Ethernet_II<br />

FRAME Ethernet_802.2<br />

NetWare DOS Requester<br />

FIRST NETWORK DRIVE = F<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 4. Configuring the other internal to−be MASQed machines 65


USE DEFAULTS = OFF<br />

VLM = CONN.VLM<br />

VLM = <strong>IP</strong>XNCP.VLM<br />

VLM = TRAN.VLM<br />

VLM = SECURITY.VLM<br />

VLM = NDS.VLM<br />

VLM = BIND.VLM<br />

VLM = NWP.VLM<br />

VLM = FIO.VLM<br />

VLM = GENERAL.VLM<br />

VLM = REDIR.VLM<br />

VLM = PRINT.VLM<br />

VLM = NETX.VLM<br />

Link Support<br />

Buffers 8 1500<br />

MemPool 4096<br />

Protocol TCP<strong>IP</strong><br />

PATH SCR<strong>IP</strong>T C:\NET\SCR<strong>IP</strong>T<br />

PATH PROFILE C:\NET\PROFILE<br />

PATH LWP_CFG C:\NET\HSTACC<br />

PATH TCP_CFG C:\NET\TCP<br />

ip_address 192.168.0.xxx<br />

ip_router 192.168.0.1<br />

Change the <strong>IP</strong> address in the above "ip_address" field (192.168.0.x, 1 < x<br />

< 255) and finally create c:\bin\resolv.cfg:<br />

SEARCH DNS HOSTS SEQUENTIAL<br />

NAMESERVER xxx.xxx.xxx.xxx<br />

NAMESERVER yyy.yyy.yyy.yyy<br />

5. Now edit the above "NAMESERVER" entries and replace them with the correct <strong>IP</strong> addresses for your<br />

local DNS server.<br />

6. Issue a ping command: ping 192.168.0.1 to test the connection to your gateway machine.<br />

(This is only an INTERNAL LAN connection test, you can't ping the outside world yet.) If you don't<br />

see "replies" to your PINGs, please verify your network configuration.<br />

4.9. Configuring OS/2 Warp<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

1. If you haven't installed the appropriate driver software for your Ethernet adapter, do so now.<br />

Descriptions to perform this task is beyond the scope of this document.<br />

2. Install the TCP/<strong>IP</strong> protocol if you don't have it already.<br />

3. Go to Programs/TCP/<strong>IP</strong> (LAN) / TCP/<strong>IP</strong> Settings<br />

4. In 'Network', add your TCP/<strong>IP</strong> Address (192.168.0.x) and set your netmask (255.255.255.0)<br />

5. Under 'Routing', press 'Add'. Set the Type to 'default' and type the <strong>IP</strong> Address of your <strong>Linux</strong> Box in<br />

the Field 'Router Address'. (192.168.0.1).<br />

6. Set the same DNS (Nameserver) Address that your <strong>Linux</strong> host uses in 'Hosts'.<br />

7. Close the TCP/<strong>IP</strong> control panel. Say yes to the following question(s).<br />

8. Reboot your system<br />

9. You may ping the <strong>Linux</strong> box to test the network configuration. Type 'ping 192.168.0.1' in a<br />

'OS/2 Command prompt Window'. When ping packets are received all is ok.<br />

Chapter 4. Configuring the other internal to−be MASQed machines 66


4.10. Configuring OS/400 on a IBM AS/400<br />

<strong>The</strong> descriptions to configure TCP/<strong>IP</strong> on OS/400 version V4R1M0 running on a AS/400 is beyond the scope<br />

of this document.<br />

1) To perform any communications configuration tasks on your AS/400, you must have the special authority<br />

of *IOSYSCFG (I/O System Configuration) defined in your user profile. You can check the characteristics of<br />

your user profile with the DSPUSRPRF command.<br />

2) Type GO CFGTCP command th reach the Configure TCP/<strong>IP</strong> menu.<br />

3) Select Option 2 − Work with TCP/<strong>IP</strong> Routes.<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

4) Enter a 1 on the Opt field to add a route. * In Route Destination type *DFTROUTE * In Subnet Mask type<br />

*NONE * In Type of Service type *NORMAL * In Nex Hop type the address of your gataway (the <strong>Linux</strong><br />

box)<br />

4.11. Configuring Other Systems<br />

<strong>The</strong> same logic should apply to setting up other platforms. Consult the sections above. If you're interested in<br />

writing about any of systems that have not been covered yet, please send a detail setup instruction to<br />

ambrose@writeme.com and dranch@trinnet.net.<br />

Chapter 4. Configuring the other internal to−be MASQed machines 67


Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong><br />

Finally, it's time to give <strong>IP</strong> Masquerading an official try after all this hard work. If you haven't already<br />

rebooted your <strong>Linux</strong> box, do so to make sure the machines boots ok, executes the /etc/rc.d/rc.firewall−*<br />

ruleset, etc. Next, make sure that both the internal LAN connection and connection of your <strong>Linux</strong> hosts to the<br />

Internet is okay.<br />

Follow these −11− tests to make sure all aspects of your MASQ setup is running properly:<br />

5.1. Loading up the rc.firewall ruleset<br />

Step One: run the correct firewall for your machine via command "/etc/rc.d/rc.firewall−[iptables / ipchains<br />

/ipfwadm]". For example, <strong>Linux</strong> 2.6 users would run "/etc/rc.d/rc.firewall−iptables"<br />

Does it load with some strange errors? Here are some exmaples and help to fix them:<br />

• Problem #1:<br />

ip_tables, Using /lib/modules/2.4.2−2/kernel/net/ipv4/netfilter/ip_tables.o<br />

/lib/modules/2.4.2−2/kernel/net/ipv4/netfilter/ip_tables.o: init_module: Device<br />

or resource busy<br />

Hint: insmod errors can be caused by incorrect module parameters, including<br />

invalid IO or IRQ parameters<br />

Run the command "/sbin/lsmod" and make sure the module "ipchains.o" is NOT installed. If it is<br />

installed, your machine (most likely Redhat−7.x based) is probably trying to load an <strong>IP</strong>CHAINS<br />

ruleset which is incompatible with <strong>IP</strong>TABLES.<br />

To disable this from happening in the future, run the command:<br />

chkconfig −−level=2345 ipchains off<br />

To remove the "ipchains" module without rebooting, run the command:<br />

/sbin/rmmod ipchains<br />

and the re−try to load the rc.firewall−* ruleset.<br />

• Problem #2:<br />

.<br />

.<br />

Creating a DROP chain..<br />

iptables v1.2.3: log−level `info' ambiguous<br />

.<br />

.<br />

Your version of <strong>IP</strong>TABLES it too old. You need to upgrade it with a newer version via an updated<br />

RPM, DEB, or via compiling up the source. You can get an updated version from your <strong>Linux</strong><br />

distribution manufacturer or from the NetFilter WWW site. This is all covered in the Section 2.6<br />

section.<br />

• Problem #3:<br />

Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong> 68


No such file:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Did you copy this rc.firewall−* file from a DOS machine? Load the rc.firewall−* file in a binary<br />

editor such as ViM (vim −b /etc/rc.d/rc.firewall−*) and make sure that every line is NOT finished<br />

with a ^M.<br />

5.2. Testing internal MASQ client PC connectivity<br />

• Step Two: Testing internal MASQ client PC connectivity<br />

From an internal MASQed computer, try pinging its local <strong>IP</strong> address (i.e. ping 192.168.0.10 ). This<br />

will verify that TCP/<strong>IP</strong> is correctly working on the local machine. Almost ALL modern operating<br />

systems have built−in support for the "ping" command. If this ping doesn't work, make sure that<br />

TCP/<strong>IP</strong> is correctly configured on the MASQed PC as described earlier in Chapter 4 of this <strong>HOWTO</strong>.<br />

<strong>The</strong> output should look something like the following (hit Control−C to abort the ping):<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

masq−client# ping 192.168.0.10<br />

PING 192.168.0.10 (192.168.0.10): 56 data bytes<br />

64 bytes from 192.168.0.10: icmp_seq=0 ttl=255 time=0.8 ms<br />

64 bytes from 192.168.0.10: icmp_seq=1 ttl=255 time=0.4 ms<br />

64 bytes from 192.168.0.10: icmp_seq=2 ttl=255 time=0.4 ms<br />

64 bytes from 192.168.0.10: icmp_seq=3 ttl=255 time=0.5 ms<br />

^C<br />

−−− 192.168.0.10 ping statistics −−−<br />

4 packets transmitted, 4 packets received, 0% packet loss<br />

round−trip min/avg/max = 0.4/0.5/0.8 ms<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

5.3. Testing internal MASQ client to MASQ server<br />

connectivity<br />

• Step Three: Testing internal MASQ client to MASQ server connectivity<br />

Next, from the same internal MASQed computer, try pinging the the <strong>IP</strong> address of the <strong>Linux</strong> MASQ<br />

server's INTERNAL interface (i.e. ping 192.168.0.1 ). This will verify that TCP/<strong>IP</strong> is correctly<br />

working on both the local and <strong>Linux</strong> MASQ machine. Almost ALL modern operating systems have<br />

built−in support for the "ping" command. If this ping doesn't work, make sure that TCP/<strong>IP</strong> is correctly<br />

configured on the MASQed Server as described by the various Network <strong>HOWTO</strong>s (URLs can be<br />

found in the requirements section for your 2.4.x kernel in Section 2.6, 2.2.x kernel in Section 2.7, or<br />

2.0.x kernel in Section 2.8). <strong>The</strong> output should look something like the following (hit Control−C to<br />

abort the ping):<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

masq−client# ping 192.168.0.1<br />

PING 192.168.0.1 (192.168.0.1): 56 data bytes<br />

64 bytes from 192.168.0.1: icmp_seq=0 ttl=255 time=0.8 ms<br />

64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=0.4 ms<br />

64 bytes from 192.168.0.1: icmp_seq=2 ttl=255 time=0.4 ms<br />

64 bytes from 192.168.0.1: icmp_seq=3 ttl=255 time=0.5 ms<br />

^C<br />

Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong> 69


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

−−− 192.168.0.1 ping statistics −−−<br />

4 packets transmitted, 4 packets received, 0% packet loss<br />

round−trip min/avg/max = 0.4/0.5/0.8 ms<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

If the ping failed, check the network connection between the MASQ server and the PC. If it's a<br />

DIRECT Ethernet connection (no hub or switch), you MUST have a "Ethernet cross−over cable".<br />

<strong>The</strong>se cables are common and can be found at any computer store. Without this cable, the NICs<br />

(network cards) will not give you a "LINK" light. If you are using a hub or switch, make sure the<br />

ports connected to the MASQ server and MASQed client machine have a LINK light. If they do and<br />

the pings STILL don't work or there is a lot of packet loss, try different ports on the hub/switch (it not<br />

all that uncommon to have hub/switch ports die). Finally, if things still don't work perfectly, try<br />

replacing each of the NICs in the machines. You would be surprised how many people I've helped<br />

have found that their NIC cards were going bad and caused them all kinds of grief.<br />

5.4. Testing internal MASQ server connectivity<br />

• Step Four: Testing internal MASQ server connectivity<br />

On the MASQ server, ping the internal <strong>IP</strong> address of the MASQ server's network interface card (i.e.<br />

ping 192.168.0.1). If this ping doesn't work, make sure that TCP/<strong>IP</strong> is correctly configured on the<br />

MASQed Server as described by the various Network <strong>HOWTO</strong>s (URLs can be found in the<br />

requirements section for your 2.4.x kernel in Section 2.6, 2.2.x kernel in Section 2.7, or 2.0.x kernel in<br />

Section 2.8). <strong>The</strong> output should look something like the following (hit Control−C to abort the ping):<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

masq−server# ping 192.168.0.1<br />

PING 192.168.0.1 (192.168.0.1): 56 data bytes<br />

64 bytes from 192.168.0.1: icmp_seq=0 ttl=255 time=0.8 ms<br />

64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=0.4 ms<br />

64 bytes from 192.168.0.1: icmp_seq=2 ttl=255 time=0.4 ms<br />

64 bytes from 192.168.0.1: icmp_seq=3 ttl=255 time=0.5 ms<br />

^C<br />

−−− 192.168.0.1 ping statistics −−−<br />

4 packets transmitted, 4 packets received, 0% packet loss<br />

round−trip min/avg/max = 0.4/0.5/0.8 ms<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

5.5. Testing internal MASQ server to MASQ client<br />

connectivity<br />

• Step Five: Testing internal MASQ server to MASQ client connectivity<br />

Next from MASQed server, try pinging the <strong>IP</strong> address of one of the internal MASQ client computers<br />

(i.e. ping 192.168.0.10 ). This will verify that TCP/<strong>IP</strong> is correctly working on both the local server<br />

machine and on the MASQ client machine. If this ping doesn't work, make sure that TCP/<strong>IP</strong> is<br />

correctly configured on the MASQed PC as described earlier in Chapter 4 of this <strong>HOWTO</strong>. Also be<br />

sure that the cabling is correct (Ethernet: the NICs connecting the internal MASQ PC and the MASQ<br />

server have the "link" light lit up). If the ping does work, the output should look something like the<br />

following (hit Control−C to abort the ping):<br />

Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong> 70


−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

masq−server# ping 192.168.0.10<br />

PING 192.168.0.10 (192.168.0.10): 56 data bytes<br />

64 bytes from 192.168.0.10: icmp_seq=0 ttl=255 time=0.8 ms<br />

64 bytes from 192.168.0.10: icmp_seq=1 ttl=255 time=0.4 ms<br />

64 bytes from 192.168.0.10: icmp_seq=2 ttl=255 time=0.4 ms<br />

64 bytes from 192.168.0.10: icmp_seq=3 ttl=255 time=0.5 ms<br />

^C<br />

−−− 192.168.0.10 ping statistics −−−<br />

4 packets transmitted, 4 packets received, 0% packet loss<br />

round−trip min/avg/max = 0.4/0.5/0.8 ms<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

5.6. Testing External MASQ server Internet connectivity<br />

• Step Six: Testing external MASQ server to Internet connectivity<br />

From the MASQ server, ping the external <strong>IP</strong> address of the MASQ server's EXTERNAL network<br />

interface that is connected to the Internet. This address might be a Ethernet interface, a PPP interface,<br />

etc. connection to your ISP. If you don't know what this external <strong>IP</strong> address is, run the <strong>Linux</strong><br />

command "/sbin/ifconfig" on the MASQ server itself to get the Internet address. <strong>The</strong> output should<br />

look something like the following (we are looking for the <strong>IP</strong> address of eth0):<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

eth0 Link encap:Ethernet HWaddr 00:08:C7:A4:CC:5B<br />

inet addr:12.13.14.15 Bcast:12.13.14.255 Mask:255.255.255.0<br />

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1<br />

RX packets:6108459 errors:0 dropped:0 overruns:0 frame:0<br />

TX packets:5422798 errors:8 dropped:0 overruns:0 carrier:8<br />

collisions:4675 txqueuelen:100<br />

Interrupt:11 Base address:0xfcf0<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

As you can see from the above, the external <strong>IP</strong> address is "12.13.14.15" for this example. So, now that<br />

you have your <strong>IP</strong> address after running the "ipconfig" command, ping your external <strong>IP</strong> address. This<br />

will confirm that the MASQ server has full network connectivity. <strong>The</strong> output should look something<br />

like the following (hit Control−C to abort the ping):<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

masq−server# ping 12.13.14.15<br />

PING 12.13.14.15 (12.13.14.15): 56 data bytes<br />

64 bytes from 12.13.14.15: icmp_seq=0 ttl=255 time=0.8 ms<br />

64 bytes from 12.13.14.15: icmp_seq=1 ttl=255 time=0.4 ms<br />

64 bytes from 12.13.14.15: icmp_seq=2 ttl=255 time=0.4 ms<br />

64 bytes from 12.13.14.15: icmp_seq=3 ttl=255 time=0.5 ms<br />

^C<br />

−−− 12.13.14.15 ping statistics −−−<br />

4 packets transmitted, 4 packets received, 0% packet loss<br />

round−trip min/avg/max = 0.4/0.5/0.8 ms<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

If either of these tests doesn't work, you need to go back and double check your network cabling and<br />

verify that the two network interfaces on the MASQ server are seen in "dmesg". An example of this<br />

output would be the following towards the END of the "dmesg" command:<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong> 71


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

.<br />

.<br />

PPP: version 2.3.7 (demand dialling)<br />

TCP compression code copyright 1989 Regents of the University of California<br />

PPP line discipline registered.<br />

3c59x.c:v0.99H 11/17/98 Donald Becker<br />

http://cesdis.gsfc.nasa.gov/linux/drivers/<br />

vortex.html<br />

eth0: 3Com 3c905 Boomerang 100baseTx at 0xfe80, 00:60:08:a7:4e:0e, IRQ 9<br />

8K word−wide RAM 3:5 Rx:Tx split, autoselect/MII interface.<br />

MII transceiver found at address 24, status 786f.<br />

Enabling bus−master transmits and whole−frame receives.<br />

eth1: 3Com 3c905 Boomerang 100baseTx at 0xfd80, 00:60:97:92:69:f8, IRQ 9<br />

8K word−wide RAM 3:5 Rx:Tx split, autoselect/MII interface.<br />

MII transceiver found at address 24, status 7849.<br />

Enabling bus−master transmits and whole−frame receives.<br />

Partition check:<br />

sda: sda1 sda2 < sda5 sda6 sda7 sda8 ><br />

sdb:<br />

.<br />

.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

Also be sure that the cabling is correct (Ethernet: the NICs connecting the external MASQ server to<br />

your ISP has the "link" light lit up). Finally, make sure that TCP/<strong>IP</strong> is correctly configured on the<br />

MASQed Server as described by the various Network <strong>HOWTO</strong>s (URLs can be found in the<br />

requirements section for your 2.4.x kernel in Section 2.6, 2.2.x kernel in Section 2.7, or 2.0.x kernel in<br />

Section 2.8).<br />

5.7. Testing internal MASQ client to external MASQ server<br />

connectivity<br />

• Step Seven: Testing internal MASQ client to external MASQ server connectivity<br />

From an internal MASQed computer, ping the <strong>IP</strong> address of the MASQ server's EXTERNAL TCP/<strong>IP</strong><br />

address obtained in Step FIVE above. This address could be from your Ethernet, PPP, etc. interface<br />

which is ultimately the address connected to your ISP. This ping test will prove that <strong>Linux</strong><br />

masquerading (ICMP Masquerading specifically) and <strong>IP</strong> forwarding is working.<br />

If everthing thing is working correctly, the output should look something like the following (hit<br />

Control−C to abort the ping):<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

masq−client# ping 12.13.14.15<br />

PING 12.13.14.15 (12.13.14.15): 56 data bytes<br />

64 bytes from 12.13.14.15: icmp_seq=0 ttl=255 time=0.8 ms<br />

64 bytes from 12.13.14.15: icmp_seq=1 ttl=255 time=0.4 ms<br />

64 bytes from 12.13.14.15: icmp_seq=2 ttl=255 time=0.4 ms<br />

64 bytes from 12.13.14.15: icmp_seq=3 ttl=255 time=0.5 ms<br />

^C<br />

−−− 12.13.14.15 ping statistics −−−<br />

4 packets transmitted, 4 packets received, 0% packet loss<br />

round−trip min/avg/max = 0.4/0.5/0.8 ms<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

If this test doesn't work, first make sure that the "Default Gateway" on the MASQed PC is pointing to<br />

Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong> 72


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

the <strong>IP</strong> address on the MASQ −SERVERs− INTERNAL NIC. Also double check that the<br />

/etc/rc.d/rc.firewall−* script was run without any errors. Just as a test, try re−running the<br />

/etc/rc.d/rc.firewall−* script now to see if it runs OK. Also, though most kernels support it by default,<br />

make sure that you enabled "ICMP Masquerading" in the kernel comfiguration and "<strong>IP</strong> Forwarding"<br />

in your /etc/rc.d/rc.firewall−* script.<br />

If you still can't get things to work, take a look at the output from the following commands run on the<br />

<strong>Linux</strong> MASQ SERVER:<br />

♦ "ifconfig" : Make sure the interface for your Internet connection (be it ppp0, eth0, etc.) is UP<br />

and you have the correct <strong>IP</strong> address for the Internet connection. An example of this output is<br />

shown in STEP FIVE above.<br />

♦ "netstat −rn" : Make sure your default gateway (the column with an <strong>IP</strong> address in the<br />

Gateway column) is set. An example of this output might look like:<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

masq−server# netstat −rn<br />

Kernel <strong>IP</strong> routing table<br />

Destination Gateway Genmask Flags MSS Window irtt Iface<br />

192.168.0.1 0.0.0.0 255.255.255.255 UH 0 16384 0 eth1<br />

12.13.14.15 0.0.0.0 255.255.255.255 UH 0 16384 0 eth0<br />

12.13.14.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0<br />

192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1<br />

127.0.0.0 0.0.0.0 255.0.0.0 U 0 16384 0 lo<br />

0.0.0.0 12.13.14.1 0.0.0.0 UG 0 16384 0 eth0<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

Notice the very LAST line that starts with 0.0.0.0? Notice that it also has an <strong>IP</strong> address in the<br />

"Gateway" field? You should specify an <strong>IP</strong> address for your specific setup in that field (this is<br />

typically done automatically when your Internet connection is enabled).<br />

♦ "cat /proc/sys/net/ipv4/ip_forward" : Make sure it says "1" so that <strong>Linux</strong> forwarding is<br />

enabled<br />

♦ Run the command "/sbin/ipchains −n −L" for 2.2.x users or "/sbin/ipfwadm −F −l" for 2.0.x<br />

users. Specifically, look for the FORWARDing section to make sure you have MASQ<br />

enabled. An example of an <strong>IP</strong>CHAINS output might look like for users using the SIMPLE<br />

rc.firewall−* ruleset:<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

.<br />

.<br />

Chain forward (policy REJECT):<br />

target prot opt source destination ports<br />

MASQ all −−−−−− 192.168.0.0/24 0.0.0.0/0 n/a<br />

ACCEPT all −−−−l− 0.0.0.0/0 0.0.0.0/0 n/a<br />

.<br />

.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

5.8. Testing external MASQ ICMP forwarding<br />

• Step Eight: Testing external MASQ ICMP forwarding<br />

From an internal MASQed computer, ping a static TCP/<strong>IP</strong> address (NOT a machine by DNS name)<br />

out on the Internet (i.e. ping 152.2.210.80 (this technically the DNS name "metalab.unc.edu" which is<br />

home of MetaLabs' <strong>Linux</strong> Archive). If this works, it should look something like the result below and<br />

this ultimately shows that ICMP Masquerading is working properly. (hit Control−C to abort the ping):<br />

Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong> 73


−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

masq−client# ping 152.2.210.80<br />

PING 12.13.14.15 (152.2.210.80): 56 data bytes<br />

64 bytes from 152.2.210.80: icmp_seq=0 ttl=255 time=133.4 ms<br />

64 bytes from 152.2.210.80: icmp_seq=1 ttl=255 time=132.5 ms<br />

64 bytes from 152.2.210.80: icmp_seq=2 ttl=255 time=128.8 ms<br />

64 bytes from 152.2.210.80: icmp_seq=3 ttl=255 time=132.2 ms<br />

^C<br />

−−− 152.2.210.80 ping statistics −−−<br />

4 packets transmitted, 4 packets received, 0% packet loss<br />

round−trip min/avg/max = 128.8/131.7/133.4 ms<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

If this didn't work, again check your Internet connection. Make sure that the MASQ server itself can<br />

ping this address. If this works from the MASQ server, make sure you are using the simple<br />

rc.firewall−* ruleset and that you have ICMP Masqurading compiled into the <strong>Linux</strong> kernel.<br />

Finally, make sure that the ruleset which enables <strong>IP</strong> MASQ is pointing to the correct EXTERNAL<br />

interface. PPPoE users should use the MASQ servers's logical PPP interface such as "ppp0" and<br />

/NOT/ the physical external interface like "eth0".<br />

5.9. Testing MASQ functionality without DNS<br />

• Step Nine: Testing MASQ functionality without DNS<br />

Now try TELNETing to a remote <strong>IP</strong> address (i.e. telnet 152.2.210.81 ( this is technically the DNS<br />

name "metalab.unc.edu"). It might take a few seconds to get a login prompt since this is a VERY busy<br />

server. Did you get a login prompt like shown below? If so, it means that TCP Masquerading is<br />

running OK. If not, try TELNETing to some other hosts you think will support TELNET like<br />

198.182.196.55 (www.linux.org). If this still doesn't work, make sure you are using the simple<br />

rc.firewall−* ruleset for this test. An example of this output might look like (hit Control−D to exit out<br />

of the TELNET):<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

masq−client# telnet 152.2.210.80<br />

Trying 152.2.210.80...<br />

Connected to 152.2.210.80.<br />

Escape character is '^]'.<br />

SunOS 5.7<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

******************** Welcome to MetaLab.unc.edu *******************<br />

To login to MetaLab as a user, connect to login.metalab.unc.edu.<br />

This machine does not allow public telnet logins.<br />

login: Connection closed by foreign host.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong> 74


5.10. Testing MASQ functionality with DNS resolution<br />

• Step Ten: Testing MASQ functionality with DNS resolution<br />

Now try TELNETing to a remote machine by DNS name (i.e. "telnet metalab.unc.edu" (<strong>IP</strong> address<br />

152.2.210.81). If this works, the output should look like something below. With this test, this shows<br />

that UDP−based DNS is working fine.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

masq−client# telnet MetaLab.unc.edu<br />

Trying 152.2.210.80...<br />

Connected to 152.2.210.80.<br />

Escape character is '^]'.<br />

SunOS 5.7<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

******************** Welcome to MetaLab.unc.edu *******************<br />

To login to MetaLab as a user, connect to login.metalab.unc.edu.<br />

This machine does not allow public telnet logins.<br />

login: Connection closed by foreign host.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

If this did not work, but Step EIGHT did work, make sure that you have one or more valid DNS<br />

servers configured on each of the MASQ CLIENT computer(s) as shown in Chapter 4. Please note<br />

that these DNS servers will typically be your ISP's DNS servers and NOT your local MASQ server.<br />

Some people might later choose to setup their OWN DNS servers but this is beyond the scope of this<br />

<strong>HOWTO</strong>.<br />

5.11. Testing more MASQ functionality with DNS<br />

• Step Eleven: Testing more MASQ functionality with DNS<br />

As a last test, try browsing some 'INTERNET' WWW sites on one of your MASQ Client machines,<br />

and see if you can reach them. For example, access the <strong>Linux</strong> <strong>Documentation</strong> <strong>Project</strong> site at<br />

http://www.tldp.org. If you are successful in bringing up that page, you can be fairly certain that<br />

everything is working FINE! If some WWW or FTP sites have problems, where other sites seem to<br />

work just fine, see the next step for more ideas.<br />

If you see <strong>The</strong> <strong>Linux</strong> <strong>Documentation</strong> <strong>Project</strong> homepage, then CONGRATULATIONS! It's working!<br />

If the WWW site comes up correctly, then all other standard network tools such as PING, TELNET,<br />

SSH, and with their related <strong>IP</strong> MASQ modules loaded: FTP, Real Audio, IRC DCCs, Quake I/II/III,<br />

CuSeeme, VDOLive, etc. should work fine too! If FTP, IRC, RealAudio, Quake I/II/III, etc. aren't<br />

working or are performing poorly, verify that their associated Masquerading modules are loaded by<br />

running "lsmod" and also be sure you are loading the module with any non−default server ports. If<br />

you don't see your needed module, make sure your /etc/rc.d/rc.firewall−* script is loading them (i.e.<br />

remove the # character for a given <strong>IP</strong> MASQ module).<br />

Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong> 75


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

5.12. Any remaining functional, performance, etc. issues...<br />

• Step Twelve: Any remaining functional, performance, etc. issues...<br />

If your system passes all of the above tests, but functionality tests like WWW browsing, FTP, and<br />

other types of traffic aren't reliable or are slow, I recommend that you read the FAQ section of this<br />

<strong>HOWTO</strong>.. specifically the Section 7.15 FAQ entry. <strong>The</strong>re might be other items in the FAQ section<br />

that will also help you as they have helped many other users in the past.<br />

Chapter 5. Testing <strong>IP</strong> <strong>Masquerade</strong> 76


Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and<br />

Software Support<br />

6.1. Problems with <strong>IP</strong> <strong>Masquerade</strong><br />

Some TCP/<strong>IP</strong> application protocols will not currently work with <strong>Linux</strong> <strong>IP</strong> Masquerading because they either<br />

assume things about port numbers or encode TCP/<strong>IP</strong> addresses and/or port numbers in their data stream.<br />

<strong>The</strong>se latter protocols need specific proxies or <strong>IP</strong> MASQ modules built into the masquerading code to make<br />

them work.<br />

6.2. Incoming services<br />

By default, <strong>Linux</strong> <strong>IP</strong> Masquerading cannot handle incoming services at all but there are a few ways that would<br />

allow this.<br />

If you do not require high levels of security, then you can simply forward or redirect <strong>IP</strong> ports. <strong>The</strong>re are<br />

various ways to perform this, though the most stable method is to use <strong>IP</strong>PORTFW. For more information,<br />

please see Section 6.7.<br />

If you wish to have some level of authorization on incoming connections, then you will need to either<br />

configure TCP−wrappers or Xinetd to allow only specific <strong>IP</strong> addresses to pass. <strong>The</strong> TIS Firewall Toolkit is a<br />

good place to look for tools and information.<br />

More details on incoming security can be found in the TrinityOS document and at <strong>IP</strong> <strong>Masquerade</strong> Resource.<br />

6.3. Supported Client Software and Other Setup Notes<br />

"** <strong>The</strong> <strong>Linux</strong> <strong>Masquerade</strong> Application list has a lot of good information regarding applications that work<br />

through <strong>Linux</strong> <strong>IP</strong> masquerading. This site was recently taken over by Steve Grevemeyer, who implemented<br />

it with a full database backend. It's a great resource! "<br />

Generally, any application that uses standard TCP and UDP should work. If you have any suggestion, hints,<br />

etc., please see the <strong>IP</strong> <strong>Masquerade</strong> Resource for more details.<br />

6.3.1. Network Clients that −Work− with <strong>IP</strong> <strong>Masquerade</strong><br />

General Clients:<br />

Archie<br />

all supported platforms, file searching client (not all archie clients are supported)<br />

FTP<br />

all supported platforms, with the ip_masq_ftp.o kernel module for active FTP connections.<br />

Gopher client<br />

all supported platforms<br />

HTTP<br />

all supported platforms, WWW surfing<br />

IRC<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 77


all IRC clients on various supported platforms, DCC is supported via the ip_masq_irc.o module<br />

NNTP (USENET)<br />

all supported platforms, USENET news client<br />

PING<br />

all platforms, with ICMP Masquerading kernel option<br />

POP3<br />

all supported platforms, email clients<br />

SSH<br />

all supported platforms, Secure TELNET/FTP clients<br />

SMTP<br />

all supported platforms, email servers like Sendmail, Qmail, PostFix, etc.<br />

TELNET<br />

all supported platforms, remote session<br />

TRACEROUTE<br />

UNIX and Windows based platforms, some variations may not work<br />

VRML<br />

Windows(possibly all supported platforms), virtual reality surfing<br />

WAIS client<br />

all supported platforms<br />

Multimedia and Communication Clients:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

All H.323 programs<br />

− MS Netmeeting, Intel Internet Phone Beta , and other H.323 applications − <strong>The</strong>re are now two<br />

solutions to accomplish this through <strong>IP</strong>MASQed connections:<br />

<strong>The</strong>re is a stable BETA 2.2.x kernel module available on the MASQ WWW site or at<br />

http://www.coritel.it/projects/nat/implementation.htm to work with Microsoft Netmeeting v3.x code<br />

on 2.2.x kernels. <strong>The</strong>re is also another module version on the MASQ WWW site specifically for<br />

Netmeeting 2.x with 2.0.x kernels, but this does not support Netmeeting v3.x.<br />

Another commercial solution is the Equivalence's PhonePatch H.323 gateway.<br />

Alpha Worlds<br />

Windows, Client−Server 3D chat program<br />

CU−SeeMe<br />

all supported platforms, with the ip_masq_cuseeme module loaded, please see Section 6.8 for more<br />

details.<br />

ICQ<br />

all supported clients. Requires the <strong>Linux</strong> kernel to be either compiled with PORTFW support, have<br />

the ip_masq_icq module (2.2.x and 2.0.x only), or have a SOCKS proxy running. A full description of<br />

this configuration is in Section 6.9.<br />

Internet Phone 3.2<br />

Windows, Peer−to−peer audio communications, users can reach you only if you initiate the call, but<br />

those users cannot call you without a specific port forwarding setup. See Section 6.7for more details.<br />

Internet Wave Player<br />

Windows, network streaming audio<br />

Powwow<br />

Windows, Peer−to−peer Text audio whiteboard communications, users can reach you only if you<br />

initiate the call, but those users cannot call you without a specific port forwarding setup. See Section<br />

6.7for more details.<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 78


Real Audio Player<br />

Windows, network streaming audio, higher quality available with the ip_masq_raudio UDP module<br />

True Speech Player 1.1b<br />

Windows, network streaming audio<br />

VDOLive<br />

Windows, with the ip_masq_vdolive patch<br />

Worlds Chat 0.9a<br />

Windows, Client−Server 3D chat program<br />

Games − See Section 6.10for more details on the LooseUDP patch<br />

Battle.net<br />

Works but requires TCP ports 116, 118 and UDP port 6112 <strong>IP</strong>PORTFWed to the client game<br />

machine. See Section 6.7for more details. Please note that FSGS and Bnetd servers still require<br />

<strong>IP</strong>PORTFW because they have not been re−written to be NAT−friendly.<br />

BattleZone 1.4<br />

Works with LooseUDP patch and new NAT−friendly −− email David Ranch for the .DLLs from<br />

Activision<br />

Dark Reign 1.4<br />

Works with LooseUDP patch or requires TCP ports 116 and 118 and UDP port 6112 <strong>IP</strong>PORTFWed<br />

to the game machine. See Section 6.7for more details.<br />

Diablo<br />

Works with LooseUDP patch or requires TCP ports 116 and 118 and UDP port 6112 <strong>IP</strong>PORTFWed<br />

to the game machine. Newer versions of Diablo use only TCP port 6112 and UDP port 6112. See<br />

Section 6.7for more details.<br />

Heavy Gear 2<br />

Works with LooseUDP patch or requires TCP ports 116 and 118 and UDP port 6112 <strong>IP</strong>PORTFWed<br />

to the game machine. See Section 6.7for more details.<br />

Quake I/II/III<br />

Works right out of the box but requires the ip_masq_quake module if there are more than one Quake<br />

I/II/III player behind a MASQ box. Also, this module only supports Quake I and QuakeWorld by<br />

default. If you need to support Quake II or non−default server ports, please see the module install<br />

section of Section 3.4.3 and Section 3.4.2 rulesets.<br />

StarCraft<br />

Works with the LooseUDP patch, <strong>IP</strong>PORTFWing TCP, and UDP ports 6112 to the internal MASQed<br />

game machine. See Section 6.7for more details.<br />

WorldCraft<br />

Works with LooseUDP patch<br />

Other Clients:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

<strong>Linux</strong> net−acct package<br />

<strong>Linux</strong>, network administration−account package<br />

NCSA Telnet 2.3.08<br />

DOS, a suite containing telnet, ftp, ping, etc.<br />

PC−anywhere for Windows<br />

MS−Windows remotely controls a PC over TCP/<strong>IP</strong>, but only works if it is a client, but not a host<br />

without a specific port forwarding setup. See Section 6.7for more details.<br />

Socket Watch<br />

uses NTP − network time protocol<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 79


6.3.2. Clients that do not have full support in <strong>IP</strong> MASQ:<br />

Intel Streaming Media Viewer Beta 1<br />

Cannot connect to server<br />

Netscape CoolTalk<br />

Cannot connect to opposite side<br />

WebPhone<br />

Cannot work at present (it makes invalid assumptions about addresses).<br />

6.4. Stronger firewall rulesets to run after initial testing<br />

6.4.1. Stronger <strong>IP</strong> Firewall (<strong>IP</strong>TABLES) rulesets<br />

<br />

#!/bin/sh<br />

#<br />

# rc.firewall−iptables−stronger<br />

#<br />

FWVER=0.88s<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# An example of a stronger <strong>IP</strong>TABLES firewall with <strong>IP</strong> <strong>Masquerade</strong><br />

# support for 2.4.x kernels.<br />

#<br />

# Log:<br />

#<br />

# 0.88s − Updated the commands for dynamically addresses machines and<br />

# to point to an expanded FAQ section for more information<br />

#<br />

# 0.87s − Removed the unused drop−and−logit chain as it was only later<br />

# being deleted anyway<br />

# 0.86s − Fixed a typo that had a preceeding ; instead of a #<br />

# 0.85s − renamed from rc.firewall−2.4−stronger to rc.firewall−iptables−<br />

# stronger to reflect this script works for all <strong>IP</strong>TABLES enabled<br />

# platforms including 2.6.x kernels<br />

# − fixed an incorrect /24 netmask for the INT<strong>IP</strong> variable<br />

# − removed the unneeded SED variable<br />

# 0.84s − Changed the defaults from 192.168.1.0 to 192.168.0.x to align<br />

# with the rest of the <strong>IP</strong>MASQ howto<br />

# 0.83s − Added additional comments to make PORTFW configs more obvious<br />

# 0.82s − Added a special ICMP filter to work around a Netfilter security<br />

# issue<br />

# − renamed the drop−and−log−it rule to reject−and−log−it<br />

# 0.81s − Added an additional comment in the INPUT section for NOT<br />

# allowing all traffic in, but only select traffic<br />

# 0.80s − Added a DISABLED ip_nat_irc kernel module section, changed the<br />

# default of the ip_conntrack_irc to NOT load by default, and<br />

# added additional kernel module comments<br />

# 0.79s − ruleset now uses modprobe instead of insmod<br />

# 0.78s − REJECT is not a legal policy yet; back to DROP<br />

# 0.77s − Changed the default block behavior to REJECT not DROP<br />

# 0.76s − Added a comment about the OPTIONAL WWW ruleset and a comment<br />

# where to put optional PORTFW commands<br />

# 0.75s − Added clarification that PPPoE users need to use<br />

# "ppp0" instead of "eth0" for their external interface<br />

# 0.74s − Changed the EXT<strong>IP</strong> command to work on NON−English distros<br />

# 0.73s − Added comments in the output section that DHCPd is optional<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 80


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# and changed the default settings to disabled<br />

# 0.72s − Changed the filter from the INTNET to the INT<strong>IP</strong> to be<br />

# stateful; moved the command VARs to the top and made the<br />

# rest of the script to use them<br />

# 0.70s − Added a disabled examples for allowing internal DHCP<br />

# and external WWW access to the server<br />

# 0.63s − Added support for the IRC module<br />

# 0.62s − Initial version based upon the basic 2.4.x rc.firewall<br />

echo −e "\nLoading rc.firewall−iptables−STRONGER − version $FWVER..\n"<br />

# <strong>The</strong> location of various iptables and other shell programs<br />

#<br />

# If your <strong>Linux</strong> distribution came with a copy of iptables, most<br />

# likely it is located in /sbin. If you manually compiled<br />

# iptables, the default location is in /usr/local/sbin<br />

#<br />

# ** Please use the "whereis iptables" command to figure out<br />

# ** where your copy is and change the path below to reflect<br />

# ** your setup<br />

#<br />

#<strong>IP</strong>TABLES=/sbin/iptables<br />

<strong>IP</strong>TABLES=/usr/local/sbin/iptables<br />

#<br />

LSMOD=/sbin/lsmod<br />

DEPMOD=/sbin/depmod<br />

MODPROBE=/sbin/modprobe<br />

GREP=/bin/grep<br />

AWK=/bin/awk<br />

IFCONFIG=/sbin/ifconfig<br />

#Setting the EXTERNAL and INTERNAL interfaces for the network<br />

#<br />

# Each <strong>IP</strong> <strong>Masquerade</strong> network needs to have at least one<br />

# external and one internal network. <strong>The</strong> external network<br />

# is where the natting will occur and the internal network<br />

# should preferably be addressed with a RFC1918 private address<br />

# scheme.<br />

#<br />

# For this example, "eth0" is external and "eth1" is internal"<br />

#<br />

# NOTE: If this doesnt EXACTLY fit your configuration, you must<br />

# change the EXTIF or INTIF variables above. For example:<br />

#<br />

# If you are a PPPoE or analog modem user:<br />

#<br />

# EXTIF="ppp0"<br />

#<br />

EXTIF="eth0"<br />

INTIF="eth1"<br />

echo " External Interface: $EXTIF"<br />

echo " Internal Interface: $INTIF"<br />

echo " −−−"<br />

# Specify your Static <strong>IP</strong> address here or let the script take care of it<br />

# for you.<br />

#<br />

# If you prefer to use STATIC addresses in your firewalls, un−# out the<br />

# static example below and # out the dynamic line. If you don't care,<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 81


# just leave this section alone.<br />

#<br />

# If you have a DYNAMIC <strong>IP</strong> address, the ruleset already takes care of<br />

# this for you. Please note that the different single and double quote<br />

# characters and the script MATTER.<br />

#<br />

#<br />

# PPP and DHCP (Cablemodem and DSL ) users:<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# PPP: If you get your TCP/<strong>IP</strong> address via DHCP, **you will need ** to<br />

# enable the # #ed out command below underneath the PPP section AND<br />

# replace the word "eth0" with the name of your EXTERNAL Internet<br />

# connection (ppp0, ippp0, etc) on the lines for "ppp−ip" and "extip".<br />

#<br />

# DHCP and PPP users: <strong>The</strong> remote DHCP or PPP server can and will change<br />

# <strong>IP</strong> addresses on you over time. To deal with this, users should configure<br />

# their DHCP or PPP client to re−run the rc.firewall−* ruleset everytime<br />

# the <strong>IP</strong> address is changed. Please see the "masq−and−dyn−addr" FAQ entry<br />

# in the <strong>IP</strong>MASQ howto for full details on how to do this.<br />

#<br />

#<br />

# Determine the external <strong>IP</strong> automatically:<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

#<br />

# <strong>The</strong> following line will determine your external <strong>IP</strong> address. This<br />

# line is somewhat complex and confusing but it will also work for<br />

# all NON−English <strong>Linux</strong> distributions:<br />

#<br />

EXT<strong>IP</strong>="`$IFCONFIG $EXTIF | $AWK \<br />

/$EXTIF/'{next}//{split($0,a,":");split(a[2],a," ");print a[1];exit}'`"<br />

# For users who wish to use STATIC <strong>IP</strong> addresses:<br />

#<br />

# # out the EXT<strong>IP</strong> line above and un−# out the EXT<strong>IP</strong> line below<br />

#<br />

#EXT<strong>IP</strong>="your.static.PPP.address"<br />

echo " External <strong>IP</strong>: $EXT<strong>IP</strong>"<br />

echo " −−−"<br />

# Assign the internal TCP/<strong>IP</strong> network and <strong>IP</strong> address<br />

INTNET="192.168.0.0/24"<br />

INT<strong>IP</strong>="192.168.0.1/32"<br />

echo " Internal Network: $INTNET"<br />

echo " Internal <strong>IP</strong>: $INT<strong>IP</strong>"<br />

echo " −−−"<br />

# Setting a few other local variables<br />

#<br />

UNIVERSE="0.0.0.0/0"<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#======================================================================<br />

#== No editing beyond this line is required for initial MASQ testing ==<br />

# Need to verify that all modules have all required dependencies<br />

#<br />

echo " − Verifying that all kernel modules are ok"<br />

$DEPMOD −a<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 82


echo −en " Loading kernel modules: "<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# With the new <strong>IP</strong>TABLES code, the core MASQ functionality is now either<br />

# modular or compiled into the kernel. This <strong>HOWTO</strong> shows ALL <strong>IP</strong>TABLES<br />

# options as MODULES. If your kernel is compiled correctly, there is<br />

# NO need to load the kernel modules manually.<br />

#<br />

# NOTE: <strong>The</strong> following items are listed ONLY for informational reasons.<br />

# <strong>The</strong>re is no reason to manual load these modules unless your<br />

# kernel is either mis−configured or you intentionally disabled<br />

# the kernel module autoloader.<br />

#<br />

# Upon the commands of starting up <strong>IP</strong> Masq on the server, the<br />

# following kernel modules will be automatically loaded:<br />

#<br />

# NOTE: Only load the <strong>IP</strong> MASQ modules you need. All current <strong>IP</strong> MASQ<br />

# modules are shown below but are commented out from loading.<br />

# ===============================================================<br />

#Load the main body of the <strong>IP</strong>TABLES module − "ip_tables"<br />

# − Loaded automatically when the "iptables" command is invoked<br />

#<br />

# − Loaded manually to clean up kernel auto−loading timing issues<br />

#<br />

echo −en "ip_tables, "<br />

#<br />

#Verify the module isn't loaded. If it is, skip it<br />

#<br />

if [ −z "` $LSMOD | $GREP ip_tables | $AWK {'print $1'} `" ]; then<br />

$MODPROBE ip_tables<br />

fi<br />

#Load the <strong>IP</strong>TABLES filtering module − "iptable_filter"<br />

#<br />

# − Loaded automatically when filter policies are activated<br />

#Load the stateful connection tracking framework − "ip_conntrack"<br />

#<br />

# <strong>The</strong> conntrack module in itself does nothing without other specific<br />

# conntrack modules being loaded afterwards such as the "ip_conntrack_ftp"<br />

# module<br />

#<br />

# − This module is loaded automatically when MASQ functionality is<br />

# enabled<br />

#<br />

# − Loaded manually to clean up kernel auto−loading timing issues<br />

#<br />

echo −en "ip_conntrack, "<br />

#<br />

#Verify the module isn't loaded. If it is, skip it<br />

#<br />

if [ −z "` $LSMOD | $GREP ip_conntrack | $AWK {'print $1'} `" ]; then<br />

$MODPROBE ip_conntrack<br />

fi<br />

#Load the FTP tracking mechanism for full FTP tracking<br />

#<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 83


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# Enabled by default −− insert a "#" on the next line to deactivate<br />

#<br />

echo −e "ip_conntrack_ftp, "<br />

#<br />

#Verify the module isn't loaded. If it is, skip it<br />

#<br />

if [ −z "` $LSMOD | $GREP ip_conntrack_ftp | $AWK {'print $1'} `" ]; then<br />

$MODPROBE ip_conntrack_ftp<br />

fi<br />

#Load the IRC tracking mechanism for full IRC tracking<br />

#<br />

# Disabled by default −− insert a "#" on the next few lines to activate<br />

#<br />

# echo −en " ip_conntrack_irc, "<br />

#<br />

#Verify the module isn't loaded. If it is, skip it<br />

#<br />

# if [ −z "` $LSMOD | $GREP ip_conntrack_irc | $AWK {'print $1'} `" ]; then<br />

# $MODPROBE ip_conntrack_irc<br />

# fi<br />

#Load the general <strong>IP</strong>TABLES NAT code − "iptable_nat"<br />

# − Loaded automatically when MASQ functionality is turned on<br />

#<br />

# − Loaded manually to clean up kernel auto−loading timing issues<br />

#<br />

echo −en "iptable_nat, "<br />

#<br />

#Verify the module isn't loaded. If it is, skip it<br />

#<br />

if [ −z "` $LSMOD | $GREP iptable_nat | $AWK {'print $1'} `" ]; then<br />

$MODPROBE iptable_nat<br />

fi<br />

#Loads the FTP NAT functionality into the core <strong>IP</strong>TABLES code<br />

# Required to support non−PASV FTP.<br />

#<br />

# Enabled by default −− insert a "#" on the next line to deactivate<br />

#<br />

echo −e "ip_nat_ftp"<br />

#<br />

#Verify the module isn't loaded. If it is, skip it<br />

#<br />

if [ −z "` $LSMOD | $GREP ip_nat_ftp | $AWK {'print $1'} `" ]; then<br />

$MODPROBE ip_nat_ftp<br />

fi<br />

#Loads the IRC NAT functionality (for DCC) into the core <strong>IP</strong>TABLES code<br />

#<br />

# DISABLED by default −− delete the "#" on the next few lines to activate<br />

#<br />

# echo −e "ip_nat_irc"<br />

#<br />

#Verify the module isn't loaded. If it is, skip it<br />

#<br />

# if [ −z "` $LSMOD | $GREP ip_nat_irc | $AWK {'print $1'} `" ]; then<br />

# $MODPROBE ip_nat_irc<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 84


# fi<br />

echo " −−−"<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# Just to be complete, here is a partial list of some of the other<br />

# <strong>IP</strong>TABLES kernel modules and their function. Please note that most<br />

# of these modules (the ipt ones) are automatically loaded by the<br />

# master kernel module for proper operation and don't need to be<br />

# manually loaded.<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

#<br />

# ip_nat_snmp_basic − this module allows for proper NATing of some<br />

# SNMP traffic<br />

#<br />

# iptable_mangle − this target allows for packets to be<br />

# manipulated for things like the TCPMSS<br />

# option, etc.<br />

#<br />

# −−<br />

#<br />

# ipt_mark − this target marks a given packet for future action.<br />

# This automatically loads the ipt_MARK module<br />

#<br />

# ipt_tcpmss − this target allows to manipulate the TCP MSS<br />

# option for braindead remote firewalls.<br />

# This automatically loads the ipt_TCPMSS module<br />

#<br />

# ipt_limit − this target allows for packets to be limited to<br />

# to many hits per sec/min/hr<br />

#<br />

# ipt_multiport − this match allows for targets within a range<br />

# of port numbers vs. listing each port individually<br />

#<br />

# ipt_state − this match allows to catch packets with various<br />

# <strong>IP</strong> and TCP flags set/unset<br />

#<br />

# ipt_unclean − this match allows to catch packets that have invalid<br />

# <strong>IP</strong>/TCP flags set<br />

#<br />

# iptable_filter − this module allows for packets to be DROPped,<br />

# REJECTed, or LOGged. This module automatically<br />

# loads the following modules:<br />

#<br />

# ipt_LOG − this target allows for packets to be<br />

# logged<br />

#<br />

# ipt_REJECT − this target DROPs the packet and returns<br />

# a configurable ICMP packet back to the<br />

# sender.<br />

#CRITICAL: Enable <strong>IP</strong> forwarding since it is disabled by default since<br />

#<br />

# Redhat Users: you may try changing the options in<br />

# /etc/sysconfig/network from:<br />

#<br />

# FORWARD_<strong>IP</strong>V4=false<br />

# to<br />

# FORWARD_<strong>IP</strong>V4=true<br />

#<br />

echo " Enabling forwarding.."<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 85


echo "1" > /proc/sys/net/ipv4/ip_forward<br />

# Dynamic <strong>IP</strong> users:<br />

#<br />

# If you get your <strong>IP</strong> address dynamically from SL<strong>IP</strong>, PPP, or DHCP,<br />

# enable the following option. This enables dynamic−address hacking<br />

# which makes the life with Diald and similar programs much easier.<br />

#<br />

echo " Enabling DynamicAddr.."<br />

echo "1" > /proc/sys/net/ipv4/ip_dynaddr<br />

echo " −−−"<br />

#############################################################################<br />

#<br />

# Enable Stronger <strong>IP</strong> forwarding and Masquerading<br />

#<br />

# NOTE: In <strong>IP</strong>TABLES speak, <strong>IP</strong> Masquerading is a form of SourceNAT or SNAT.<br />

#<br />

# NOTE #2: <strong>The</strong> following is an example for an internal LAN address in the<br />

# 192.168.0.x network with a 255.255.255.0 or a "24" bit subnet<br />

# mask connecting to the Internet on external interface "eth0".<br />

# This example will MASQ internal traffic out to the Internet<br />

# but not allow non−initiated traffic into your internal network.<br />

#<br />

#<br />

# ** Please change the above network numbers, subnet mask, and your<br />

#<br />

#Clearing any previous configuration<br />

#<br />

# Unless specified, the defaults for INPUT, OUTPUT, and FORWARD to DROP<br />

#<br />

# You CANNOT change this to REJECT as it isn't a vaild policy setting.<br />

# If you want REJECT, you must explictly REJECT at the end of a giving<br />

# INPUT, OUTPUT, or FORWARD chain<br />

#<br />

echo " Clearing any existing rules and setting default policy to DROP.."<br />

$<strong>IP</strong>TABLES −P INPUT DROP<br />

$<strong>IP</strong>TABLES −F INPUT<br />

$<strong>IP</strong>TABLES −P OUTPUT DROP<br />

$<strong>IP</strong>TABLES −F OUTPUT<br />

$<strong>IP</strong>TABLES −P FORWARD DROP<br />

$<strong>IP</strong>TABLES −F FORWARD<br />

$<strong>IP</strong>TABLES −F −t nat<br />

#Not needed and it will only load the unneeded kernel module<br />

#<br />

#$<strong>IP</strong>TABLES −F −t mangle<br />

# Delete all User−specified chains<br />

$<strong>IP</strong>TABLES −X<br />

# Reset all <strong>IP</strong>TABLES counters<br />

$<strong>IP</strong>TABLES −Z<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#Configuring specific CHAINS for later use in the ruleset<br />

#<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 86


# NOTE: Some users prefer to have their firewall silently<br />

# "DROP" packets while others prefer to use "REJECT"<br />

# to send ICMP error messages back to the remote<br />

# machine. <strong>The</strong> default is "REJECT" but feel free to<br />

# change this below.<br />

#<br />

# NOTE: Without the −−log−level set to "info", every single<br />

# firewall hit will goto ALL vtys. This is a very big<br />

# pain.<br />

#<br />

echo " Creating a DROP chain.."<br />

$<strong>IP</strong>TABLES −N reject−and−log−it<br />

$<strong>IP</strong>TABLES −A reject−and−log−it −j LOG −−log−level info<br />

$<strong>IP</strong>TABLES −A reject−and−log−it −j REJECT<br />

echo −e "\n − Loading INPUT rulesets"<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#######################################################################<br />

# INPUT: Incoming traffic from various interfaces. All rulesets are<br />

# already flushed and set to a default policy of DROP.<br />

#<br />

# loopback interfaces are valid.<br />

#<br />

$<strong>IP</strong>TABLES −A INPUT −i lo −s $UNIVERSE −d $UNIVERSE −j ACCEPT<br />

# local interface, local machines, going anywhere is valid<br />

#<br />

$<strong>IP</strong>TABLES −A INPUT −i $INTIF −s $INTNET −d $UNIVERSE −j ACCEPT<br />

# remote interface, claiming to be local machines, <strong>IP</strong> spoofing, get lost<br />

#<br />

$<strong>IP</strong>TABLES −A INPUT −i $EXTIF −s $INTNET −d $UNIVERSE −j reject−and−log−it<br />

# external interface, from any source, for ICMP traffic is valid<br />

#<br />

# If you would like your machine to "ping" from the Internet,<br />

# enable this next line<br />

#<br />

#$<strong>IP</strong>TABLES −A INPUT −i $EXTIF −p ICMP −s $UNIVERSE −d $EXT<strong>IP</strong> −j ACCEPT<br />

# remote interface, any source, going to the MASQ servers <strong>IP</strong> address is valid<br />

#<br />

# ENABLE this line if you want ALL Internet traffic to connect to your<br />

# the various servers running on the MASQ server. This includes<br />

# web servers, ssh servers, dns servers, etc.<br />

#<br />

# I DON'T recommend you enable this rule. Instead, only enable specific<br />

# access to select server ports under the "OPTIONAL INPUT Section".<br />

# An example of enabling HTTP (WWW) has been given below:<br />

#<br />

#<br />

#$<strong>IP</strong>TABLES −A INPUT −i $EXTIF −s $UNIVERSE −d $EXT<strong>IP</strong> −j ACCEPT<br />

# Allow any related traffic coming back to the MASQ server in.<br />

#<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 87


# STATEFULLY TRACKED<br />

#<br />

$<strong>IP</strong>TABLES −A INPUT −i $EXTIF −s $UNIVERSE −d $EXT<strong>IP</strong> −m state −−state \<br />

ESTABLISHED,RELATED −j ACCEPT<br />

# −−−−− Begin OPTIONAL INPUT Section −−−−−<br />

#<br />

# DHCPd − Enable the following lines if you run an INTERNAL DHCPd server<br />

#<br />

#$<strong>IP</strong>TABLES −A INPUT −i $INTIF −p tcp −−sport 68 −−dport 67 −j ACCEPT<br />

#$<strong>IP</strong>TABLES −A INPUT −i $INTIF −p udp −−sport 68 −−dport 67 −j ACCEPT<br />

# HTTPd − Enable the following lines if you run an EXTERNAL WWW server<br />

#<br />

# NOTE: This is NOT needed for simply enabling PORTFW. This is ONLY<br />

# for users that plan on running Apache on the MASQ server itself<br />

#<br />

#echo −e " − Allowing EXTERNAL access to the WWW server"<br />

#$<strong>IP</strong>TABLES −A INPUT −i $EXTIF −m state −−state NEW,ESTABLISHED,RELATED \<br />

# −p tcp −s $UNIVERSE −d $EXT<strong>IP</strong> −−dport 80 −j ACCEPT<br />

#<br />

# −−−−− End OPTIONAL INPUT Section −−−−−<br />

# Catch all rule, all other incoming is denied and logged.<br />

#<br />

$<strong>IP</strong>TABLES −A INPUT −s $UNIVERSE −d $UNIVERSE −j reject−and−log−it<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

echo −e " − Loading OUTPUT rulesets"<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#######################################################################<br />

# OUTPUT: Outgoing traffic from various interfaces. All rulesets are<br />

# already flushed and set to a default policy of DROP.<br />

#<br />

# Workaround bug in netfilter<br />

# See http://www.netfilter.org/security/2002−04−02−icmp−dnat.html<br />

#<br />

$<strong>IP</strong>TABLES −A OUTPUT −m state −p icmp −−state INVALID −j DROP<br />

# loopback interface is valid.<br />

#<br />

$<strong>IP</strong>TABLES −A OUTPUT −o lo −s $UNIVERSE −d $UNIVERSE −j ACCEPT<br />

# local interfaces, any source going to local net is valid<br />

#<br />

$<strong>IP</strong>TABLES −A OUTPUT −o $INTIF −s $EXT<strong>IP</strong> −d $INTNET −j ACCEPT<br />

# local interface, MASQ server source going to the local net is valid<br />

#<br />

$<strong>IP</strong>TABLES −A OUTPUT −o $INTIF −s $INT<strong>IP</strong> −d $INTNET −j ACCEPT<br />

# outgoing to local net on remote interface, stuffed routing, deny<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 88


#<br />

$<strong>IP</strong>TABLES −A OUTPUT −o $EXTIF −s $UNIVERSE −d $INTNET −j reject−and−log−it<br />

# anything else outgoing on remote interface is valid<br />

#<br />

$<strong>IP</strong>TABLES −A OUTPUT −o $EXTIF −s $EXT<strong>IP</strong> −d $UNIVERSE −j ACCEPT<br />

# −−−−− Begin OPTIONAL OUTPUT Section −−−−−<br />

#<br />

# DHCPd − Enable the following lines if you run an INTERNAL DHCPd server<br />

# − Remove BOTH #s all the #s if you need this functionality.<br />

#<br />

#$<strong>IP</strong>TABLES −A OUTPUT −o $INTIF −p tcp −s $INT<strong>IP</strong> −−sport 67 \<br />

# −d 255.255.255.255 −−dport 68 −j ACCEPT<br />

#$<strong>IP</strong>TABLES −A OUTPUT −o $INTIF −p udp −s $INT<strong>IP</strong> −−sport 67 \<br />

# −d 255.255.255.255 −−dport 68 −j ACCEPT<br />

#<br />

# −−−−− End OPTIONAL OUTPUT Section −−−−−<br />

# Catch all rule, all other outgoing is denied and logged.<br />

#<br />

$<strong>IP</strong>TABLES −A OUTPUT −s $UNIVERSE −d $UNIVERSE −j reject−and−log−it<br />

echo −e " − Loading FORWARD rulesets"<br />

#######################################################################<br />

# FORWARD: Enable Forwarding and thus <strong>IP</strong>MASQ<br />

#<br />

# −−−−− Begin OPTIONAL FORWARD Section −−−−−<br />

#<br />

# Put PORTFW commands here<br />

#<br />

# −−−−− End OPTIONAL FORWARD Section −−−−−<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

echo " − FWD: Allow all connections OUT and only existing/related IN"<br />

$<strong>IP</strong>TABLES −A FORWARD −i $EXTIF −o $INTIF −m state −−state ESTABLISHED,RELATED \<br />

−j ACCEPT<br />

$<strong>IP</strong>TABLES −A FORWARD −i $INTIF −o $EXTIF −j ACCEPT<br />

# Catch all rule, all other forwarding is denied and logged.<br />

#<br />

$<strong>IP</strong>TABLES −A FORWARD −j reject−and−log−it<br />

echo " − NAT: Enabling SNAT (MASQUERADE) functionality on $EXTIF"<br />

#<br />

#More liberal form<br />

#$<strong>IP</strong>TABLES −t nat −A POSTROUTING −o $EXTIF −j MASQUERADE<br />

#<br />

#Stricter form<br />

$<strong>IP</strong>TABLES −t nat −A POSTROUTING −o $EXTIF −j SNAT −−to $EXT<strong>IP</strong><br />

#######################################################################<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 89


echo −e "\nrc.firewall−iptables−stronger $FWVER done.\n"<br />

<br />

To automatically start this stronger firewall ruleset at the proper time, please see the end of the Section 3.4.2<br />

section for full details. Please make sure you make the correct "rc.firewall−iptables" to<br />

"rc.firewall−iptables−stronger" substitutions!!<br />

6.4.2. Stronger <strong>IP</strong> Firewall (<strong>IP</strong>CHAINS) rulesets<br />

This section provides a more in−depth guide to using the 2.2.x firewall tool, <strong>IP</strong>CHAINS. See above sections<br />

for <strong>IP</strong>FWADM rulesets.<br />

This example is for a firewall/masquerade system behind a PPP link with a static PPP address (dynamic PPP<br />

instructions are included but disabled). <strong>The</strong> trusted interface is 192.168.0.1 and the PPP interface <strong>IP</strong> address<br />

has been changed to protect the guilty :−). I have listed each incoming and outgoing interface individually to<br />

catch <strong>IP</strong> spoofing as well as stuffed routing and/or masquerading. A nything not explicitly allowed is<br />

FORBIDDEN (well.. rejected actually). If your <strong>IP</strong> MASQ box breaks after implementing this<br />

rc.firewall−ipchains−stronger script, be sure that you edit it for your configuration and check your<br />

/var/log/messages or /var/adm/messages SYSLOG file for any firewall errors.<br />

For more comprehensive examples of a strong <strong>IP</strong> <strong>Masquerade</strong>d <strong>IP</strong>FWADM rulesets for PPP, Cablemodem<br />

users, etc., please see TrinityOS − Section 10 and GreatCircle's Firewall WWW page<br />

NOTE #1: −−− UPDATE YOUR KERNEL −−− <strong>Linux</strong> 2.2.x kernels less than version 2.2.20 contain several<br />

different security vulnerabilities (some were MASQ specific). Kernels less than 2.2.20 have a few local<br />

vulnerabilities. Kernel versions less than 2.2.16 have a TCP root exploit vulnerability and versions less than<br />

2.2.11 have a <strong>IP</strong>CHAINS fragmentation bug. Because of these issues, users running a firewall with strong<br />

<strong>IP</strong>CHAINS rulesets are open to possible instrusion. Please upgrade your kernel to a fixed version.<br />

NOTE #2: If you get a dynamically assigned TCP/<strong>IP</strong> address from your ISP (PPP, DSL, Cablemodems, etc.),<br />

you CANNOT load this strong ruleset upon booting. You will either need to reload this firewall ruleset<br />

EVERY TIME you get a new <strong>IP</strong> address or make your /etc/rc.d/rc.firewall−ipchains−stronger ruleset more<br />

intelligent. To do this for various types of connections such as PPP or DHCP users, please see the Section 7.8<br />

FAQ entry for all the details.<br />

Please also be aware that there are several GUI Firewall creation tools available as well. Please see<br />

Chapter 7for full details.<br />

Lastly, if you are using a STATIC PPP <strong>IP</strong> address, change the "EXTIF="your.static.PPP.address"" line to<br />

reflect your address.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#!/bin/sh<br />

#<br />

# /etc/rc.d/rc.firewall−ipchains−stronger: An example of a Stronger <strong>IP</strong>CHAINS<br />

# firewall ruleset for 2.2 kernels<br />

#<br />

FWVER=0.75s<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 90


#<br />

# Log:<br />

# 0.75s − Updated the commands for dynamically addresses machines and<br />

# to point to an expanded FAQ section for more information<br />

#<br />

# 0.74s − renamed from rc.firewall−2.2−stronger to<br />

# rc.firewall−ipchains−stronger to better reflect that this ruleset can<br />

# can run on different major kernel versions<br />

# − removed unused SED variable<br />

# 0.73s − Added additional comments to make PORTFW configs more obvious<br />

# 0.72s − #ed out the rule that would allow all traffic destined for the<br />

# MASQ server itself to be accepted. Use the OPTIONAL INPUT<br />

# section to only allow explicit services.<br />

# − Fixed an INTLAN rule that was allowing traffic from ANY <strong>IP</strong> address<br />

# instead of the proper INT<strong>IP</strong> <strong>IP</strong> address only. This aligns the<br />

# <strong>IP</strong>CHAINS ruleset with the <strong>IP</strong>TABLES and <strong>IP</strong>FWADM ruleset examples<br />

# 0.71s − ruleset now uses modprobe instead of insmod<br />

# 0.70s − Added missing execution variables<br />

# − fixed a missing −p tcp for the commented HTTPd section<br />

# 0.65s − Added comments HTTPd rules to the INPUT and OUTPUT section<br />

# − Added a comment where to insert <strong>IP</strong>PORTFW commands<br />

# 0.60s − Changed the EXT<strong>IP</strong> command to work on NON−English distros<br />

# − Updated the CASE of some of the script variables<br />

#<br />

echo −e "\nLoading rc.firewall−ipchains−stronger : version $FWVER..\n"<br />

# <strong>The</strong> location of various iptables and other shell programs<br />

#<br />

# If your <strong>Linux</strong> distribution came with a copy of iptables, most<br />

# likely it is located in /sbin. If you manually compiled<br />

# iptables, the default location is in /usr/local/sbin<br />

#<br />

# ** Please use the "whereis iptables" command to figure out<br />

# ** where your copy is and change the path below to reflect<br />

# ** your setup<br />

#<br />

<strong>IP</strong>CHAINS=/sbin/ipchains<br />

LSMOD=/sbin/lsmod<br />

DEPMOD=/sbin/depmod<br />

MODPROBE=/sbin/modprobe<br />

GREP=/bin/grep<br />

AWK=/bin/awk<br />

IFCONFIG=/sbin/ifconfig<br />

PATH=/sbin:/bin:/usr/sbin:/usr/bin<br />

# Global variables<br />

# −−−−−−−−−−−−−−−−<br />

# ALL PPP and DHCP users must set this for the correct EXTERNAL and<br />

# INTERNAL interfaces names. Examples: eth0, ppp0, ippp0, etc.<br />

# See more info about this below.<br />

#<br />

EXTIF="ppp0"<br />

INTIF="eth0"<br />

# <strong>The</strong> INTERNAL <strong>IP</strong> address<br />

#<br />

INT<strong>IP</strong>="192.168.0.1/32"<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 91


INTNET="192.168.0.0/24"<br />

echo " Internal <strong>IP</strong>: $INT<strong>IP</strong>"<br />

echo " Internal Network: $INTNET"<br />

# Load all required <strong>IP</strong> MASQ modules<br />

#<br />

# NOTE: Only load the <strong>IP</strong> MASQ modules you need. All current <strong>IP</strong> MASQ modules<br />

# are shown below but are commented from loading.<br />

# Needed to initially load modules<br />

#<br />

$DEPMOD −a<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# Supports the proper masquerading of FTP file transfers using the PORT method<br />

#<br />

$MODPROBE ip_masq_ftp<br />

# Supports the masquerading of RealAudio over UDP. Without this module,<br />

# RealAudio WILL function but in TCP mode. This can cause a reduction<br />

# in sound quality<br />

#<br />

$MODPROBE ip_masq_raudio<br />

# Supports the masquerading of IRC DCC file transfers<br />

#<br />

#$MODPROBE ip_masq_irc<br />

# Supports the masquerading of Quake and QuakeWorld by default. <strong>The</strong>se modules are<br />

# for multiple users behind the <strong>Linux</strong> MASQ server. If you are going to<br />

# play Quake I, II, and III, use the second example.<br />

#<br />

# NOTE: If you get ERRORs loading the QUAKE module, you are running an old<br />

# −−−−− kernel that has bugs in it. Please upgrade to the newest kernel.<br />

#<br />

#Quake I / QuakeWorld (ports 26000 and 27000)<br />

#$MODPROBE ip_masq_quake<br />

#<br />

#Quake I/II/III / QuakeWorld (ports 26000, 27000, 27910, 27960)<br />

#$MODPROBE ip_masq_quake 26000,27000,27910,27960<br />

# Supports the masquerading of the CuSeeme video conferencing software<br />

#<br />

#$MODPROBE ip_masq_cuseeme<br />

#Supports the masquerading of the VDO−live video conferencing software<br />

#<br />

#$MODPROBE ip_masq_vdolive<br />

#CRITICAL: Enable <strong>IP</strong> forwarding since it is disabled by default<br />

#<br />

# Redhat Users: you may try changing the options in<br />

# /etc/sysconfig/network from:<br />

#<br />

# FORWARD_<strong>IP</strong>V4=false<br />

# to<br />

# FORWARD_<strong>IP</strong>V4=true<br />

#<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 92


echo "1" > /proc/sys/net/ipv4/ip_forward<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#CRITICAL: Enable automatic <strong>IP</strong> defragmentation since it is disabled by default<br />

# in 2.2.x kernels<br />

#<br />

# This used as a compile−time option but the behavior was changed<br />

# in 2.2.12. It should also be noted that some distributions have<br />

# removed this option from the /proc table. If this entry isn't<br />

# present in your /proc, don't worry about it.<br />

#<br />

echo "1" > /proc/sys/net/ipv4/ip_always_defrag<br />

# Dynamic <strong>IP</strong> users:<br />

#<br />

# If you get your <strong>IP</strong> address dynamically from SL<strong>IP</strong>, PPP, or DHCP, enable this<br />

# following option. This enables dynamic−ip address hacking in <strong>IP</strong> MASQ,<br />

# making life with Diald and similar programs much easier.<br />

#<br />

#echo "1" > /proc/sys/net/ipv4/ip_dynaddr<br />

# Enable the LooseUDP patch which some Internet−based games require<br />

#<br />

# If you are trying to get an Internet game to work through your <strong>IP</strong> MASQ box,<br />

# and you configured it to the best of your ability without it working, try<br />

# enabling this option (delete the "#" character). This option is disabled<br />

# by default due to possible internal machine UDP port scanning<br />

# vulnerabilities.<br />

#<br />

#echo "1" > /proc/sys/net/ipv4/ip_masq_udp_dloose<br />

# Specify your Static <strong>IP</strong> address here.<br />

#<br />

# If you have a DYNAMIC <strong>IP</strong> address, you need to make this ruleset recognize<br />

# your <strong>IP</strong> address everytime you get a new <strong>IP</strong>. To do this, enable the<br />

# following one−line script. (Please note that the different single and<br />

# double quote characters MATTER).<br />

#<br />

#<br />

# DHCP users (Cablemodem and DSL ) users:<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# If you get your TCP/<strong>IP</strong> address via DHCP, **you will need ** to enable the<br />

# #ed out command below underneath the PPP section AND replace the word<br />

# "ppp0" with the name of your EXTERNAL Internet connection (eth0, eth1, etc)<br />

# on the lines for "ppp−ip" and "EXT<strong>IP</strong>".<br />

#<br />

# DHCP and PPP users: <strong>The</strong> remote DHCP or PPP server can and will change<br />

# <strong>IP</strong> addresses on you over time. To deal with this, users should configure<br />

# their DHCP or PPP client to re−run the rc.firewall−* ruleset everytime<br />

# the <strong>IP</strong> address is changed. Please see the "masq−and−dyn−addr" FAQ entry<br />

# in the <strong>IP</strong>MASQ howto for full details on how to do this.<br />

#<br />

#<br />

# Determine the external <strong>IP</strong> automatically:<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

#<br />

# <strong>The</strong> following line will determine your external <strong>IP</strong> address. This<br />

# line is somewhat complex and confusing but it will also work for<br />

# all NON−English <strong>Linux</strong> distributions.<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 93


#<br />

# Make sure the EXTIF variable above is set to reflect the name<br />

# of your Internet connection<br />

#<br />

EXT<strong>IP</strong>="`$IFCONFIG $EXTIF | $AWK \<br />

/$EXTIF/'{next}//{split($0,a,":");split(a[2],a," ");print a[1];exit}'`"<br />

# MASQ timeouts<br />

#<br />

# 2 hrs timeout for TCP session timeouts<br />

# 10 sec timeout for traffic after the TCP/<strong>IP</strong> "FIN" packet is received<br />

# 60 sec timeout for UDP traffic (MASQ'ed ICQ users must enable a 30sec<br />

# firewall timeout in ICQ itself)<br />

#<br />

$<strong>IP</strong>CHAINS −M −S 7200 10 60<br />

#############################################################################<br />

# Incoming, flush and set default policy of reject. Actually the default policy<br />

# is irrelevant because there is a catch all rule with deny and log.<br />

#<br />

$<strong>IP</strong>CHAINS −F input<br />

$<strong>IP</strong>CHAINS −P input REJECT<br />

# local interface, local machines, going anywhere is valid<br />

#<br />

$<strong>IP</strong>CHAINS −A input −i $INTIF −s $INTNET −d 0.0.0.0/0 −j ACCEPT<br />

# remote interface, claiming to be local machines, <strong>IP</strong> spoofing, get lost<br />

#<br />

$<strong>IP</strong>CHAINS −A input −i $EXTIF −s $INTNET −d 0.0.0.0/0 −l −j REJECT<br />

# remote interface, any source, going to the MASQ servers <strong>IP</strong> address is valid<br />

#<br />

# ENABLE this line if you want ALL Internet traffic to connect to your<br />

# the various servers running on the MASQ server. This includes<br />

# web servers, ssh servers, dns servers, etc.<br />

#<br />

# I DON'T recommend you enable this rule. Instead, only enable specific<br />

# access to select server ports under the "OPTIONAL INPUT Section".<br />

# An example of enabling HTTP (WWW) has been given below:<br />

#<br />

#<br />

#$<strong>IP</strong>CHAINS −A input −i $EXTIF −s 0.0.0.0/0 −d $EXT<strong>IP</strong>/32 −j ACCEPT<br />

# loopback interface is valid.<br />

#<br />

$<strong>IP</strong>CHAINS −A input −i lo −s 0.0.0.0/0 −d 0.0.0.0/0 −j ACCEPT<br />

# −−−−− Begin OPTIONAL INPUT Section −−−−−<br />

#<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# HTTPd − Enable the following lines if you either run a WWW server on<br />

# the <strong>IP</strong>MASQ server −OR− plan on PORTFW'ing HTTP traffic to<br />

# an internal WWW server<br />

#<br />

#$<strong>IP</strong>CHAINS −A input −i $EXTIF −p tcp −s 0.0.0.0/0 −d $EXT<strong>IP</strong> 80 −j ACCEPT<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 94


#<br />

# −−−−− End OPTIONAL INPUT Section −−−−−<br />

# catch all rule, all other incoming is denied and logged. pity there is no<br />

# log option on the policy but this does the job instead.<br />

#<br />

$<strong>IP</strong>CHAINS −A input −s 0.0.0.0/0 −d 0.0.0.0/0 −l −j REJECT<br />

#############################################################################<br />

# Outgoing, flush and set default policy of reject. Actually the default policy<br />

# is irrelevant because there is a catch all rule with deny and log.<br />

#<br />

$<strong>IP</strong>CHAINS −F output<br />

$<strong>IP</strong>CHAINS −P output REJECT<br />

# local interface, MASQ server source going to the local net is valid<br />

#<br />

$<strong>IP</strong>CHAINS −A output −i $INTIF −s $INT<strong>IP</strong> −d $INTNET −j ACCEPT<br />

# outgoing to local net on remote interface, stuffed routing, deny<br />

#<br />

$<strong>IP</strong>CHAINS −A output −i $EXTIF −s 0.0.0.0/0 −d $INTNET −l −j REJECT<br />

# outgoing from local net on remote interface, stuffed masquerading, deny<br />

#<br />

$<strong>IP</strong>CHAINS −A output −i $EXTIF −s $INTNET −d 0.0.0.0/0 −l −j REJECT<br />

# anything else outgoing on remote interface is valid<br />

#<br />

$<strong>IP</strong>CHAINS −A output −i $EXTIF −s $EXT<strong>IP</strong>/32 −d 0.0.0.0/0 −j ACCEPT<br />

# loopback interface is valid.<br />

#<br />

$<strong>IP</strong>CHAINS −A output −i lo −s 0.0.0.0/0 −d 0.0.0.0/0 −j ACCEPT<br />

# −−−−− Begin OPTIONAL OUTPUT Section −−−−−<br />

#<br />

# HTTPd − Enable the following lines if you either run a WWW server on<br />

# the <strong>IP</strong>MASQ server −OR− plan on PORTFW'ing HTTP traffic to<br />

# an internal WWW server<br />

#<br />

#$<strong>IP</strong>CHAINS −A output −i $EXTIF −p tcp −s $EXT<strong>IP</strong> 80 −d 0.0.0.0/0 −j ACCEPT<br />

#<br />

# −−−−− End OPTIONAL OUTPUT Section −−−−−<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# catch all rule, all other outgoing is denied and logged. pity there is no<br />

# log option on the policy but this does the job instead.<br />

#<br />

$<strong>IP</strong>CHAINS −A output −s 0.0.0.0/0 −d 0.0.0.0/0 −l −j REJECT<br />

#############################################################################<br />

# Forwarding, flush and set default policy of deny. Actually the default policy<br />

# is irrelevant because there is a catch all rule with deny and log.<br />

#<br />

$<strong>IP</strong>CHAINS −F forward<br />

$<strong>IP</strong>CHAINS −P forward DENY<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 95


# −−−−− Begin OPTIONAL FORWARD Section −−−−−<br />

#<br />

# Put PORTFW commands here<br />

#<br />

# −−−−− End OPTIONAL FORWARD Section −−−−−<br />

# <strong>Masquerade</strong> from local net on local interface to anywhere.<br />

#<br />

$<strong>IP</strong>CHAINS −A forward −i $EXTIF −s $INTNET −d 0.0.0.0/0 −j MASQ<br />

#<br />

# catch all rule, all other forwarding is denied and logged. pity there is no<br />

# log option on the policy but this does the job instead.<br />

#<br />

$<strong>IP</strong>CHAINS −A forward −s 0.0.0.0/0 −d 0.0.0.0/0 −l −j REJECT<br />

#End of file.<br />

<br />

To automatically start this stronger firewall ruleset at the proper time, please see the end of the Section 3.4.2<br />

section for full details. Please make sure you make the correct "rc.firewall−ipchains" to<br />

"rc.firewall−ipchains−stronger" substitutions!!<br />

With <strong>IP</strong>CHAINS, you can block traffic to a particular site using the "input", "output", and/or "forward" rules.<br />

Remember that the set of rules are scanned from top to bottom and "−A" tells <strong>IP</strong>CHIANS to "append" this<br />

new rule to the existing set of rules. So with this in mind, any specific restrictions need to come before any<br />

global rules. For example:<br />

Using "input" rules:<br />

Probably the fastest and most efficient method to block traffic, but this method only stops the MASQed<br />

machines and NOT the firewall machine itself. Of course, you might want to allow that combination.<br />

Anyway, to block 204.50.10.13:<br />

In the /etc/rc.d/rc.firewall−ipchains−stronger ruleset:<br />

... start of "input" rules ...<br />

# reject and log local interface, local machines going to 204.50.10.13<br />

#<br />

ipchains −A input −s 192.168.0.0/24 −d 204.50.10.13/32 −l −j REJECT<br />

# local interface, local machines, going anywhere is valid<br />

#<br />

ipchains −A input −s 192.168.0.0/24 −d 0.0.0.0/0 −l −j ACCEPT<br />

... end of "input" rules ...<br />

Using "output" rules:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

This is the slower method to block traffic because the packets must go through masquerading before they are<br />

dropped. Yet, this rule even stops the firewall machine from accessing the forbidden site.<br />

... start of "output" rules ... # reject and log outgoing to 204.50.10.13 # ipchains −A output −s $ppp_ip/32 −d<br />

204.50.10.13/32 −l −j REJECT # anything else outgoing on remote interface is valid # ipchains −A output −s<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 96


$ppp_ip/32 −d 0.0.0.0/0 −l −j ACCEPT ... end of "output" rules ...<br />

Using "forward" rules:<br />

Probably slower than "input" rules for blocking traffic, this only stops masqueraded machines (e.g. internal<br />

machines). <strong>The</strong> firewall machine can still reach forbidden site(s).<br />

... start of "forward" rules ... # Reject and log from local net on PPP interface to 204.50.10.13. # ipchains −A<br />

forward −i ppp0 −s 192.168.0.0/24 −d 204.50.10.13/32 −l −j REJECT # <strong>Masquerade</strong> from local net on local<br />

interface to anywhere. # ipchains −A forward −i ppp0 −s 192.168.0.0/24 −d 0.0.0.0/0 −j MASQ ... end of<br />

"forward" rules ...<br />

No need for a special rule to allow machines on the 192.168.0.0/24 network to go to 204.50.11.0. Why? It is<br />

already covered by the global MASQ rule.<br />

NOTE: Unlike <strong>IP</strong>FWADM, <strong>IP</strong>CHIANS has only one way of coding the interfaces name. <strong>IP</strong>CHAINS uses the<br />

"−i eth0" option where as <strong>IP</strong>FWADM had both "−W" for the interface name and "−V" for the interface's <strong>IP</strong><br />

address.<br />

6.4.3. Stronger <strong>IP</strong> Firewall (<strong>IP</strong>FWADM) Rulesets<br />

This section provides a more in−depth guide on using the 2.0.x firewall tool, <strong>IP</strong>FWADM. See below for<br />

<strong>IP</strong>CHAINS rulesets<br />

This example is for a firewall/masquerade system behind a PPP link with a static PPP address (dynamic PPP<br />

instructions are included but disabled). <strong>The</strong> trusted interface is 192.168.0.1 and the PPP interface <strong>IP</strong> address<br />

has been changed to protect the guilty :). I have listed each incoming and outgoing interface individually to<br />

catch <strong>IP</strong> spoofing as well as stuffed routing and/or masquerading. Anything not explicitly allowed is<br />

FORBIDDEN (well.. rejected, actually). If your <strong>IP</strong> MASQ box breaks after implementing this<br />

rc.firewall−ipfwadm−stronger script, be sure that you edit it for your configuration and check your<br />

/var/log/messages or /var/adm/messages SYSLOG file for any firewall errors.<br />

For more comprehensive examples of a strong <strong>IP</strong> <strong>Masquerade</strong>d <strong>IP</strong>FWADM rulesets for PPP, Cablemodem<br />

users, etc., please see TrinityOS − Section 10 and GreatCircle's Firewall WWW page<br />

NOTE #2: If you get a dynamically assigned TCP/<strong>IP</strong> address from your ISP (PPP, DSL, Cablemodems, etc.),<br />

you CANNOT load this strong ruleset upon booting. You will either need to reload this firewall ruleset<br />

EVERY TIME you get a new <strong>IP</strong> address or make your /etc/rc.d/rc.firewall−ipchains−stronger ruleset more<br />

intelligent. To do this for various types of connections such as PPP or DHCP users, please see the Section 7.8<br />

FAQ entry for all the details.<br />

Please also be aware that there are several GUI Firewall creation tools available as well. Please see<br />

Chapter 7for full details.<br />

Lastly, if you are using a STATIC PPP <strong>IP</strong> address, change the "ppp_ip="your.static.PPP.address"" line to<br />

reflect your address.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 97


#!/bin/sh<br />

#<br />

# /etc/rc.d/rc.firewall−ipfwadm−stronger: An example of a semi−STRONG<br />

# <strong>IP</strong>FWADM firewall ruleset for 2.0 kernels<br />

#<br />

FWVER=0.74s<br />

#<br />

# Log:<br />

# 0.74s − Updated the commands for dynamically addresses machines and<br />

# to point to an expanded FAQ section for more information<br />

#<br />

# 0.73s − renamed from rc.firewall−2.0−stronger to<br />

# rc.firewall−ipfwadm−stronger<br />

#<br />

# 0.72s − #ed out the rule that would allow all traffic destined for the<br />

# MASQ server itself to be accepted. Use the OPTIONAL INPUT<br />

# section to only allow explicit services.<br />

PATH=/sbin:/bin:/usr/sbin:/usr/bin<br />

# testing, wait a bit then clear all firewall rules.<br />

# uncomment the following lines if you want the firewall to automatically<br />

# disable after 10 minutes.<br />

#<br />

# Disabled by default<br />

#<br />

# (sleep 600; \<br />

# ipfwadm −I −f; \<br />

# ipfwadm −I −p accept; \<br />

# ipfwadm −O −f; \<br />

# ipfwadm −O −p accept; \<br />

# ipfwadm −F −f; \<br />

# ipfwadm −F −p accept; \<br />

# ) &<br />

# Load all required <strong>IP</strong> MASQ modules<br />

#<br />

# NOTE: Only load the <strong>IP</strong> MASQ modules you need. All current <strong>IP</strong> MASQ modules<br />

# are shown below but are commented from loading.<br />

# Needed to initially load modules<br />

#<br />

/sbin/depmod −a<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# Supports the proper masquerading of FTP file transfers using the PORT method<br />

#<br />

/sbin/modprobe ip_masq_ftp<br />

# Supports the masquerading of RealAudio over UDP. Without this module,<br />

# RealAudio WILL function but in TCP mode. This can cause a reduction<br />

# in sound quality<br />

#<br />

#/sbin/modprobe ip_masq_raudio<br />

# Supports the masquerading of IRC DCC file transfers<br />

#<br />

#/sbin/modprobe ip_masq_irc<br />

# Supports the masquerading of Quake and QuakeWorld by default. This modules is<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 98


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# for multiple users behind the <strong>Linux</strong> MASQ server. If you are going to<br />

# play Quake I, II, and III, use the second example.<br />

#<br />

# NOTE: If you get ERRORs loading the QUAKE module, you are running an old<br />

# −−−−− kernel that has bugs in it. Please upgrade to the newest kernel.<br />

#<br />

#Quake I / QuakeWorld (ports 26000 and 27000)<br />

#/sbin/modprobe ip_masq_quake<br />

#<br />

#Quake I/II/III / QuakeWorld (ports 26000, 27000, 27910, 27960)<br />

#/sbin/modprobe ip_masq_quake 26000,27000,27910,27960<br />

# Supports the masquerading of the CuSeeme video conferencing software<br />

#<br />

#/sbin/modprobe ip_masq_cuseeme<br />

#Supports the masquerading of the VDO−live video conferencing software<br />

#<br />

#/sbin/modprobe ip_masq_vdolive<br />

#CRITICAL: Enable <strong>IP</strong> forwarding, since it is disabled by default<br />

#<br />

# Redhat Users: you may try changing the options in /etc/sysconfig/network<br />

# from:<br />

#<br />

# FORWARD_<strong>IP</strong>V4=false<br />

# to<br />

# FORWARD_<strong>IP</strong>V4=true<br />

#<br />

echo "1" > /proc/sys/net/ipv4/ip_forward<br />

#CRITICAL: Enable automatic <strong>IP</strong> defragmenting since it is disabled by default<br />

# in 2.2.x kernels<br />

#<br />

# This used to be a compile−time option but the behavior was changed<br />

# in 2.2.12<br />

#<br />

echo "1" > /proc/sys/net/ipv4/ip_always_defrag<br />

# Dynamic <strong>IP</strong> users:<br />

#<br />

# If you get your <strong>IP</strong> address dynamically from SL<strong>IP</strong>, PPP, or DHCP, enable this<br />

# following option. This allows dynamic−ip address hacking in <strong>IP</strong> MASQ,<br />

# making the life with Diald and similar programs much easier.<br />

#<br />

#echo "1" > /proc/sys/net/ipv4/ip_dynaddr<br />

# Specify your Static <strong>IP</strong> address here.<br />

#<br />

# If you have a DYNAMIC <strong>IP</strong> address, you need to make this ruleset understand<br />

# your <strong>IP</strong> address everytime you get a new <strong>IP</strong>. To do this, enable the<br />

# following one−line script. (Please note that the different single and<br />

# double quote characters MATTER).<br />

#<br />

#<br />

# DHCP (Cablemodem and DSL) and PPP users:<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 99


# If you get your TCP/<strong>IP</strong> address a dynamic <strong>IP</strong> address **you will need ** to<br />

# enable the #ed out command below underneath the PPP section AND replace the word<br />

# "ppp0" with the name of your EXTERNAL Internet connection (eth0, eth1,<br />

# etc).<br />

#<br />

# DHCP and PPP users: <strong>The</strong> remote DHCP or PPP server can and will change<br />

# <strong>IP</strong> addresses on you over time. To deal with this, users should configure<br />

# their DHCP or PPP client to re−run the rc.firewall−* ruleset everytime<br />

# the <strong>IP</strong> address is changed. Please see the "masq−and−dyn−addr" FAQ entry<br />

# in the <strong>IP</strong>MASQ howto for full details on how to do this.<br />

#<br />

#<br />

# PPP and DHCP Users:<br />

# −−−−−−−−−−−−−−−−−−−<br />

# Remove the # on the line below and place a # in front of the line after that.<br />

#<br />

#ppp_ip="`/sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' | sed −e 's/.*://'`"<br />

#<br />

ppp_ip="your.static.PPP.address"<br />

# MASQ timeouts<br />

#<br />

# 2 hrs timeout for TCP session timeouts<br />

# 10 sec timeout for traffic after the TCP/<strong>IP</strong> "FIN" packet is received<br />

# 60 sec timeout for UDP traffic (MASQ'ed ICQ users must enable a 30sec<br />

# firewall timeout in ICQ itself)<br />

#<br />

/sbin/ipfwadm −M −s 7200 10 60<br />

#############################################################################<br />

# Incoming, flush and set default policy of reject. Actually the default policy<br />

# is irrelevant because there is a catch all rule with deny and log.<br />

#<br />

/sbin/ipfwadm −I −f<br />

/sbin/ipfwadm −I −p reject<br />

# local interface, local machines, going anywhere is valid<br />

#<br />

/sbin/ipfwadm −I −a accept −V 192.168.0.1 −S 192.168.0.0/24 −D 0.0.0.0/0<br />

# remote interface, claiming to be local machines, <strong>IP</strong> spoofing, get lost<br />

#<br />

/sbin/ipfwadm −I −a reject −V $ppp_ip −S 192.168.0.0/24 −D 0.0.0.0/0 −o<br />

# remote interface, any source, going to the MASQ servers <strong>IP</strong> address is valid<br />

#<br />

# ENABLE this line if you want ALL Internet traffic to connect to your<br />

# the various servers running on the MASQ server. This includes<br />

# web servers, ssh servers, dns servers, etc.<br />

#<br />

# I DON'T recommend you enable this rule. Instead, only enable specific<br />

# access to select server ports under the "OPTIONAL INPUT Section".<br />

# An example of enabling HTTP (WWW) has been given below:<br />

#<br />

#<br />

#/sbin/ipfwadm −I −a accept −V $ppp_ip −S 0.0.0.0/0 −D $ppp_ip/32<br />

# loopback interface is valid.<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 100


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#<br />

/sbin/ipfwadm −I −a accept −V 127.0.0.1 −S 0.0.0.0/0 −D 0.0.0.0/0<br />

# catch all rule, all other incoming is denied and logged. pity there is no<br />

# log option on the policy but this does the job instead.<br />

#<br />

/sbin/ipfwadm −I −a reject −S 0.0.0.0/0 −D 0.0.0.0/0 −o<br />

#############################################################################<br />

# Outgoing, flush and set default policy of reject. Actually the default policy<br />

# is irrelevant because there is a catch all rule with deny and log.<br />

#<br />

/sbin/ipfwadm −O −f<br />

/sbin/ipfwadm −O −p reject<br />

# local interface, MASQ server source going to the local net is valid<br />

#<br />

/sbin/ipfwadm −O −a accept −V 192.168.0.1 −S 0.0.0.0/0 −D 192.168.0.0/24<br />

# outgoing to local net on remote interface, stuffed routing, deny<br />

#<br />

/sbin/ipfwadm −O −a reject −V $ppp_ip −S 0.0.0.0/0 −D 192.168.0.0/24 −o<br />

# outgoing from local net on remote interface, stuffed masquerading, deny<br />

#<br />

/sbin/ipfwadm −O −a reject −V $ppp_ip −S 192.168.0.0/24 −D 0.0.0.0/0 −o<br />

# outgoing from local net on remote interface, stuffed masquerading, deny<br />

#<br />

/sbin/ipfwadm −O −a reject −V $ppp_ip −S 0.0.0.0/0 −D 192.168.0.0/24 −o<br />

# anything else outgoing on remote interface is valid<br />

#<br />

/sbin/ipfwadm −O −a accept −V $ppp_ip −S $ppp_ip/32 −D 0.0.0.0/0<br />

# loopback interface is valid.<br />

#<br />

/sbin/ipfwadm −O −a accept −V 127.0.0.1 −S 0.0.0.0/0 −D 0.0.0.0/0<br />

# catch all rule, all other outgoing is denied and logged. pity there is no<br />

# log option on the policy but this does the job instead.<br />

#<br />

/sbin/ipfwadm −O −a reject −S 0.0.0.0/0 −D 0.0.0.0/0 −o<br />

#############################################################################<br />

# Forwarding, flush and set default policy of deny. Actually the default policy<br />

# is irrelevant because there is a catch all rule with deny and log.<br />

#<br />

/sbin/ipfwadm −F −f<br />

/sbin/ipfwadm −F −p reject<br />

# <strong>Masquerade</strong> from local net on local interface to anywhere.<br />

#<br />

/sbin/ipfwadm −F −a masquerade −W ppp0 −S 192.168.0.0/24 −D 0.0.0.0/0<br />

#<br />

# catch all rule, all other forwarding is denied and logged. Pity there is no<br />

# log option on the policy but this does the job instead.<br />

#<br />

/sbin/ipfwadm −F −a reject −S 0.0.0.0/0 −D 0.0.0.0/0 −o<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 101


#End of file.<br />

<br />

To automatically start this stronger firewall ruleset at the proper time, please see the end of the Section 3.4.3<br />

section for full details. Please make sure you make the correct "rc.firewall−ipfwadm" to<br />

"rc.firewall−ipfwadm−stronger" substitutions!!<br />

With <strong>IP</strong>FWADM, you can block traffic to a particular site using the −I, −O or −F rules. Remember that the set<br />

of rules are scanned top to bottom and "−a" tells <strong>IP</strong>FWADM to "append" this new rule to the existing set of<br />

rules. So with this in mind, any specific restrictions need to come before global rules. For example:<br />

Using −I (input ) rules:<br />

Probably the fastest and most efficient method to block traffic but it only stops the MASQed machines, and<br />

NOT the the firewall machine itself. Of course, you might want to allow that combination.<br />

Anyway, to block 204.50.10.13:<br />

In the /etc/rc.d/rc.firewall−ipfwadm−stronger ruleset: ... start of −I rules ... # reject and log local interface,<br />

local machines going to 204.50.10.13 # /sbin/ipfwadm −I −a reject −V 192.168.0.1 −S 192.168.0.0/24 −D<br />

204.50.10.13/32 −o # local interface, local machines, going anywhere is valid # /sbin/ipfwadm −I −a accept<br />

−V 192.168.0.1 −S 192.168.0.0/24 −D 0.0.0.0/0 ... end of −I rules ...<br />

Using −O (output) rules:<br />

This is the slower method to block traffic because the packets go through masquerading first before they are<br />

dropped. Yet, this rule even stops the firewall machine from accessing the forbidden site.<br />

... start of −O rules ... # reject and log outgoing to 204.50.10.13 # /sbin/ipfwadm −O −a reject −V $ppp_ip −S<br />

$ppp_ip/32 −D 204.50.10.13/32 −o # anything else outgoing on remote interface is valid # /sbin/ipfwadm −O<br />

−a accept −V $ppp_ip −S $ppp_ip/32 −D 0.0.0.0/0 ... end of −O rules ...<br />

Using −F (forward) rules:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Probably slower than −I (input) rules for blocking traffic, this still only stops masqueraded machines (e.g.<br />

internal machines). <strong>The</strong> firewall machine can still reach forbidden site(s).<br />

... start of −F rules ... # Reject and log from local net on PPP interface to 204.50.10.13. # /sbin/ipfwadm −F −a<br />

reject −W ppp0 −S 192.168.0.0/24 −D 204.50.10.13/32 −o # <strong>Masquerade</strong> from local net on local interface to<br />

anywhere. # /sbin/ipfwadm −F −a masquerade −W ppp0 −S 192.168.0.0/24 −D 0.0.0.0/0 ... end of −F rules ...<br />

<strong>The</strong>re is no need for a special rule to allow machines on the 192.168.0.0/24 network to go to 204.50.11.0.<br />

Why? It is already covered by the global MASQ rule.<br />

NOTE: <strong>The</strong>re is more than one way of coding the interfaces in the above rules. For example instead of "−V<br />

192.168.255.1" you can code "−W eth0", instead of "−V $ppp_ip" , you can use "−W ppp0". <strong>The</strong> "−V"<br />

method was phased out with the imgration to <strong>IP</strong>CHAINS, but for <strong>IP</strong>FWADM users, its more of a personal<br />

choice and documentation.<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 102


6.5. <strong>IP</strong> Masquerading multiple internal networks<br />

Masquerading more than one internal network is fairly simple. You need to first make sure that all of your<br />

networks are running correctly (both internal and external). You then need to enable traffic to pass to both the<br />

other internal interfaces and to be MASQed to the Internet.<br />

Next, you need to enable Masquerading on the INTERNAL interfaces. This example uses a total of THREE<br />

interfaces: EXTIF stands for the eth0 interface which is the EXTERNAL connection to the Internet. INTIF<br />

stands for the eth1 interface and is the 192.168.0.0 network. Finally, INTIF2 stands for the eth2 interface and<br />

is the 192.168.1.0 network. Both INTIF and INTIF2 will be MASQed out of interface eth0 or EXTIF. In your<br />

rc.firewall−* ruleset next to the existing MASQ at the very end of the ruleset, add the following:<br />

6.5.1. iptables support for multiple internal lans<br />

•<br />

# 2.6.x and 2.4.x kernels with <strong>IP</strong>TABLES<br />

#<br />

# <strong>The</strong> following rules build upon the rc.firewall−iptables−stronger ruleset.<br />

# Please see that ruleset in Section 6 for how all variables get set, etc.<br />

#Enable internal interfaces to communication between each other<br />

#<br />

$<strong>IP</strong>TABLES −A FORWARD −i $EXTIF −o $INTIF2 −m state −−state ESTABLISHED,RELATED \<br />

−j ACCEPT<br />

$<strong>IP</strong>TABLES −A FORWARD −i $INTIF −o $INTIF2 −m state −−state ESTABLISHED,RELATED \<br />

−j ACCEPT<br />

$<strong>IP</strong>TABLES −A FORWARD −i $INTIF2 −o $INTIF −m state −−state ESTABLISHED,RELATED \<br />

−j ACCEPT<br />

$<strong>IP</strong>TABLES −t nat −A POSTROUTING −o $EXTIF −j SNAT −−to $EXT<strong>IP</strong><br />

6.5.2. ipchains support for multiple internal lans<br />

•<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# 2.2.x kernels with <strong>IP</strong>CHAINS<br />

#<br />

# <strong>The</strong> following rules build upon the rc.firewall−ipchains−stronger ruleset.<br />

# Please see that ruleset in Section 6 for how all variables get set, etc.<br />

#Enable internal interfaces to communication between each other<br />

$<strong>IP</strong>CHAINS −A forward −i eth1 −d 192.168.0.0/24 −j ACCEPT<br />

$<strong>IP</strong>CHAINS −A forward −i eth2 −d 192.168.1.0/24 −j ACCEPT<br />

#Enable internal interfaces to MASQ out to the Internet<br />

$<strong>IP</strong>CHAINS −A forward −j MASQ −i eth0 −s 192.168.0.0/24 −d 0.0.0.0/0<br />

$<strong>IP</strong>CHAINS −A forward −j MASQ −i eth0 −s 192.168.1.0/24 −d 0.0.0.0/0<br />

6.5.3. ipfwadm support for multiple internal lans<br />

• # 2.0.x kernels with <strong>IP</strong>FWADM<br />

#<br />

# <strong>The</strong> following rules build upon the rc.firewall−ipfwadm−stronger ruleset.<br />

# Please see that ruleset in Section 6 for how all variables get set, etc.<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 103


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#Enable internal interfaces to communication between each other<br />

/sbin/ipfwadm −F −a accept −V 192.168.0.1 −D 192.168.1.0/24<br />

/sbin/ipfwadm −F −a accept −V 192.168.1.1 −D 192.168.0.0/24<br />

#Enable internal interfaces to MASQ out to the Internet<br />

/sbin/ipfwadm −F −a masq −W eth0 −S 192.168.0.0/24 −D 0.0.0.0/0<br />

/sbin/ipfwadm −F −a masq −W eth0 −S 192.168.1.0/24 −D 0.0.0.0/0<br />

Please note that it is CORRECT to have "eth0" specified multiple times for the exmples shown above. <strong>The</strong><br />

reason for this is the <strong>Linux</strong> kernel needs to know which interface is used for OUTGOING traffic. Since eth0<br />

in the above examples is the Internet connection, it is listed for each internal interface.<br />

6.6. <strong>IP</strong> <strong>Masquerade</strong> and Dial−on−Demand Connections<br />

1. If you would like to setup your network to automatically dial up the Internet, either the Diald demand<br />

dial−up or new versions of the PPPd packages will be of great utility. Both Diald and PPPd are very<br />

powerful in their configuration flexibility.<br />

2. To setup PPPd for Dial−on−Demand, pease check out the PPPd Homepage<br />

3. To setup Diald, please check out the Diald Homepage or TrinityOS − Section 23<br />

4. Once Dial on Demand and <strong>IP</strong> Masq have been setup properly, any MASQed client machines that<br />

initiate a web, telnet or ftp session will make the <strong>Linux</strong> box dynamically bring up its Internet link.<br />

5. <strong>The</strong>re is a timeout that will occur with the first connection. This is inevitable if you are using analog<br />

modems. <strong>The</strong> time taken to establish the modem link and the PPP connections may cause your client<br />

program (WWW browser, etc.) to stop. This isn't common though. If this does happen, just retry that<br />

Internet traffic request (say a WWW page) again and it should come up fine. You can also try setting<br />

echo "1" > /proc/sys/net/ipv4/ip_dynaddr kernel option to help with this initial setup.<br />

6.7. Port Forwarding with <strong>IP</strong>TABLES or external tools like<br />

<strong>IP</strong>PORTFW, <strong>IP</strong>MASQADM, <strong>IP</strong>AUTOFW, REDIR, UDPRED,<br />

and other Port Forwarding tools<br />

<strong>IP</strong>TABLES as well as <strong>IP</strong>PORTFW, <strong>IP</strong>AUTOFW, REDIR, UDPRED, and other programs offer generic TCP<br />

and/or UDP port forwarding for <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong>. <strong>The</strong>se tools are typically used with or as a replacement<br />

for specific <strong>IP</strong> MASQ modules to get a specific network traffic through the MASQ server.<br />

With port forwarders, you can redirect data connections from the Internet to an internal, privately addressed<br />

machine behind your <strong>IP</strong> MASQ server. This forwarding ability includes network protocols such as TELNET,<br />

WWW, and SMTP. Protocols such as FTP, legacy ICQ, and others require special handling via kernel<br />

modules (see below).<br />

NOTE: If you are just looking to do simple port forwarding but you don't need Masquerading support, you<br />

don't have any choice. You will STILL NEED to enable <strong>IP</strong> Masquerading support in the kernel AND either<br />

run a <strong>IP</strong>TABLES, <strong>IP</strong>CHAINS, or <strong>IP</strong>FWADM ruleset to be able to use <strong>Linux</strong>'s port forwarding tools.<br />

So why all the different choices? <strong>IP</strong>TABLES, <strong>IP</strong>PORTFW, MARK (MFW), <strong>IP</strong>MASQADM (PORTFW or<br />

AUTOFW), <strong>IP</strong>AUTOFW, REDIR, and UDPRED (all URLs are in Section 3.2.3) are the various tools<br />

available to <strong>IP</strong> MASQ users to allow this type of functionality depending on their kernel version. Later, as the<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> feature matured, many of these tools were eventually replaced by the <strong>IP</strong>TABLES or<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 104


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

PORTFW and MARK systems which are far more intelligent solutions.<br />

For the later 2.2.x kernels, the <strong>IP</strong>MASQADM tool combined the legacy <strong>IP</strong>AUTOFW and <strong>IP</strong>PORTFW 2.0.x<br />

kernel tools into one binary. Both the <strong>IP</strong>MASQADM tool for 2.2.x kernels as well as <strong>IP</strong>TABLES for the 2.6.x<br />

and 2.4.x kernels also supports a new mechanism called "MARK" or MFW for PORTFW functionality. <strong>The</strong><br />

MARK system works where a specific <strong>IP</strong>TABLES or <strong>IP</strong>CHAINS ruleset would match a given packet<br />

sequence. Once matched, the tool would "mark" these packets. Later, the <strong>IP</strong>MASQADM tool or a specific<br />

<strong>IP</strong>TABLE "table" could be instructed to change these packets as needed and forward them off to their desired<br />

internal destination. Currently, this <strong>HOWTO</strong> doesn't cover the MARK solution but it will in the future.<br />

Anyway, because of the availablity of the newer tools, it is *HIGHLY DISCOURAGED* to use the old tools<br />

such as <strong>IP</strong>AUTOFW (even AUTOFW in <strong>IP</strong>MASQADM) and REDIR because they don't properly notify the<br />

<strong>Linux</strong> kernel of their presence and can ultimately CRASH your <strong>Linux</strong> server with extreme use.<br />

NOTE #2: With enabling PORTFW functionality in ANY 2.2/2.0 <strong>Linux</strong> kernel (2.6.x. and 2.4.x users won't<br />

use these specific tools anyway), internal machines typically CANNOT use the same "external"<br />

PORTFWed <strong>IP</strong> address to access a given internal" machine. To put it another way, PORTFW was only<br />

intended to be used with "external" computers on the Internet. If this is an issue for you, you can also use the<br />

REDIR tool for older 2.2.x and 2.0.x kernels to let internal machines get redirected to the internal servers too.<br />

2.6.x and 2.4.x kernels users running <strong>IP</strong>TABLES solves this issue once and for all and is fully covered in a<br />

FAQ entry in Section 7.19 below. If you would like a technical explination on why this internal/external<br />

forwarding doesn't work, please page down towards the bottom of the 2.2.x PORTFW section for a note from<br />

Juan Jose Ciarlante.<br />

NOTE #3: <strong>The</strong> forwarding of non−NAT friendly traffic such as FTP server traffic to an internal MASQed<br />

FTP server, known as PORTFW FTP, is now fully supported in the 2.6.x and 2.4.x kernels as well as in the<br />

2.2.x kernels via a BETA version FTP kernel module (does NOT come with the stock Linus kernels). It<br />

should also be noted that you can also PORTFW FTP traffic using an external FTP proxy program (not<br />

covered in this <strong>HOWTO</strong>). It should be noted that the Beta 2.2.x FTP kernel module code is still experimental<br />

and some people get better results simply using ACTIVE FTP sessions compared to PASSIVE connections.<br />

Interestingly enough, other people have seen the exact opposite behavior. Please let us know what your results<br />

are like. More about this is covered below in both the 2.2.x and 2.0.x sections as the solutions require the use<br />

of different patches.<br />

WARNING! Before jumping right into installing ANY of these tools, it needs to be mentioned that network<br />

security can be an issue with ANY PORT FORWARD tool. <strong>The</strong> reason for this is because these tools basically<br />

create a hole in strong packet firewalls for the required TCP/UDP ports. Though this doesn't pose any threat to<br />

your <strong>Linux</strong> machine, it might be an issue to the PORTFW'ed internal machine(s). No worries though, this is<br />

what Steven Clarke (the author of <strong>IP</strong>PORTFW) had to say about that:<br />

"Port Forwarding is only called within masquerading functions so it<br />

fits inside the same <strong>IP</strong>FWADM/<strong>IP</strong>CHAINS rules. Masquerading is an extension to<br />

<strong>IP</strong> forwarding. <strong>The</strong>refore, ipportfw only sees a packet if it fits<br />

both the input and masquerading ipfwadm rule sets."<br />

What that means in English is that if you have a strong packet firewall running, PORTFW doesn't directly<br />

bypass any of that security. You will still be able to allow or deny specific <strong>IP</strong>s and/or domains to this new<br />

PORTFW'ed resource if you so wish.<br />

With this said, it's important to have a strong firewall ruleset. Please see Section 6.4.1, Section 6.4.2, and<br />

Section 6.4.3 for more details on getting strong rulesets.<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 105


• 2.6.x and 2.4.x kernels have PORTFW functional already built in using the <strong>IP</strong>TABLES tool. 2.2.x and<br />

2.0.x kernel kernel users will need to re−compile the <strong>Linux</strong> kernel to support PORTFW. It should be<br />

noted that some <strong>Linux</strong> distribution kernels might have this already done for you.<br />

• <strong>The</strong> latest 2.2.x kernel users will already have the PORTFW kernel option available to them though<br />

you might still need to recompile the kernel via the normal kernel "make" procedures.<br />

• 2.0.x users will need to apply a simple kernel option patch to have access to then enable this via the<br />

normal kernel "make" procedures.<br />

6.7.1. <strong>IP</strong>TABLES−based PORTFWD'ing: Using <strong>IP</strong>TABLES's PREROUTING<br />

option for 2.6.x and 2.4.x kernels<br />

As mentioned before, a port forward or "PORTFW" allows a single or range of TCP/<strong>IP</strong> ports from the<br />

external side of the network to be forwarded into the inside network.<br />

Unlike ALL previous <strong>Linux</strong> kernels, the 2.6.x and 2.4.x series kernels now allows for full PORTFW,<br />

PORTFW FTP, and PORTFW REDIR functionality within the "iptables" tool itself.<br />

NOTE: Once you enable a port forwarder on say port 80 (forward WWW traffic through the MASQ server to<br />

an internal WWW server), that port will no longer be used by the <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> server itself. To be<br />

more specific, if you have a WWW server already running on the MASQ server, enabling PORTFW will now<br />

give all Internet users acces to the WWW pages from the −INTERNAL− WWW server and not the pages on<br />

your <strong>IP</strong> MASQ server.<br />

To enable port forwarding on an <strong>IP</strong>TABLES (2.6.x or 2.4.x kernel):<br />

• Edit the /etc/rc.d/rc.firewall−iptables ruleset and place the lines shown below just ABOVE the "FWD:<br />

Allow all connections OUT and only existing and related ones IN" line<br />

(in the "Optional FORWARD section"). Please be sure to replace the word "$EXT<strong>IP</strong>" with your<br />

specific Internet <strong>IP</strong> address.<br />

• NOTE: Unlike the 2.2.x and 2.0.x kernels, PORTFWed traffic does *not* traverse the INPUT or<br />

OUTPUT rules. It only traverses the FORWARD rule.<br />

• NOTE: If you get a dynamically assigned TCP/<strong>IP</strong> address from your ISP (PPP, DSL, Cablemodems,<br />

etc.), you CANNOT load this strong ruleset upon booting. You will either need to reload this firewall<br />

ruleset EVERY TIME you get a new <strong>IP</strong> address or make your /etc/rc.d/rc.firewall−ipchains−stronger<br />

ruleset more intelligent. To do this for various types of connections such as PPP or DHCP users,<br />

please see the Section 7.8 FAQ entry for all the details.<br />

/etc/rc.d/rc.firewall−*<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#echo "Enabling PORTFW Redirection on the external LAN.."<br />

#<br />

# This will forward ALL port 80 traffic from the external <strong>IP</strong> address<br />

# to port 80 on the 192.168.0.10 machine<br />

#<br />

# Be SURE that when you add these new rules to your rc.firewall−*, you<br />

# add them before a direct or implict DROP or REJECT.<br />

#<br />

PORTFW<strong>IP</strong>="192.168.0.10"<br />

# NOTE: If you are using the basic rc.firewall−iptables ruleset, you<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 106


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

# will need to enable the following EXT<strong>IP</strong> option. Users of the<br />

# rc.firewall−iptables−stronger ruleset already have this defined.<br />

#<br />

# *PLEASE* look over the rc.firewall−iptables−stronger ruleset for more<br />

# specific issues regarding dynamic vs. static <strong>IP</strong> addresses<br />

#<br />

#<br />

# Determine the external <strong>IP</strong> automatically:<br />

# −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

#<br />

# <strong>The</strong> following line will determine your external <strong>IP</strong> address. This<br />

# line is somewhat complex and confusing but it will also work for<br />

# all NON−English <strong>Linux</strong> distributions:<br />

#<br />

# DISABLED by default −− to enable, REMOVE both the "#" characters below<br />

#<br />

#EXT<strong>IP</strong>="`$IFCONFIG $EXTIF | $AWK \<br />

#/$EXTIF/'{next}//{split($0,a,":");split(a[2],a," ");print a[1];exit}'`"<br />

# Allow forwarding of new and existing port 80 connections from the external<br />

# interface. This rule is required as our default FORWARD policy is DENY.<br />

#<br />

$<strong>IP</strong>TABLES −A FORWARD −i $EXTIF −o $INTIF −p tcp −−dport 80 −m state \<br />

−−state NEW,ESTABLISHED,RELATED −j ACCEPT<br />

#Enable PORTFW of this port 80 traffic from the external interface<br />

#<br />

$<strong>IP</strong>TABLES −A PREROUTING −t nat −p tcp −d $EXT<strong>IP</strong> −−dport 80 −m state \<br />

−−state NEW,ESTABLISHED,RELATED −j DNAT −−to $PORTFW<strong>IP</strong>:80<br />

That's it! Just re−run your /etc/rc.d/rc.firewall−iptables ruleset and test it out! If you would like to learn more<br />

about this, please see the Section 7.19<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

Running the rc.firewall−iptables−stronger ruleset? Good for you! To get PORTFW running with this ruleset,<br />

it's very easy. <strong>The</strong> following example is for HTTP (WWW) traffic to be PORTFWed to the <strong>IP</strong> address<br />

indicated by the $PORTFW<strong>IP</strong> variable:<br />

• Take the ruleset lines shown above (for the generic rc.firewall−* ruleset) and place them just *after*<br />

the "#FORWARD Enable Forwarding and thus <strong>IP</strong>MASQ" comment lines. It should also be<br />

noted that you DO NOT have to enable the "HTTPD" rules under the "Optional 'INPUT' section" for<br />

2.4−based kernels. With 2.4 kernels, those lines are ONLY used if you want to allow HTTP traffic to<br />

terminate on the MASQ server's own local httpd process (usually Apache).<br />

PORTFW FTP: If you have the "ip_conntrack_ftp" and "ip_nat_ftp" kernel modules loaded into kernel space<br />

(as already done in the rc.firewall−iptables script), the simple PREROUTING command like the one shown<br />

above changed for for port "21" should do the trick. This is much easier than the configuration for the older<br />

<strong>IP</strong>CHAINS / <strong>IP</strong>FWADM tools for the 2.2.x / 2.0.x kernels!<br />

Please note, if you setup PORTFW to redirect traffic to an internal FTP server that is running on a<br />

NON−standard FTP port, say port 8021 instead of the usual port 21, you MUST tell the "ip_conntrack_ftp"<br />

module to be aware of the new FTP port. <strong>The</strong> reason for this configuration change is that FTP is not a<br />

NAT−friendly protocol. By telling the FTP NAT module about this non−standard FTP port, the NAT module<br />

and do it's job again. To enable this, edit your rc.firewall−* file and change the loading of the FTP module to<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 107


look something like this:<br />

/sbin/insmod ip_conntrack_ftp ports=21,8021<br />

PORTFW Redirection of Internal requests:<br />

In the past, if users PORTFWed port 80 on their EXTERNAL <strong>IP</strong> address to some internal machine, only the<br />

machines out on the Internet would be able to properly reach this internal WWW server. If you tried to contact<br />

this internal WWW server via the MASQ server's EXTERNAL address, it would fail. Fortunately, there are<br />

workarounds for all <strong>Linux</strong> kernels. <strong>IP</strong>TABLES for the 2.6.x and 2.4.x kernels supports this functionality<br />

natively. <strong>IP</strong>CHAINS support for the 2.2.x kernels and <strong>IP</strong>FWADM support for the 2.0.x kernels need to use the<br />

external REDIR tool (not currently covered in the <strong>HOWTO</strong>). For those of you who understand <strong>IP</strong>TABLES<br />

fairly well, the rule of thumb is a PREROUTING/DNAT rule is for enabling PORTFW from *external*<br />

machines and a POSTROUTING/SNAT rule is for enabling PORTFW from *internal* machines.<br />

To support redirection like this from an internal host, add a rule like the one shown below ABOVE the "Catch<br />

all" FORWARDing rule in the rc.firewall−* file. <strong>The</strong> following example will REDIRECT all external as well<br />

as internal WWW traffic to the internal machine noted as PORTFW<strong>IP</strong> (192.168.0.10). This traffic will have<br />

the source <strong>IP</strong> address of the <strong>IP</strong> Masq server's internal <strong>IP</strong> address. Please change the <strong>IP</strong> address of the<br />

PORTFW<strong>IP</strong> variable to reflect your specific configuration:<br />

#<strong>The</strong> following rule should be configured in *addition* to the above rule<br />

# for enabling external to internal PORTFWing<br />

$<strong>IP</strong>TABLES −t nat −A POSTROUTING −d $PORTFW<strong>IP</strong> −s $INTLAN −p tcp \<br />

−−dport 80 −m state −−state NEW,ESTABLISHED,RELATED −j SNAT \<br />

−−to $INT<strong>IP</strong><br />

6.7.2. <strong>IP</strong>MASQADM−based PORTFWD'ing: Using <strong>IP</strong>MASQADM with 2.2.x<br />

kernels<br />

First, make sure you have the newest 2.2.x kernel uncompressed into /usr/src/kernel/linux. If you haven't<br />

already done this, please see Section 3.2.2 section for full details. Next, download the "ipmasqadm.c" program<br />

from Section 2.7 into the /usr/src/kernel directory.<br />

Next, you'll need to compile the 2.2.x kernel as shown in Section 3.2.2 section. Be sure to say "YES" to the<br />

<strong>IP</strong>PORTFW option when you configure the kernel. Once the kernel compile is complete and you have<br />

rebooted, return to this section.<br />

Now, compile and install the <strong>IP</strong>MASQADM tool:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

cd /usr/src<br />

tar xzvf ipmasqadm−x.tgz<br />

cd ipmasqadm−x<br />

make<br />

make install<br />

Now, for this example, we are going to allow ALL WWW Internet traffic (port 80) hitting your Internet<br />

TCP/<strong>IP</strong> address to be forwarded to the internal <strong>Masquerade</strong>d machine at <strong>IP</strong> address 192.168.0.10.<br />

PORTFW FTP: As mentioned above, there are two solutions for forwarding FTP server traffic to an internal<br />

MASQed PC. <strong>The</strong> first solution *IS* a BETA level <strong>IP</strong>_MASQ_FTP module for 2.2.x kernels to PORT<br />

Forward FTP connections to an internal MASQed FTP server. <strong>The</strong> other method is using a FTP proxy<br />

program (the URL is in Section 2.7. It should also be noted that the FTP kernel module also supports the<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 108


adding of additional PORTFW FTP ports on the fly without the requirement of unloading and reloading the<br />

<strong>IP</strong>_MASQ_FTP module and thus breaking any existing FTP transfers. You can find more about this new code<br />

at the <strong>IP</strong>MASQ WWW site at http://ipmasq.webhop.net;. <strong>The</strong>re are also examples and some additional<br />

information about PORTFWed FTP connection below in the 2.0.x. kernel section.<br />

NOTE: Once you enable a port forwarder on port 80, that port can no longer be used by the <strong>Linux</strong> <strong>IP</strong><br />

<strong>Masquerade</strong> server. To be more specific, if you have a WWW server already running on the MASQ server, a<br />

port forward will now give all Internet users the WWW pages from the −INTERNAL− WWW server and not<br />

the pages on your <strong>IP</strong> MASQ server.<br />

Anyway, to enable port forwarding for HTTPd:<br />

• Edit the /etc/rc.d/rc.firewall−* ruleset and ENABLE the "Optional" "HTTP" sections in both the<br />

INPUT and OUTPUT subsections.<br />

• Add the following lines shown below JUST BELOW the "ipchains −P forward DENY" rule<br />

(in the "Optional FORWARD section"). Be sure to replace the "$EXT<strong>IP</strong>" variable's contents with<br />

your EXTERNAL Internet <strong>IP</strong> address on the <strong>IP</strong>MASQ server.<br />

NOTE #2: If you get a dynamically assigned TCP/<strong>IP</strong> address from your ISP (PPP, DSL, Cablemodems, etc.),<br />

you CANNOT load this strong ruleset upon booting. You will either need to reload this firewall ruleset<br />

EVERY TIME you get a new <strong>IP</strong> address or make your /etc/rc.d/rc.firewall−ipchains−stronger ruleset more<br />

intelligent. To do this for various types of connections such as PPP or DHCP users, please see the Section 7.8<br />

FAQ entry for all the details.<br />

/etc/rc.d/rc.firewall−*<br />

#echo "Enabling <strong>IP</strong>PORTFW Redirection on the external LAN.."<br />

#<br />

# This will forward ALL port 80 traffic from the external <strong>IP</strong> address<br />

# to port 80 on the 192.168.0.10 machine<br />

#<br />

PORTFW<strong>IP</strong>="192.168.0.10"<br />

/usr/sbin/ipmasqadm portfw −f<br />

/usr/sbin/ipmasqadm portfw −a −P tcp −L $EXT<strong>IP</strong> 80 −R $PORTFW<strong>IP</strong> 80<br />

That's it! Just re−run your /etc/rc.d/rc.firewall−* ruleset and test it out!<br />

If you get the error message "ipchains: setsockopt failed: Protocol not available", you AREN'T running your<br />

new <strong>IP</strong>PORTFW enabled kernel. Make sure that you moved the new kernel over, re−run LILO, and then<br />

reboot again. If you are sure you are running your new kernel, run the command "ls /proc/net/ip_masq" and<br />

make sure the "portfw" file exists. If it doesn't, you must have made an error when configuring your kernel.<br />

Try again.<br />

PORTFW Redirection of Internal requests:<br />

It should be mention that this <strong>IP</strong>MASQ <strong>HOWTO</strong> currently does *NOT* provide any explination or examples<br />

on how to use the REDIR tool. If you need help setting it up for 2.2.x kernels, send me an email. For those<br />

who want to understand why PORTFW cannot redirect traffic for both external and internal interfaces (what<br />

the REDIR tool fixes), here is an email from Juanjo that better explains it.<br />

From Juanjo Ciarlante<br />

−−<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 109


If I use:<br />

><br />

> ipmasqadm portfw −a −P tcp −L 1.2.3.4 80 −R 192.168.2.3 80<br />

><br />

>Everything works great from the outside but internal requests for the same<br />

>1.2.3.4 address fail. Are there chains that will allow a machine on localnet<br />

>192.168.2.0 to accesss www.periapt.com without using a proxy?<br />

Actually not.<br />

I usually setup a ipmasqadm rule for outside, *AND* a port<br />

redirector for inside. This works because ipmasqadm hooks before<br />

redir will get the eventual outside connection, _but_ leaves things<br />

ok if not (stated by APPROPIATE rules).<br />

<strong>The</strong> actual "conceptual" problem comes from the TRUE client (peer) <strong>IP</strong><br />

goal (thanks to masq) being in the same net as target server.<br />

<strong>The</strong> failing scenario for "local masq" is :<br />

client: 192.168.2.100<br />

masq: 192.168.2.1<br />

serv: 192.168.2.10<br />

1)client−>server packet<br />

a) client: 192.168.2.100:1025 −> 192.168.2.1:80 [SYN]<br />

b) (masq): 192.168.2.100:1025 −> 192.168.2.10:80 [SYN]<br />

(and keep 192.168.2.1:61000 192.168.2.100:1025 related)<br />

c) serv: gets masqed packet (1b)<br />

2)server−>client packet<br />

a) serv: 192.168.2.10:80 −> 192.168.2.100:1025 [SYN,ACK]<br />

b) client: 192.168.2.100:1025 −> 192.168.2.10:80 [RST]<br />

Now take a moment to compare (1a) with (2a).<br />

You see, the server replied DIRECTLY to client bypassing masq (not<br />

letting masq to UNDO the packet hacking) because it is in SAME net, so<br />

the client resets the connection.<br />

hope I helped.<br />

Warm regards<br />

Juanjo<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

6.7.3. <strong>IP</strong>PORTFW−based PORTFWD'ing: Using <strong>IP</strong>PORTFW on 2.0.x<br />

kernels<br />

First, make sure you have the newest 2.0.x kernel uncompressed into /usr/src/kernel. If you haven't already<br />

done this, please see Section 3.2.3 for full details. Next, download the "ipportfw.c" program and the<br />

"subs−patch−x.gz" kernel patch from Section 3.2.3 into the /usr/src/ directory.<br />

NOTE: Please replace the "x" in the "subs−patch−x.gz" file name with the most current version available on<br />

the site.<br />

Next, if you plan on port forwarding FTP traffic to an internal server, you will have to apply an additional<br />

NEW <strong>IP</strong>_MASQ_FTP module patch found in Section 3.2.3. More details regarding this are later in this<br />

section. Please note that this is NOT the same patch as for the 2.2.x kernels so some functionality such as the<br />

dynamic FTP PORT functionality is not present.<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 110


Now, copy the <strong>IP</strong>PORTFW patch (subs−patch−x.gz) into the <strong>Linux</strong> directory<br />

cp /usr/src/subs−patch−1.37.gz /usr/src/linux<br />

Next, apply the kernel patch to create the <strong>IP</strong>PORTFW kernel option:<br />

cd /usr/src/linux<br />

zcat subs−patch−1.3x.gz | patch −p1<br />

Ok, time to compile the kernel as shown in Section 3.2.3. Be sure to say YES to the <strong>IP</strong>PORTFW option now<br />

available when you configure the kernel. Once the compile is complete and you have rebooted, return to this<br />

section.<br />

Now with a newly compiled kernel, please compile and install the actual "<strong>IP</strong>PORTFW" program<br />

cd /usr/src<br />

gcc ipportfw.c −o ipportfw<br />

mv ipportfw /usr/local/sbin<br />

Now, for this example, we are going to allow ALL WWW Internet traffic (port 80) hitting your Internet<br />

TCP/<strong>IP</strong> address to then be forwarded to the internal <strong>Masquerade</strong>d machine at <strong>IP</strong> address 192.168.0.10.<br />

NOTE: Once you enable a port forwarder on port 80, that port can no longer be used by the <strong>Linux</strong> <strong>IP</strong><br />

<strong>Masquerade</strong> server. To be more specific, if you have a WWW server already running on the MASQ server<br />

and then you port forward port 80 to an internal MASQed computer, ALL internet users will see the WWW<br />

pages pages from the −INTERNAL− WWW server and not the pages on your <strong>IP</strong> MASQ server. This only<br />

performs a port forward to some other port, say 8080, to your internal MASQ machine. Though this will<br />

work, all Internet users will have to append :8080 to the URL to then contact the internal MASQed WWW<br />

server.<br />

Anyway, to enable port forwarding, edit the /etc/rc.d/rc.firewall−* ruleset. Add the follow lines but be sure to<br />

replace the word "$extip" with your Internet <strong>IP</strong> address.<br />

NOTE #2: If you get a dynamically assigned TCP/<strong>IP</strong> address from your ISP (PPP, DSL, Cablemodems, etc.),<br />

you CANNOT load this strong ruleset upon booting. You will either need to reload this firewall ruleset<br />

EVERY TIME you get a new <strong>IP</strong> address or make your /etc/rc.d/rc.firewall−ipchains−stronger ruleset more<br />

intelligent. To do this for various types of connections such as PPP or DHCP users, please see the Section 7.8<br />

FAQ entry for all the details.<br />

/etc/rc.d/rc.firewall−*<br />

#echo "Enabling <strong>IP</strong>PORTFW Redirection on the external LAN.."<br />

#<br />

# This will forward ALL port 80 traffic from the external <strong>IP</strong> address<br />

# to port 80 on the 192.168.0.10 machine<br />

#<br />

/usr/local/sbin/ipportfw −C<br />

/usr/local/sbin/ipportfw −A −t$extip/80 −R 192.168.0.10/80<br />

That's it! Just re−run your /etc/rc.d/rc.firewall−* ruleset and test it out!<br />

If you get the error message "ipfwadm: setsockopt failed: Protocol not available", you AREN'T running your<br />

new kernel. Make sure that you moved the new kernel over, re−run LILO, and then reboot again.<br />

Port Forwarding FTP servers:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 111


If you plan on port forwarding FTP to an internal machine, things get more complicated. <strong>The</strong> reason for this is<br />

because the standard <strong>IP</strong>_MASQ_FTP kernel module wasn't written for this though some users report that it<br />

works without any problems. Personally, without the patch, I've heard that extended file transfers in excess of<br />

30 minutes will fail without the patch while other users swear that it works flawlessly. Anyway, I recommend<br />

that you try the following PORTFW instruction with the STOCK ip_masq_ftp module and see if it works for<br />

you. If it doesn't, try using the modified ip_masq_ftp module.<br />

For those who need the module, Fred Viles wrote a modified <strong>IP</strong>_MASQ_FTP module to make things work. If<br />

you are curious what EXACTLY are the issues, download the following archive since Fred documents it quite<br />

well. Also understand that this patch is somewhat experimental and should be treated as such. It should be<br />

noted that this patch is ONLY available for the 2.0.x kernels though there is a different patch available for<br />

2.2.x kernels.<br />

So, to get the 2.0.x patch working, you need to:<br />

• FIRST, apply the <strong>IP</strong>PORTFW kernel patch as shown earlier in this section.<br />

• Download the "msqsrv−patch−36" from Fred Viles's FTP server in Section 3.2.3and put it into<br />

/usr/src/linux.<br />

• Patch the kernel with this new code by running "cat msqsrv−patch−36 | patch −p1"<br />

• Next, replace the original "ip_masq_ftp.c" kernel module with the new one<br />

mv /usr/src/linux/net/ipv4/ip_masq_ftp.c /usr/src/linux/net/ipv4/ip_masq_ftp.c.orig<br />

mv /usr/src/linux/ip_masq_ftp.c /usr/src/linux/net/ipv4/ip_masq_ftp.c<br />

• Lastly, build and install the kernel with this new code in place.<br />

Once this is complete, edit the /etc/rc.d/rc.firewall−* ruleset and add the following lines, but be sure to replace<br />

the word "$extip" with your Internet <strong>IP</strong> address.<br />

This example, like the one above, will allow ALL FTP Internet traffic (port 21) hitting your Internet TCP/<strong>IP</strong><br />

address to then be forwarded to the internal <strong>Masquerade</strong>d machine at <strong>IP</strong> address 192.168.0.10.<br />

NOTE: Once you enable a port forwarder on port 21, that port can no longer be used by the <strong>Linux</strong> <strong>IP</strong><br />

<strong>Masquerade</strong> server. To be more specific, if you have an FTP server already running on the MASQ server, a<br />

port forward will now give all Internet users the FTP files from the −INTERNAL− FTP server and not the<br />

files on your <strong>IP</strong> MASQ server.<br />

/etc/rc.d/rc.firewall−*<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

#echo "Enabling <strong>IP</strong>PORTFW Redirection on the external LAN.."<br />

#<br />

/usr/local/sbin/ipportfw −C<br />

/usr/local/sbin/ipportfw −A −t$extip/21 −R 192.168.0.10/21<br />

#NOTE: If you are using multiple local port numbers to PORTFW<br />

# to multuple internal FTP servers (say, 21, 2121, 2112,<br />

# etc, you need to configure the ip_masq_ftp nodule to<br />

# listen to these ports. To do this, edit the<br />

# /etc/rc.d/rc.firewall−* script as shown in this <strong>HOWTO</strong><br />

# to look like:<br />

#<br />

# /sbin/modprobe ip_masq_ftp ports=21,2121,2112<br />

#<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 112


# Re−run the /etc/rc.d/rc.firewall−* script for these changes to<br />

# take effect.<br />

#Please note that PORTFWing port 20 is probably NOT required<br />

# for ACTIVE connections as the internal FTP server will<br />

# initiate this port 20 connection and it will be properly<br />

# handled by the classic MASQ mechanisms.<br />

That's it! Just re−run your /etc/rc.d/rc.firewall−* ruleset and test it out!<br />

PORTFW Redirection of Internal requests:<br />

It's not clear if the REDIR tool will compile or work against legacy 2.0.x kernels. It should also be mentioned<br />

that this <strong>IP</strong>MASQ <strong>HOWTO</strong> currently does *NOT* provide any explination or examples on how to use the<br />

REDIR tool. If you need help setting it up, send me an email. If you would like to learn more about REDIR,<br />

please see the above section for the 2.2.x kernels.<br />

6.8. CU−SeeMe and <strong>Linux</strong> <strong>IP</strong>−<strong>Masquerade</strong><br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> supports CuSeeme via the "ip_masq_cuseeme" kernel module. This kernel modules<br />

should be loaded in the /etc/rc.d/rc.firewall−* script. Once the "ip_masq_cuseeme" module is installed, you<br />

should be able to both initiate and receive CuSeeme connections to remote reflectors and/or users.<br />

NOTE: It is recommended to use the <strong>IP</strong>PORTFW tool instead of the old <strong>IP</strong>AUTOFW tool for running<br />

CuSeeme.<br />

If you need more explicit information on configuring CuSeeme, see Michael Owings's CuSeeMe page for a<br />

Mini−<strong>HOWTO</strong> or <strong>The</strong> <strong>IP</strong> <strong>Masquerade</strong> Resources for a mirror of the Mini−<strong>HOWTO</strong>.<br />

6.9. Mirabilis ICQ<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

ICQ, the instant messaging client now owned by AOL, has changed over the years. All modern ICQ clients<br />

are NAT friendly and thus DON'T require any special NAT modules, PORTFW tricks, etc.<br />

IF, for some reason, you want to run an OLD ICQ client, you can read this section. If not, just IGNORE all<br />

this info. I am leaving this in the <strong>HOWTO</strong> demonstrate large a LARGE PORTFW example.<br />

<strong>The</strong>re are three methods of getting ICQ to work behind a <strong>Linux</strong> MASQ server. <strong>The</strong>se solutions include the use<br />

the ICQ Masq module (for 2.2.x and 2.0.x kernels), using <strong>IP</strong>PORTFW for basic ICQ functionality, or setting<br />

up a SOCKS proxy server.<br />

MODULE: <strong>The</strong> ICQ module was written for the older generation of ICQ clients for both the 2.2.x and 2.0.x<br />

kernels. This module allows for the simple setup of multiple ICQ users behind a MASQ server. It also doesn't<br />

require any special changes to the ICQ client(s). Recently, AOL changed the protocol and ports used for ICQ.<br />

Because of this, many users might find that the ip_masq_icq module will no longer help them. For users of the<br />

older ICQ clients, the 2.2.x version of the module supports file transfer and read−time chat. <strong>The</strong> 2.0.x kernel<br />

module doesn't support file transfers and there is no module available for the 2.4.x kernels.<br />

PORTFW: Your next option is to use port forwarding. With port forwarding, basic ICQ chat will work but file<br />

transfers might not be very reliable. Please see below for an example of how to configure ICQ PORTFW.<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 113


SOCKS: Finally, your last and possibly best option is to setup a SOCKS proxy server on your <strong>Linux</strong> machine.<br />

This service can happily co−exist with the MASQ service and ICQ should be fully functional regardless of<br />

what <strong>Linux</strong> kernel version you are running. <strong>The</strong> use of a SOCKS server will require ALL ICQ clients to be<br />

reconfigured to use it and the installation and configuration of a SOCKS server has nothing to do with <strong>IP</strong><br />

<strong>Masquerade</strong>. Because of this, SOCKS is not covered in this <strong>HOWTO</strong>.<br />

If you are interested in Andrew Deryabin's djsf@usa.net ICQ <strong>IP</strong> Masq module for the 2.2.x and 2.0.x kernels,<br />

please see Section 2.7 for details.<br />

To use port forwarding (PORFW)for ICQ, you will have to make some changes on both <strong>Linux</strong> and ICQ<br />

clients but all ICQ messaging, URLs, chat, and some file transfers should work.<br />

• First, you need to be running a <strong>Linux</strong> kernel with <strong>IP</strong>PPORTFW enabled. Please see Section 6.7for<br />

more details.<br />

• Next, you need to add the following lines to your /etc/rc.d/rc.firewall−* file. This example assumes<br />

that 10.1.2.3 is your external Internet <strong>IP</strong> address and your internal MASQed ICQ machine is<br />

192.168.0.10:<br />

• <strong>The</strong> following example is for a 2.2.x kernel with <strong>IP</strong>CHAINS:<br />

I have included two examples here for the user: Either one would work fine:<br />

Example #1<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2000 −R 192.168.0.10 2000<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2001 −R 192.168.0.10 2001<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2002 −R 192.168.0.10 2002<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2003 −R 192.168.0.10 2003<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2004 −R 192.168.0.10 2004<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2005 −R 192.168.0.10 2005<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2006 −R 192.168.0.10 2006<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2007 −R 192.168.0.10 2007<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2008 −R 192.168.0.10 2008<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2009 −R 192.168.0.10 2009<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2010 −R 192.168.0.10 2010<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2011 −R 192.168.0.10 2011<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2012 −R 192.168.0.10 2012<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2013 −R 192.168.0.10 2013<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2014 −R 192.168.0.10 2014<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2015 −R 192.168.0.10 2015<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2016 −R 192.168.0.10 2016<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2017 −R 192.168.0.10 2017<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2018 −R 192.168.0.10 2018<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2019 −R 192.168.0.10 2019<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 2020 −R 192.168.0.10 2020<br />

Example #2<br />

port=2000<br />

while [ $port −le 2020 ]<br />

do<br />

/usr/local/sbin/ipmasqadm portfw −a −P tcp −L 10.1.2.3 $port −R 192.168.0.10 $port<br />

port=$((port+1))<br />

done<br />

• <strong>The</strong> following example is for a 2.0.x kernel with <strong>IP</strong>FWADM:<br />

I have included two examples here for the user: Either one would work fine:<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 114


Example #1<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2000 −R 192.168.0.10/2000<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2001 −R 192.168.0.10/2001<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2002 −R 192.168.0.10/2002<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2003 −R 192.168.0.10/2003<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2004 −R 192.168.0.10/2004<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2005 −R 192.168.0.10/2005<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2006 −R 192.168.0.10/2006<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2007 −R 192.168.0.10/2007<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2008 −R 192.168.0.10/2008<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2009 −R 192.168.0.10/2009<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2010 −R 192.168.0.10/2010<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2011 −R 192.168.0.10/2011<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2012 −R 192.168.0.10/2012<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2013 −R 192.168.0.10/2013<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2014 −R 192.168.0.10/2014<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2015 −R 192.168.0.10/2015<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2016 −R 192.168.0.10/2016<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2017 −R 192.168.0.10/2017<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2018 −R 192.168.0.10/2018<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2019 −R 192.168.0.10/2019<br />

/usr/local/sbin/ipportfw −A −t10.1.2.3/2020 −R 192.168.0.10/2020<br />

Example #2<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

port=2000<br />

while [ $port −le 2020 ]<br />

do<br />

/usr/local/sbin/ipportfw −A t10.1.2.3/$port −R 192.168.0.10/$port<br />

port=$((port+1))<br />

done<br />

• Once your new rc.firewall−* is ready, reload the ruleset to make sure things are OK by simply typing<br />

in "/etc/rc.d/rc.firewall−*". If you get any errors, you either don't have <strong>IP</strong>PORTFW support in the<br />

kernel or you made a typo in the rc.firewall file.<br />

• Now, in ICQ's Preferences−−>Connection, configure it to be "Behind a LAN" and "Behind a firewall<br />

or Proxy". Now, click on "Firewall Settings" and configure it to be "I don't use a SOCK5 proxy". Also<br />

note that it was previously recommended to change ICQ's "Firewall session timeouts" to "30" seconds<br />

BUT many users have found that ICQ becomes unreliable. It has been found that ICQ is more reliable<br />

with its stock timeout setting (don't enable that ICQ option) and simply change MASQ's timeout to<br />

160 seconds. You can see how to change this timeout in Section 3.4.3 and Section 3.4.2 rulesets.<br />

Finally, click on Next and configure ICQ to "Use the following TCP listen ports.." from "2000" to<br />

"2020". Now click done.<br />

Now ICQ will tell you that you will have to restart ICQ for the changes to take effect. To be honest, I<br />

had to REBOOT the Windows9x machine in order for things to work right but some users might say<br />

otherwise. So.. try it both ways.<br />

• A user once told me that by simply portforwarding port 4000 to his ICQ machine, it worked perfectly.<br />

He reported that EVERYTHING worked fine (even chat, file transfers, etc) WITHOUT<br />

re−configuring ICQ from its default settings. Your mileage might vary on this topic but I thought you<br />

might like to hear about this alternative configuration.<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 115


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

6.10. Gamers: <strong>The</strong> LooseUDP patch<br />

<strong>The</strong> LooseUDP patch allows semi−NAT−friendly games that usually use UDP connections to both WORK<br />

behind a <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> server.<br />

What the LooseUDP patch does is allow ALL UDP packets to be NATed through the MASQ box without any<br />

checks or expiration. This liberal forwarding method is considered insecure by many and is disabled in<br />

modern 2.2.x kernels. <strong>The</strong> 2.4.x kernels with it's <strong>IP</strong>TABLES stateful UDP inspection only allows incoming<br />

UDP packets into the machine (and thus MASQ) if there was already an outbound UDP packet to that same<br />

host in it's stateful table. If the MASQ host hasn't sent a UDP packet to the remote host within ~30 seconds,<br />

the return UDP table entry is deleted. Because of this, <strong>IP</strong>TABLES removes most of the need for the<br />

LooseUDP patch as it does it in a more secure fashion.<br />

Currently, LooseUDP is available as a patch for 2.0.36+ kernels and it is already built into 2.2.3+ kernels<br />

though it is now DISABLED by DEFAULT in 2.2.16+ (please see the example rc.firewal ruleset comments<br />

for details).<br />

To get LooseUDP running on a 2.0.x kernel, follow the following steps:<br />

• Have the newest 2.0.x kernel sources uncompressed in the /usr/src/linux directory<br />

• ABSOLUTELY REQUIRED for v2.0.x: Download and install the <strong>IP</strong>PORTFW patch from Section<br />

3.2.3and as described in Section 6.7of the <strong>HOWTO</strong>.<br />

• Download the LooseUDP patch from Section 3.2.3<br />

Now, put the LooseUDP patch in the /usr/src/linux directory. Once this is done, type in:<br />

For a compressed patch file: zcat loose−udp−2.0.36.patch.gz | patch −p1<br />

For a NON−compressed patch file: cat loose−udp−2.0.36.patch | patch −p1<br />

Now, depending on the version of your "patch", You will then see the following text:<br />

patching file `CREDITS'<br />

patching file `<strong>Documentation</strong>/Configure.help'<br />

patching file `include/net/ip_masq.h'<br />

patching file `net/ipv4/Config.in'<br />

patching file `net/ipv4/ip_masq.c'<br />

• If you see the text "Hunk FAILED" only ONCE and ONLY ONCE at the very beginning of the<br />

patching, don't be alarmed. You probably have an old patch file (this has been fixed) but it still works.<br />

If it fails completely, make sure you have applied the <strong>IP</strong>PORTFW kernel patch FIRST.<br />

Once the patch is installed, re−configure the kernel as shown in Section 3.2.3 and be sure to say "Y"<br />

to the "<strong>IP</strong>: loose UDP port managing (EXPERIMENTAL) (CONFIG_<strong>IP</strong>_MASQ_LOOSE_UDP)<br />

[Y/n/?]" option.<br />

To get LooseUDP running on a 2.2.x kernel, follow the following steps:<br />

• In the /etc/rc.d/rc.firewall−* script, goto the BOTTOM of the file and find the LooseUDP section.<br />

Change the "0" in the line: echo "0" > /proc/sys/net/ipv4/ip_masq_udp_dloose to<br />

a "1" and re−run the rc.firewall−* ruleset. An example of this is given in both Section 3.4.2 example<br />

and Section 6.4.3 example.<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 116


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

NOTE: <strong>The</strong> LooseUDP code is /not/ available (?required?) for the 2.4.x kernels<br />

• See the begining of this section for all the details. Basically, the old 2.0.x / 2.2.x LooseUDP code was<br />

considered a security issue. Because of this, it was removed from the kernel. Fortunately, some games<br />

that used to require the LooseUDP code on the 2.2.x <strong>IP</strong>CHAINS system might work just final under<br />

the 2.4.x <strong>IP</strong>TABLES kernels. If the games don't work, I'm not aware of a solution for you. Sorry.<br />

Once you are running the new LooseUDP enabled kernel, you should be good to go for most NAT−friendly<br />

games. Some URLs have been given for patches to make games like BattleZone and others NAT friendly.<br />

Please see Section 6.3.1 for more details.<br />

Chapter 6. Other <strong>IP</strong> <strong>Masquerade</strong> Issues and Software Support 117


Chapter 7. Frequently Asked Questions<br />

If you can think of any useful FAQ suggestions, please send it to dranch@trinnet.net. Please clearly state the<br />

question and an appropriate answer (if you have it). Thank you!<br />

7.1. ( Distro ) − What <strong>Linux</strong> Distributions support <strong>IP</strong><br />

Masquerading?<br />

If your <strong>Linux</strong> distribution doesn't support <strong>IP</strong> MASQ out of the box, don't worry. All you have to do is to<br />

re−compile the kernel as shown above in this <strong>HOWTO</strong>.<br />

NOTE: If you can help us fill out this table, please email dranch@trinnet.net.<br />

• Caldera < v1.2 : NO − ?<br />

• Caldera v1.3 : YES − 2.0.35 based<br />

• Caldera v2.2 : YES − 2.2.5 based<br />

• Caldera eServer v2.3 : YES − ? based<br />

• Debian v1.3 : NO − ?<br />

• Debian v2.0 : NO − ?<br />

• Debian v2.1 : YES − 2.2.1 based<br />

• Debian v2.2 : YES − 2.2.15 based<br />

• Debian v3.0 : YES − 2.4.18 based<br />

• DLX <strong>Linux</strong> v? : ? − ?<br />

• DOS <strong>Linux</strong> v? : ? − ?<br />

• FloppyFW v1.0.2 : ? − ?<br />

• Gentoo v1.4 : YES − ? Based<br />

• Hal91 <strong>Linux</strong> v? : ? − ?<br />

• <strong>Linux</strong> PPC vR4 : NO − ?<br />

• <strong>Linux</strong> Pro v? : ? − ?<br />

• <strong>Linux</strong>Ware v? : ? − ?<br />

• Mandrake v5.3 : YES − ?<br />

• Mandrake v6.0 : YES − 2.2.5<br />

• Mandrake v6.1 : YES − ?<br />

• Mandrake v7.0 : YES − 2.2.14<br />

• Mandrake v7.1 : YES − 2.2.15<br />

• Mandrake v7.2 : YES − 2.2.17<br />

• Mandrake v8.0 : YES − ?<br />

• Mandrake v8.1 : YES − 2.4.8<br />

• Mandrake v8.2 : YES − ?<br />

• Mandrake v9.0 : YES − ?<br />

• Mandrake v9.1 : YES − 2.4.21−pre<br />

• Mk<strong>Linux</strong> v? : ? − ?<br />

• Mu<strong>Linux</strong> v3rl : YES − ?<br />

• Redhat < v4.x : NO − ?<br />

• Redhat v5.0 : YES − ?<br />

• Redhat v5.1 : YES − 2.0.34 based<br />

• Redhat v5.2 : YES − 2.0.36 based<br />

• Redhat v6.0 : YES − 2.2.5 based<br />

• Redhat v6.1 : YES − 2.2.12 based<br />

Chapter 7. Frequently Asked Questions 118


• Redhat v6.2 : YES − 2.2.14 based<br />

• Redhat v7.0 : YES − 2.2.16 based<br />

• Redhat v7.2 : YES − 2.4.7 based<br />

• Redhat v7.3 : YES − 2.4.? based<br />

• Redhat v8.0 : YES − 2.4.18? based<br />

• Redhat v9.0 : YES − 2.4.20 based<br />

• Slackware v3.0 : ? − ?<br />

• Slackware v3.1 : ? − ?<br />

• Slackware v3.2 : ? − ?<br />

• Slackware v3.3 : ? − 2.0.34 based<br />

• Slackware v3.4 : ? − ?<br />

• Slackware v3.5 : ? − ?<br />

• Slackware v3.6 : ? − ?<br />

• Slackware v3.9 : ? − 2.0.37pre10 based<br />

• Slackware v4.0 : YES − 2.2.6 based<br />

• Slackware v7.0 : YES − 2.2.13 based<br />

• Slackware v7.1 : YES − 2.2.16 based<br />

• Slackware v8.0 : YES − 2.4.17 based<br />

• Slackware v8.1 : YES − ? based<br />

• Stampede <strong>Linux</strong> v? : ? − ?<br />

• SuSE v5.2 : YES − 2.0.32 base<br />

• SuSE v5.3 : YES − ?<br />

• SuSE v6.0 : YES − 2.0.36 based<br />

• SuSE v6.1 : YES − 2.2.5 based<br />

• SuSE v6.3 : YES − 2.2.13 based<br />

• Tomsrbt <strong>Linux</strong> v? : ? − ?<br />

• Turbo<strong>Linux</strong> Lite v4.0 : YES − ?<br />

• Turbo<strong>Linux</strong> v6.0 : YES − 2.2.12 based<br />

• Tri<strong>Linux</strong> v? : ? − ?<br />

• Yggdrasil <strong>Linux</strong> v? : ? − ?<br />

7.2. ( Requirements ) − What are the minimum hardware<br />

requirements and any limitations for <strong>IP</strong> <strong>Masquerade</strong>? How<br />

well does it perform?<br />

A 486/66 box with 16MB of RAM was more than sufficient to fill a 1.54Mb/s T1 100%! MASQ has also been<br />

known to run quite well on 386SX−16s with 8MB of RAM. Yet, it should be noted that <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong><br />

starts thrashing the system with more than 500 MASQ entries.<br />

<strong>The</strong> only application that I know which can temporarily break <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong>, is GameSpy. Why?<br />

When it refreshes its lists, it creates 10,000s of quick connections in a VERY short period of time. Until these<br />

sessions timeout, the MASQ tables become "FULL". See Section 7.23 of the FAQ for more details.<br />

While we are at it:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

<strong>The</strong>re is a hard limit of 4096 concurrent connections each for TCP & UDP. This limit can be changed by<br />

fiddling the values in /usr/src/linux/net/ipv4/ip_masq.h − a maximum limit of 32000 should by OK. If you<br />

want to change the limit − you need to change the PORT_MASQ_BEGIN & PORT_MASQ_END values to<br />

get an appropriately sized range above 32K and below 64K.<br />

Chapter 7. Frequently Asked Questions 119


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

7.3. ( Errors ) − When I run my specific rc.firewall−* ruleset, I<br />

get "command not found" errors. Why?<br />

First off, when I say rc.firewall−*, what I really mean is to use one of the various types of firewall rulesets<br />

depending on what kernel version you're running. Your options from this <strong>HOWTO</strong> include:<br />

rc.firewall−iptables or rc.firewall−iptables−stronger or rc.firewall−ipchains or rc.firewall−ipchains−stronger<br />

or rc.firewall−ipfwadm or rc.firewall−ipfwadm−stronger.<br />

Next, how did you put the rc.firewall−* onto your machine? Did you cut&paste it into a TELNET window,<br />

FTP it from a Windows/DOS machine, etc? Try this.. log into your <strong>Linux</strong> box and run "vim −b<br />

/etc/rc.d/rc.firewall−*" and see if all your lines end in a ^M. If they do, delete all the ^M and try again.<br />

7.4. ( Still wont work ) − I've checked all my configurations, I<br />

still can't get <strong>IP</strong> <strong>Masquerade</strong> to work. What should I do?<br />

• Stay calm. Get yourself a cup of tea, coffee, soda, etc., and have a rest. Once your mind is clear, try<br />

the suggestions mentioned below. Setting up <strong>Linux</strong> <strong>IP</strong> Masquerading is NOT hard but there are<br />

several concepts that will be new to you.<br />

• Again, go through all the steps in Chapter 5. 99% of all first−time <strong>Masquerade</strong> users who have<br />

problems haven't looked here.<br />

• Check the <strong>IP</strong> <strong>Masquerade</strong> Mailing List Archives, most likely your questions or problems are a<br />

common one and can be found in a simple Archive search.<br />

• Check out the TrinityOS document. It covers <strong>IP</strong> Masquerading for both the 2.0.x and 2.2.x kernels<br />

and MANY other topics including PPPd, DialD, DHCP, DNS, Sendmail, etc.<br />

• Make sure that you aren't running ROUTED or GATED. To verify, run "ps aux | grep −e routed −e<br />

gated"<br />

• Post your question to the <strong>IP</strong> <strong>Masquerade</strong> Mailing List (see next the FAQ section for details). Please<br />

only use this if you cannot find the answer from the <strong>IP</strong> Masquerading Archive. Be sure to include all<br />

the information requested in Chapter 5 in your email!!<br />

• Post your question to a related <strong>Linux</strong> NNTP newsgroup.<br />

• Send email to ambrose@writeme.com and dranch@trinnet.net. You have a better chance of getting a<br />

reply from the <strong>IP</strong> Masquerading Email list than either of us.<br />

• Check your configurations again :−)<br />

7.5. ( Email list ) − How do I join or view the <strong>IP</strong> <strong>Masquerade</strong><br />

and/or <strong>IP</strong> Masqurade Developers mailing lists and archives?<br />

<strong>The</strong>re are two ways to join the two <strong>Linux</strong> <strong>IP</strong> Masquerading mailing lists. <strong>The</strong> first way is to send an email to<br />

masq−request@indyramp.com. To join the <strong>Linux</strong> <strong>IP</strong> Masquerading Developers mailing list, send an email to<br />

masq−dev−request@indyramp.com. Please see the bullet below for more details.<br />

• Subscribe via email: Now put the word "subscribe" in either the subject or body of the e−mail<br />

message. If you want to only subscribe to the Digest version of either the main MASQ or<br />

MASQ−DEV list (all e−mails on the given list during the week are sent to you in one big email), put<br />

the words "subscribe digest" in either the subject or body of the e−mail message.<br />

Chapter 7. Frequently Asked Questions 120


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Once the server receives your request, it will subscribe you to your requested list and give you a<br />

PASSWORD. Save this password as you will need it to later unsubscribe from the list or change your<br />

options.<br />

<strong>The</strong> second method is to use a WWW browser and subscribe via a form at<br />

http://home.indyramp.net/mailman/listinfo/masq for the main MASQ list or<br />

http://home.indyramp.net/mailman/listinfo/masq−dev for the MASQ−DEV list.<br />

Once subscribed, you will get emails from your subscribed list. It should be also noted that both subscribed<br />

and NON−subscribed users can access the two list's archives. To do this, please see the above two WWW<br />

URLs for more details.<br />

Lastly, please note that you can only post to the MASQ list from the original account/address you used to<br />

subscribe.<br />

If you have any problems regarding the mailing list or the mailing list archive, please contact Robert Novak.<br />

7.6. ( NAT vs. Proxy ) − How does <strong>IP</strong> <strong>Masquerade</strong> differ from<br />

Proxy or NAT services?<br />

Proxy: Proxy servers are available for: Win95, NT, <strong>Linux</strong>, Solaris, etc.<br />

Pro: + (1) <strong>IP</strong> address ; cheap<br />

+ Optional caching for better performance (WWW, etc.)<br />

Con: − All applications behind the proxy server must both SUPPORT<br />

proxy services (SOCKS) and be CONFIGURED to use the Proxy<br />

server<br />

− Screws up WWW counters and WWW statistics<br />

A proxy server uses only (1) public <strong>IP</strong> address, like <strong>IP</strong> MASQ, and acts<br />

as a translator to clients on the private LAN (WWW browser, etc.).<br />

This proxy server receives requests like TELNET, FTP, WWW,<br />

etc. from the private network on one interface. It would then in turn,<br />

initiate these requests as if someone on the local box was making the<br />

requests. Once the remote Internet server sends back the requested<br />

information, it would re−translate the TCP/<strong>IP</strong> addresses back to the<br />

internal MASQ client and send traffic to the internal requesting host.<br />

This is why it is called a PROXY server.<br />

Note: ANY applications that you might want to use on the<br />

internal machines *MUST* have proxy server support<br />

like Netscape and some of the better TELNET and FTP<br />

clients. Any clients that don't support proxy servers<br />

won't work.<br />

Another nice thing about proxy servers is that some of them<br />

can also do caching (Squid for WWW). So, imagine that you have 50<br />

proxied hosts all loading Netscape at once. If they were installed<br />

with the default homepage URL, you would have 50 copies of the same<br />

Netscape WWW page coming over the WAN link for each respective computer.<br />

With a caching proxy server, only one copy would be downloaded by the<br />

proxy server and then the proxied machines would get the WWW page from<br />

the cache. Not only does this save bandwidth on the Internet<br />

connection, it will be MUCH MUCH faster for the internal proxied<br />

machines.<br />

Chapter 7. Frequently Asked Questions 121


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

MASQ: <strong>IP</strong> Masq is available on <strong>Linux</strong> and a few ISDN routers such<br />

or as the Zytel Prestige128, Cisco 770, NetGear ISDN routers, etc.<br />

1:Many<br />

NAT<br />

Pro: + Only (1) <strong>IP</strong> address needed (cheap)<br />

+ Doesn't require special application support<br />

+ Uses firewall software so your network can become<br />

more secure<br />

Con: − Requires a <strong>Linux</strong> box or special ISDN router<br />

(though other products might have this.. )<br />

− Incoming traffic cannot access your internal LAN<br />

unless the internal LAN initiates the traffic or<br />

specific port forwarding software is installed.<br />

Many NAT servers CANNOT provide this functionality.<br />

− Special protocols need to be uniquely handled by<br />

firewall redirectors, etc. <strong>Linux</strong> has full support<br />

for this (FTP, IRC, etc.) capabilty but many routers<br />

do NOT (NetGear DOES).<br />

Masq or 1:Many NAT is similar to a proxy server in the sense that the<br />

server will perform <strong>IP</strong> address translation and fake out the remote server<br />

(WWW for example) as if the MASQ server made the request instead of an<br />

internal machine.<br />

<strong>The</strong> major difference between a MASQ and PROXY server is that MASQ servers<br />

don't need any configuration changes to all the client machines. Just<br />

configure them to use the linux box as their default gateway and everything<br />

will work fine. You WILL need to install special <strong>Linux</strong> modules for things<br />

like RealAudio, FTP, etc. to work)!<br />

Also, many users operate <strong>IP</strong> MASQ for TELNET, FTP, etc. *AND* also setup a<br />

caching proxy on the same <strong>Linux</strong> box for WWW traffic for the additional<br />

performance.<br />

NAT: NAT servers are available on Windows 95/NT, <strong>Linux</strong>, Solaris, and some<br />

of the better ISDN routers (not Ascend)<br />

Pro: + Very configurable<br />

+ No special application software needed<br />

Con: − Requires a subnet from your ISP (expensive)<br />

Network Address Translation is the name for a box that would have a pool of<br />

valid <strong>IP</strong> addresses on the Internet interface which it can use. Whenever the<br />

Internal network wanted to go to the Internet, it associates an available<br />

VALID <strong>IP</strong> address from the Internet interface to the original requesting<br />

PRIVATE <strong>IP</strong> address. After that, all traffic is re−written from the NAT<br />

public <strong>IP</strong> address to the NAT private address. Once the associated PUBLIC<br />

NAT address becomes idle for some pre−determined amount of time, the<br />

PUBLIC <strong>IP</strong> address is returned back into the public NAT pool.<br />

<strong>The</strong> major problem with NAT is, once all of the free public <strong>IP</strong> addresses are<br />

used, any additional private users requesting Internet service are out of<br />

luck until a public NAT address becomes free.<br />

For an excellent and very comprehensive description of the various forms of NAT, please see:<br />

Chapter 7. Frequently Asked Questions 122


• http://www.suse.de/~mha/linux−ip−nat/diplom/nat.html/<br />

Here is another good site to learn about NAT, although many of the URLs are old but still valid:<br />

• http://www.linas.org/linux/load.html/<br />

7.7. ( GUI ) − Are there any GUI firewall<br />

creation/management tools?<br />

Yes! <strong>The</strong>y vary in the type of user interface, complexity, etc. but they are quite good though most are only for<br />

the <strong>IP</strong>FWADM tool so far. Here is a short list of available tools in alphabetical order. If you know of any<br />

others or have any thoughts on which ones are good/bad/ugly, please email David.<br />

• John Hardin's <strong>IP</strong>FWADM Dot file generator − a <strong>IP</strong>CHAINS version is in the works<br />

• Sonny Parlin's fBuilder: From the author of FWCONFIG, this new solution is fully WWW based and<br />

offers redundancy options, etc for both <strong>IP</strong>CHAINS and NetFilter.<br />

• William Stearns's Mason − A Build−a−ruleset on−the−fly type system<br />

7.8. ( MASQ and Dynamic <strong>IP</strong>s ) − Does <strong>IP</strong> <strong>Masquerade</strong> work<br />

with dynamically assigned <strong>IP</strong> addresses?<br />

Yes, it works with either dynamic <strong>IP</strong> addressed assigned by your ISP via either PPP or a DHCP server<br />

(common for Cablemodem and DSL users). As long as you have a valid Internet <strong>IP</strong> address, it should work.<br />

Of course, static <strong>IP</strong>s work too. If you plan on implementing a strong <strong>IP</strong>TABLES, <strong>IP</strong>CHAINS, or <strong>IP</strong>FWADM<br />

ruleset and/or plan on using a Port forwarder, your ruleset will have to be re−executed everytime your <strong>IP</strong><br />

address changes.<br />

So, re−running the rc−firewall−* ruleset really depends on which method you get your <strong>IP</strong> addresses:<br />

•<br />

•<br />

PPP: <strong>The</strong> /etc/ppp/ip−up script is always run when a PPP connection comes up. Because of this, we<br />

can make the rc.firewall−* go get the new PPP <strong>IP</strong> address and update the firewall ruleset. If the<br />

/etc/ppp/ip−up file doesn't exist or if does exists, simply edit that file and append a line containing the<br />

name of your chosen firewall ruleset. For example, to run the SIMPLE <strong>IP</strong>TABLES ruleset:<br />

/etc/rc.d/rc.firewall−iptables<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

DHCP: If you get your <strong>IP</strong> address via DHCP, common for Cablemodem and DSL users, it's easy get<br />

the rc.firewall−* ruleset to run when you get a new <strong>IP</strong> lease. How this happens depends on what<br />

DHCP client your distribution uses:<br />

♦ dhclient : Most modern <strong>Linux</strong> distributions use dhclient from ISC. To re−run your specific<br />

rc−firewall−* script when your system gets a new <strong>IP</strong> address, add the following line to the<br />

/etc/dhclient−exit−hooks file. Please note that this example is loging the SIMPLE <strong>IP</strong>TABLES<br />

ruleset. Please use the correct rc.firewall−* name for your specific setup:<br />

/etc/rc.d/rc.firewall−iptables<br />

♦ pump : Many older Redhat distributions use this DHCP client. To re−run the rc−firewall−*<br />

script when your system gets a new <strong>IP</strong> address, add the following line to the /etc/pump.conf<br />

file. Please note that this example is loading the SIMPLE <strong>IP</strong>TABLES ruleset. Please use the<br />

Chapter 7. Frequently Asked Questions 123


♦<br />

correct rc.firewall−* name for your specific setup:<br />

script /etc/rc.d/rc.firewall−iptables<br />

dhcpcd : Many older distros use this DHCP client. To re−run the rc−firewall−* script when<br />

your system gets a new <strong>IP</strong> address depends on which verion of dhcpcd you're using.<br />

For newer dhcpcd client versions, append the following line to the<br />

/etc/dhcpcd−[interface].exe file. Please note that you have to replace the [interface] text with<br />

the name of your Interface connecting to the Internet. For this example, we are going run the<br />

SIMPLE <strong>IP</strong>TABLES ruleset against the eth0 interface by editing the<br />

/etc/dhcpc/dhcpcd−eth0.exe file:<br />

/etc/rc.d/rc.firewall−iptables<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

For old dhcpcd client versions, you need to figure out what script starts up dhcpcd (depends<br />

on the <strong>Linux</strong> distribution and it's version). From there, you need to replace the specific<br />

dhcpcd line with the folling line with the correct Internet−facing interface name. For this<br />

example, dhcpcd will run the SIMPLE <strong>IP</strong>TABLES ruleset against the eth0 interface:<br />

dhcpcd −c /etc/rc.d/rc.firewall eth0<br />

Please also see the top of TrinityOS − Section 10 for additional help with strong firewall rulesets and<br />

Dynamic <strong>IP</strong> addresses.<br />

7.9. ( MASQ and various networks ) − Can I use a cable<br />

modem (both bi−directional and with modem returns), DSL,<br />

satellite link, etc. to connect to the Internet and use <strong>IP</strong><br />

<strong>Masquerade</strong>?<br />

Yes, as long as <strong>Linux</strong> supports that network interface, it should work. If you receive a dynamic <strong>IP</strong> address,<br />

please see the URL under the "Does <strong>IP</strong> <strong>Masquerade</strong> work with dynamically assigned <strong>IP</strong>" FAQ item above.<br />

7.10. ( Dial on Demand ) − Can I use Diald or the<br />

Dial−on−Demand feature of PPPd with <strong>IP</strong> MASQ?<br />

Definitely! <strong>IP</strong> Masquerading is totally transparent to Diald or PPP. <strong>The</strong> only thing that might become an issue<br />

is if you use STRONG firewall rulesets with dynamic <strong>IP</strong> addresses. See the FAQ item, "Does <strong>IP</strong> <strong>Masquerade</strong><br />

work with dynamically assigned <strong>IP</strong> addresses?" above for more details.<br />

7.11. ( Apps ) − What applications are supported with <strong>IP</strong><br />

<strong>Masquerade</strong>?<br />

It is very difficult to keep track of a list of "working applications". However, most of the normal Internet<br />

applications are supported, such as WWW browsing (Netscape, MSIE, etc.), FTP (such as WS_FTP),<br />

TELNET, SSH, RealAudio, POP3 (incoming email − Pine, Eudora, Outlook), SMTP (outgoing email), etc. A<br />

Chapter 7. Frequently Asked Questions 124


somewhat more complete list of MASQ−compatible clients can be found in Section 6.3 in this <strong>HOWTO</strong>.<br />

Applications involving more complicated protocols or special connection methods such as video conferencing<br />

software need special helper tools.<br />

For more details, please see the <strong>Linux</strong> <strong>IP</strong> masquerading Applications page.<br />

7.12. ( Distro Setup ) − How can I get <strong>IP</strong> <strong>Masquerade</strong> running<br />

on Redhat, Debian, Slackware, etc.?<br />

No matter which <strong>Linux</strong> distribution you have, the procedures for setting up <strong>IP</strong> <strong>Masquerade</strong> mentioned in this<br />

<strong>HOWTO</strong> should apply. Some distributions may have GUI or special configuration files that make the setup<br />

easier. We tried our best to write this <strong>HOWTO</strong> as general as possible.<br />

7.13. ( Timeouts ) − Connections seem to break if I don't use<br />

them often. Why is that?<br />

<strong>IP</strong> Masq, by default, sets its timers for TCP session, TCP FIN, and UDP traffic to 15 minutes. It is recommend<br />

to use the following settings (as already shown in this <strong>HOWTO</strong>'s /etc/rc.d/rc.firewall−* ruleset) for most<br />

users:<br />

<strong>Linux</strong> 2.4.x with <strong>IP</strong>TABLES<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

<strong>IP</strong>MASQ timeouts are NOT adjustable under <strong>IP</strong>TABLES<br />

<strong>Linux</strong> 2.2.x with <strong>IP</strong>CHAINS:<br />

# MASQ timeouts<br />

#<br />

# 2 hrs timeout for TCP session timeouts<br />

# 10 sec timeout for traffic after the TCP/<strong>IP</strong> "FIN" packet is received<br />

# 60 sec timeout for UDP traffic (MASQ'ed ICQ users must enable a 30sec<br />

# firewall timeout in ICQ itself)<br />

#<br />

/ipchains −M −S 7200 10 60<br />

<strong>Linux</strong> 2.0.x with <strong>IP</strong>FWADM:<br />

# MASQ timeouts<br />

#<br />

# 2 hrs timeout for TCP session timeouts<br />

# 10 sec timeout for traffic after the TCP/<strong>IP</strong> "FIN" packet is received<br />

# 60 sec timeout for UDP traffic (MASQ'ed ICQ users must enable a 30sec<br />

# firewall timeout in ICQ itself)<br />

#<br />

/sbin/ipfwadm −M −s 7200 10 60<br />

7.14. ( Odd Behavior ) − When my Internet connection first<br />

comes up, nothing works. If I try again, everything then<br />

works fine. Why is this?<br />

Chapter 7. Frequently Asked Questions 125


<strong>The</strong> reason is because you have a dynamic <strong>IP</strong> address and when your Internet connection first comes up, <strong>IP</strong><br />

<strong>Masquerade</strong> doesn't know its <strong>IP</strong> address. <strong>The</strong>re is a solution to this. In your /etc/rc.d/rc.firewall−* ruleset, add<br />

the following:<br />

# Dynamic <strong>IP</strong> users:<br />

#<br />

# If you get your <strong>IP</strong> address dynamically from SL<strong>IP</strong>, PPP, or DHCP, enable this<br />

# following option. This enables dynamic−ip address hacking in <strong>IP</strong> MASQ, making<br />

# the life with Diald and similar programs much easier.<br />

#<br />

echo "1" > /proc/sys/net/ipv4/ip_dynaddr<br />

7.15. ( MTU ) − <strong>IP</strong> MASQ seems to be working fine but some<br />

sites don't work. This usually happens with WWW and some<br />

FTP sites.<br />

Depending on what <strong>Linux</strong> kernel version you are running on the MASQ server, some will people disagree on<br />

the real problem. <strong>The</strong> two following arguments have valid points, are inter−related, and users from each camp<br />

continue to debate this to this day.<br />

•<br />

With modern 2.4.x <strong>Linux</strong> systems, most users point their finger at the adminstrators of these remote<br />

broken sites (typically SSL−encrypted WWW sites, etc.) or your MASQ server's upstream router run<br />

by your ISP. <strong>The</strong> main though it that these machines are either filtering or not properly responding to<br />

SOME or ALL FORMS of ICMP packets (specifically ICMP Code 3 Type 4 − Fragmentation<br />

Needed) messages due to a fray of misplaced security paranoia.<br />

What does that all mean? Basically, say your machine is connected to the Internet with a MTU of<br />

1492 bytes (Maximum Transmission Unit −− the maximum packet size your computer can transmit)<br />

which is common for PPPoE users. At the same time, the remote WWW/FTP site is connected to the<br />

Internet at a MTU of 1500 bytes. <strong>The</strong> way that TCP/<strong>IP</strong> works is that when a TCP connection is being<br />

negotiated for your HTTP / FTP connection, the remote side will try to verify that a 1500 byte packet<br />

can reach your computer via the initial TCP "SYN" packet.<br />

Since the packet is too big for your connection, your upstream router (run by your ISP) will send a<br />

ICMP 3:4 (fragmentation needed) packet back to the remote WWW / FTP server. Within this packet<br />

is a recommended smaller MTU size to retry with. <strong>The</strong> problem is that either your local upstream<br />

router, some router between you and the remote server, or the remote HTTP / FTP server is either<br />

misconfigured or has a firewall in front of it that is BLOCKing these ICMP packets.<br />

• <strong>The</strong> final UNCOMMON possibility is a debatable 2.0 / 2.2 kernel bug in the <strong>IP</strong>MASQ code. Some<br />

users point their finger to the fact that <strong>IP</strong>MASQ might have problems with ICMP packets that have<br />

the DF or "Don't Fragment" bit set. Basically, when a MASQ box connects to the Internet with an<br />

MTU of anything less than 1500, some packets will have the DF field set. Though changing the MTU<br />

of the MASQ server's Internet link to 1500 seemingly fixes the problem, the possible bug is still there.<br />

What is believed to be happening in these older kernels is that the MASQ code is not properly<br />

re−writing the return <strong>IP</strong> addresses of the ICMP 3 Sub 4 code packets back to the originating MASQed<br />

computer. Because of this, these critical packets get dropped.<br />

No worries though. A there are several perfectly good ways to fix this nasty MTU problem:<br />

• Enable PMTU clamping in PPPoE<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 7. Frequently Asked Questions 126


•<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

This solution is mostly for modern 2.4.x and 2.2.x kernel users connected to the Internet via a PPPoE<br />

DSL or Cablemodem connections. This solution allows for changes to be done ONLY on the MASQ<br />

server itself and not on all of the internal MASQ clients.<br />

Enable PMTU clamping via <strong>IP</strong>TABLES<br />

This solution is only modern 2.4.x kernel users connected via ANY type of Internet connection. This<br />

solution allows for changes to be done ONLY on the MASQ server itself and not on all of the internal<br />

MASQ clients.<br />

• Change your MASQ server's Internet Link MTU<br />

This solution will work for any <strong>Linux</strong> kernel version but is is NOT a solution if you have a PPPoE<br />

connection for DSL or Cablemodem users.<br />

It should be noted that some users will balk at this solution because it can hurt some latency specific<br />

programs like TELNET and Internet games but the impact is only slight. On the other hand, most<br />

HTTP and FTP traffic will SPEED UP!<br />

• Change the MTU of all internal MASQed machines<br />

This solution requires the most work as you have to make minor changes to ALL of the internal<br />

<strong>IP</strong>MASQed machines. Basically, you would be changing the MTU on all of the internal machines to<br />

match the MTU of your MASQ server's Internet connection. Fortunately, this solution is usually<br />

bulletproof where as some of the other solutions mentioned in this section might rarely not work.<br />

7.15.1. Enabling PMTU Clamping for PPPoE and some PPP Users:<br />

For those users who use PPPoE clients for (DSL / Cablemodem) or PPP (Dialup), your Internet connection is<br />

NOT "eth0" (for example) but usually "ppp0". In addition to this, your Internet link's MTU or Maximum<br />

Transmission Unit (largest packet you can transmit over the Internet) isn't 1500 bytes but 1492. <strong>The</strong> 1492 byte<br />

MTU comes from the link size of Ethernet (1518 bytes) − Ethernet MAC overhead (18) = 1500. <strong>The</strong>n you<br />

subtract the PPPoE header (8 bytes) == MTU of 1492. This overhead isn't a big deal but sometimes ISPs or<br />

remote Internet sites do stupid things to break PPPoE or non−1500 byte MTU connected machines.<br />

You can find more info about this topic on the web. Specifically, here is good presentaion on the topic:<br />

mss−talk presentation (PDF). Here is the entire Write up and other good info<br />

To enable clamping in both the RP or PPPd PPPoE clients, add the following line to your /etc/ppp/pppoe.conf<br />

file:<br />

# − If you have a computer acting as a gateway for a LAN, choose "1412".<br />

# <strong>The</strong> setting of 1412 is safe for either setup, but uses slightly more<br />

# CPU power.<br />

#<br />

CLAMPMSS=1412<br />

7.15.2. Clamping the MSS via <strong>IP</strong>TABLES:<br />

As mentioned above for PPPoE users, some ISPs and WWW sites filter critical ICMP packets like MTU Path<br />

Discovery. Because of this, many users might find more Internet sites work but others hang or work poorly.<br />

Fortunately, recent <strong>IP</strong>TABLES have added PMTU Clamping support which should help you. If your using<br />

<strong>IP</strong>TABLES and think you're hitting this issue, try adding the following line to the end of your<br />

Chapter 7. Frequently Asked Questions 127


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

rc.firewall−iptables ruleset. It should be noted that there is no PMTU clamping support in <strong>IP</strong>CHAINS.<br />

iptables −I FORWARD −p tcp −−tcp−flags SYN,RST SYN −j TCPMSS −−clamp−mss−to−pmtu<br />

If this line causes an error when you re−run the rc.firewall−iptables* firewall rulesets, you might need to<br />

upgrade your version of <strong>IP</strong>TABLES which includes the "TCPMSS" <strong>IP</strong>TABLES module.<br />

7.15.3. Changing the External MTU of the MASQ server:<br />

This solution usually only applies to DIALUP users since PPPoE users cannot INCREASE their MTU<br />

because of PPPoE's header overhead.<br />

To use this solution, first see what your current MTU for your Internet link is. To do so, run "/bin/ifconfig" on<br />

the MASQ server. Look at the lines that corresponds to your Internet connection and look for the MTU (for<br />

example, ppp0). This NEEDs to be set to 1500. Usually, Ethernet links will default to 1500 for Ethernet but<br />

serial / DIALUP modem PPP links might default to 576.<br />

• To change the MTU on a standard Ethernet link to your bridged or routed DSL, Cablemodem, etc.<br />

connection, you need to edit the correct network startup scripts for your <strong>Linux</strong> distribution. Please see<br />

the TrinityOS − Section 16 document for network optimizations.<br />

• To change the MTU issue on a PPP (not PPPoE) Internet link, edit your "/etc/ppp/options" file and<br />

towards the top, add the following text on two seperate lines, add:<br />

mtu 1500<br />

mru 1500<br />

Save these new changes and then restart PPP. Like shown above, verify that your PPP link has the<br />

correct MTU and MTU.<br />

CUA Users: Lastly, though this isn't a common problem, some <strong>Linux</strong> 2.0.x kernel users have found a<br />

MTU solution to the following problem. With PPP users, verify what port is your PPPd code<br />

connecting to. Is it a /dev/cua* port or a /dev/ttyS* port? It NEEDS to be a /dev/ttyS* port as the<br />

/dev/cua* device ststem has been deprecated and it breaks some things in very odd ways.<br />

7.15.4. Changing the MTU of various operating systems:<br />

If you reconfigure ALL of your MASQed PCs to use the SAME MTU as your external Internet link's MTU<br />

(for example, 1492 for PPPoE users), everything should work fine and this method is sometimes the MOST<br />

EFFECTIVE way of fixing things. This is including ALL of the solutions mentioned above. But doing things<br />

this way can be a lot of work if there are lots of internal MASQed machines or be even impossible to do if you<br />

don't have administrative access to all the internal MASQed machines.<br />

Follow these simple steps for your respective operating system:<br />

<strong>The</strong> follow examples utilize an MTU of 1492 for typical PPPoE connections for some DSL and Cablemodem<br />

users. It is recommended to use the HIGHEST values possible for all connections that are 128Kb/s and faster.<br />

It should be noted that some PPPoE ISPs might require an MTU setting of 1460 (not 1492) for proper<br />

connectivity due to additional overhead in the ISP's internal network.<br />

<strong>The</strong> only real reason to use smaller MTUs than 1492 or 1460 is to lower your Internet link's latency but at the<br />

cost of throughput. Please see http://www.ecst.csuchico.edu/~dranch/PPP/ppp−performance.html#mtu for<br />

Chapter 7. Frequently Asked Questions 128


more details on this topic.<br />

If you know how to make similar changes like these to other OSes like OS/2, MacOS, etc. please email David<br />

Ranch so it can be included in the <strong>HOWTO</strong>.<br />

7.15.4.1. Changing the MTU on <strong>Linux</strong>:<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

1. <strong>The</strong> setting of MTU can vary from <strong>Linux</strong> distribution to distribution.<br />

For Redhat: You need to edit the various "ifconfig" statements in<br />

the /sbin/ifup script<br />

For Slackware: You need to edit the various "ifconfig" statements in<br />

the /etc/rc.d/rc1.inet<br />

2. Here is one good, any−distribution−will−work example, edit the<br />

/etc/rc.d/rc.local file and put the following at the END of the file:<br />

echo "Changing the MTU of ETH0"<br />

/sbin/ifconfig eth0 mtu 1492<br />

Replace "eth0" with the interface name that is the machine's upstream<br />

connection which is connected to the Internet.<br />

3. For advanced options like "TCP Receive Windows" and such, detailed examples<br />

on how to edit the respective networking scripts for your specific <strong>Linux</strong><br />

distro, etc., please see Chapter 16 of<br />

http://www.ecst.csuchico.edu/~dranch/LINUX/index−linux.html#trinityos<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

7.15.4.2. Changing the MTU on MS Windows 2000<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

1. Making ANY changes to the Registry is inheritantly risky but<br />

with a backup copy, you should be safe. Proceed at your<br />

OWN RISK.<br />

2. Goto Start−−>Run−−>RegEdit<br />

3. Registry−−>Export Registry File−−>Save a copy of your registry<br />

to a reliable place<br />

4. Navigate down to the key:<br />

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Inter<br />

faces\<br />

Each ID Adapter has default keys for DNS, TCP/<strong>IP</strong> address, Default Gateway,<br />

subnet mask, etc. Find the key one that is for your network card.<br />

5. Create the following Entry:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

type=DWORD<br />

name="MTU" (Do NOT include the quotes)<br />

value=1492 (Decimal) (Do NOT include the text "(Decimal)")<br />

http://support.microsoft.com/support/kb/articles/Q120/6/42.asp?LN=EN−US&SD=gn&FR=0<br />

Chapter 7. Frequently Asked Questions 129


*** If you know how to also change the MSS, TCP Window Size, and the<br />

*** TTL parameters in NT 2000, please email dranch@trinnet.net as I<br />

*** would love to add it to the <strong>HOWTO</strong>.<br />

5. Reboot to let the changes take effect.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

7.15.4.3. Changing the MTU on MS Windows NT 4.x<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

1. Making ANY changes to the Registry is inheritantly risky but<br />

with a backup copy, you should be safe. Proceed at your<br />

OWN RISK.<br />

2. Goto Start−−>Run−−>RegEdit<br />

3. Registry−−>Export Registry File−−>Save a copy of your registry<br />

to a reliable place<br />

4. Create the following keys in the Registry trees, choose two<br />

possible Registry trees. Multiple entries are for various<br />

network devices like DialUp Networking (ppp), Ethernet NICs,<br />

PPTP VPNs, etc.<br />

http://support.microsoft.com/support/kb/articles/Q102/9/73.asp?LN=EN−US&SD=gn&FR=0<br />

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Parameters\Tcpip]<br />

and<br />

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\\Parameters\Tcpip]<br />

Replace "" with the respective name of your uplink LAN NIC<br />

interface<br />

type=DWORD<br />

name="MTU" (Do NOT include the quotes)<br />

value=1492 (Decimal) (Do NOT include the text "(Decimal>")<br />

(Do NOT include the quotes)<br />

*** If you know how to also change the MSS, TCP Window Size, and the<br />

*** TTL parameters in NT 4.x, please email dranch@trinnet.net as I<br />

*** would love to add it to the <strong>HOWTO</strong>.<br />

5. Reboot to make the changes take effect.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

7.15.4.4. Changing the MTU on MS Windows 98:<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

1. Making ANY changes to the Registry is inheritantly risky but<br />

with a backup copy, you should be safe. Proceed at your OWN RISK.<br />

2. Goto Start−−>Run−−>RegEdit<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

3. You should make a backup copy of your Registry before doing anything. To<br />

do this, copy the "user.dat" and "system.dat" files from the \WINDOWS<br />

directory and put them into a safe place. It should be noted that the<br />

Chapter 7. Frequently Asked Questions 130


previously mentioned method of using "Regedit: Registry−−>Export Registry<br />

File−−>Save a copy of your registry" would only perform Registry MERGES<br />

and NOT do a replacement.<br />

4. Search though each of the Registry trees that end in "n" (e.g. 0007)<br />

and have a Registry entry called "<strong>IP</strong>Address" which has the <strong>IP</strong> address<br />

of your NIC. Under that key, add the following:<br />

From http://support.microsoft.com/support/kb/articles/q158/4/74.asp<br />

[Hkey_Local_Machine\System\CurrentControlset\Services\Class\NetTrans\000n]<br />

type=STRING<br />

name="MaxMTU" (Do NOT include the quotes)<br />

value=1492 (Decimal) (Do NOT include the text "(Decimal)")<br />

5. You can also change the "TCP Receive Window" which sometimes<br />

increases network performance SUBSTANTIALLY. If you notice your<br />

throughput has DECREASED, put these items BACK to their original<br />

settings and reboot.<br />

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP]<br />

type=STRING<br />

name="DefaultRcvWindow" (Do NOT include the quotes)<br />

value=32768 (Decimal) (Do NOT include the text "(Decimal>")<br />

type=STRING<br />

name="DefaultTTL" (Do NOT include the quotes)<br />

value=128 (Decimal) (Do NOT include the text "(Decimal>")<br />

6. Reboot to let the changes take effect.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

7.15.4.5. Changing the MTU on MS Windows 95:<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

1. Making ANY changes to the Registry is inheritantly risky but<br />

with a backup copy, you should be safe. Proceed at your OWN RISK.<br />

2. Goto Start−−>Run−−>RegEdit<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

3. You should make a backup copy of your Registry before continuing. To<br />

do this, copy the "user.dat" and "system.dat" files from the \WINDOWS<br />

directory and put them into a safe place. It should be noted that the<br />

previously mentioned method of using "Regedit: Registry−−>Export Registry<br />

File−−>Save a copy of your registry" would only do Registry MERGES and NOT<br />

do a replacement.<br />

4. Search through each of the Registry trees that end in "n" (e.g. 0007)<br />

and have a Registry entry called "<strong>IP</strong>Address", which has the <strong>IP</strong> address<br />

of your NIC. Under that key, add the following:<br />

From http://support.microsoft.com/support/kb/articles/q158/4/74.asp<br />

[Hkey_Local_Machine\System\CurrentControlset\Services\Class\NetTrans\000n]<br />

type=DWORD<br />

name="MaxMTU" (Do NOT include the quotes)<br />

value=1492 (Decimal) (Do NOT include the text "(Decimal)")<br />

Chapter 7. Frequently Asked Questions 131


type=DWORD<br />

name="MaxMSS" (Do NOT include the quotes)<br />

value=1450 (Decimal) (Do NOT include the text "(Decimal>")<br />

5. You can also change the "TCP Receive Window" which sometimes<br />

increases network performance SUBSTANTIALLY. If you notice your<br />

throughput has DECREASED, put these items BACK to their original<br />

settings and reboot.<br />

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP]<br />

type=DWORD<br />

name="DefaultRcvWindow" (Do NOT include the quotes)<br />

value=32768 (Decimal) (Do NOT include the text "(Decimal>")<br />

type=DWORD<br />

name="DefaultTTL" (Do NOT include the quotes)<br />

value=128 (Decimal) (Do NOT include the text "(Decimal>")<br />

6. Reboot to let the changes take effect.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

7.16. ( FTP ) − MASQed FTP clients don't work.<br />

Check to see that the "ip_masq_ftp" module is loaded. To do this, log into the MASQ server and run the<br />

command "/sbin/lsmod". If you don't see the "ip_masq_ftp" module loaded, make sure that you followed the<br />

BASIC /etc/rc.d/rc.firewall−* recommendations found in Section 3.4. If you are implementing your own<br />

ruleset, make sure you include most of the examples from the <strong>HOWTO</strong> or you will have many susequent<br />

problems.<br />

7.17. ( Performance ) − <strong>IP</strong> Masquerading seems slow<br />

<strong>The</strong>re might be a few reasons for this:<br />

•<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

You might be unrealistic about how much available bandwidth is on your modem line. Lets do the<br />

math for a typical 56k modem connection:<br />

1. 56k modems = 56,000 bits per second.<br />

2. You really DON'T have a 56k modem but a 52k modem per US FCC limitations.<br />

3. You'll almost NEVER get 52k, the best connection I used to get was 48k<br />

4. 48,000 bits per second is 4,800 BYTES per second (8 bits to a byte + 2 bits for the START<br />

and STOP RS−232 serial bits)<br />

5. With an MTU of 1500, you will get (3.2) packets in one second. Since this will involve<br />

fragmentation, you need to round DOWN to (3) packets per second.<br />

6. Again with MTU of 1500, thats 3.2 x 40 bytes of TCP/<strong>IP</strong> overhead (8%)<br />

7. So the BEST throughput you could hope for is 4.68KB/s w/o compression. Compression, be<br />

it v.42bis hardware compression, MNP5, or MS/Stac compression can yeild impressive<br />

numbers on highly compressable stuff like TEXT files, but acutally slow things down when<br />

transfering pre−compressed files like Z<strong>IP</strong>s, MP3s, etc.<br />

Ethernet attached setups (DSL, Cablemodem, LANs, etc)<br />

Chapter 7. Frequently Asked Questions 132


• Make sure you don't have both your INTERNAL and EXTERNAL networks running on the same<br />

network card with the "<strong>IP</strong> Alias" feature. If you ARE doing this, it can be made to work but it will be<br />

excessively slow due to high levels of collisions, IRQ usage, etc. It is highly recommended that you<br />

install another network card for the internal and external networks to have their own interface.<br />

• Make sure you have the right Ethernet settings for both SPEED and DUPLEX.<br />

• Some 10Mb/s Ethernet cards and most 100Mb/s cards support FULL Duplex connections. Direct<br />

connections from an Ethernet card to, say, a DSL modem (without any hubs in between) *CAN* be<br />

set to FULL DUPLEX but only if the DSL modem supports it. You should also be sure that you have<br />

Ethernet cables with all eight wires used and that they are in good condition.<br />

Internal networks that use HUBs −cannot− use Full Duplex. You need either a 10 or 100Mb.s<br />

Ethernet SWITCH to be able to do this.<br />

Both auto 10/100Mb/s SPEED negotiation and Full/Half DUPLEX negotiation on Ethernet cards can<br />

wreck havoc on networks. I recommend to hard code both the NIC speed and duplex into the NIC(s)<br />

if possible. This is directly possible via <strong>Linux</strong> NIC kernel modules but isn't directly possible in<br />

monolithic kernels. You will need to either use MII utililies from Section 8.1 or hardcode the kernel<br />

source.<br />

Optimize your MTU and set the TCP Sliding window to at least 8192<br />

• Though this is COMPLETELY out of the scope of this document, this helps QUITE A BIT with ANY<br />

network link you have, be it an internal or external PPP, Ethernet, TokenRing, etc. link. For more<br />

details, this topic is briefly touched in an above section in Section 7.15. For even more details, check<br />

out the Network Optimization section of TrinityOS − Section 16.<br />

Serial based modem users with PPP<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• If you have an external modem, make sure you have a good serial cable. Also, many PCs have cheesy<br />

ribbon cables connecting the serial port from the motherboard or I/O card to the serial port<br />

connection. If you have one of these, make sure it is in good condition. Personally, I have ferrite coils<br />

(those grey−black metal like rings) around ALL of my ribbon cables.<br />

• Make sure your MTU is set to 1500 as described in the FAQ section of this <strong>HOWTO</strong> above<br />

• Make sure that your serial port is a 16550A or better UART. Run "dmesg | more" to verify<br />

• Setup IRQ−Tune for your serial ports.<br />

On most PC hardware, the use of Craig Estey's IRQTUNE tool and significantly increase serial port<br />

performance including SL<strong>IP</strong> and PPP connections.<br />

• Make sure that your serial port for your PPP connection is running at 115200 (or faster if both your<br />

modem and serial port can handle it.. a.k.a ISDN terminal adapters)<br />

♦ 2.0.x kernels: <strong>The</strong> 2.0.x kernels are kind of an odd ball because you can't directly tell the<br />

kernel to clock the serial ports at 115200. So, in one of your startup scripts like the<br />

/etc/rc.d/rc.local or /etc/rc.d/rc.serial file, execute the following commands for a modem on<br />

COM2:<br />

♦ setserial /dev/ttyS1 spd_vhi<br />

♦ In your PPPd script, edit the actual pppd execution line to include the speed "38400" per the<br />

pppd man page.<br />

♦ 2.2.x kernels: Unlike the 2.0.x kernels, both the 2.1.x and 2.2.x kernels don't have this<br />

"spd_vhi" issue.<br />

Chapter 7. Frequently Asked Questions 133


All interface types:<br />

So, in your PPPd script, edit the actual pppd execution line to include the speed "115200" per<br />

the pppd man page.<br />

7.18. ( PORTFW ) − <strong>IP</strong> Masquerading with PORTFWing<br />

seems to break when my line is idle for long periods<br />

If you have a DSL or Cablemodem, this behavior is unfortunately quite common. Basically your ISP is<br />

putting your connection into a very low priority queue to better service non−idle connections. <strong>The</strong> problem is<br />

that some enduser's connections will actually be taken OFFLINE until some traffic from the user's<br />

DSL/Cablemodem connection awakens the ISP's hardware.<br />

• Some DSL installations can take an idle connection OFFLINE and only be checked for activity once<br />

every 30 seconds or so.<br />

• Some Cablemodem setups can set an idle connection into a low priority queue and only be checked<br />

for activity every minute or so.<br />

What do I recommend to do? Ping your default gateway every 30 seconds. To do this, edit the<br />

/etc/rc.d/rc.local file and add the following to the bottom of the file:<br />

ping −i 30 100.200.212.121 > /dev/null &<br />

Replace the 100.200.212.121 with your default router (upstream router).<br />

7.19. ( PORTFW − Locally ) − I can't reach my PORTFWed<br />

server from the INTERNAL lan<br />

Basically, say your domain, acme.com, has an external <strong>IP</strong> address of 1.2.3.4 and you are PORTFWing all<br />

WWW traffic to an internal machine, say, 192.168.0.20/24. <strong>The</strong>n an /internal/ user on the 192.169.0.x<br />

network tries to contact to http://www.acme.com and expects things to work. Well, that isn't going to happen<br />

with a basic config. Let me explain. Basically, http://www.acme.com is being resolved to the <strong>IP</strong> of<br />

http://1.2.3.4 by your chosen DNS server. What really should be happening is the web request should resolve<br />

that request to http://192.168.0.20.<br />

See the difference?<br />

<strong>The</strong> proper solution to this is to setup a SPLIT DNS server. Internal users would be configured to use an<br />

/internal/ DNS server which would resolve requests like this with the 192.168.0.20 address when asked for<br />

www.acme.com. All external users should be serviced by an /external/ DNS server which will will resolve the<br />

requrest to the 1.2.3.4 <strong>IP</strong> address. From there, <strong>IP</strong>TABLES/<strong>IP</strong>CHAINS/<strong>IP</strong>FWADM would then PORTFW the<br />

traffic to the 192.168.0.20 server as normal.<br />

But you're probably thinking that you don't want to setup a split DNS server and there has to be another way.<br />

<strong>The</strong>re are a few alternatives! <strong>The</strong> first alternative is if you only have a few internal machines. Here, you can<br />

setup a "hosts" file entry on *all* internal machines. That static hosts entry would basically look like:<br />

www.acme.com 192.168.0.20<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 7. Frequently Asked Questions 134


Got it? With that in place, the machine would consult the hosts table before going to the DNS server to<br />

resolve the host. This works well but if you change the <strong>IP</strong> address on that internal web server, you're going to<br />

need to manually update the hosts file on all of those internal machines. If you are interested in doing the<br />

more scalable split DNS approach, TrinityOS completely covers split and chrooted DNS servers. TrinityOS −<br />

Section 24 http://www.ecst.csuchico.edu/~dranch/LINUX/index−linux.html#trinityos<br />

Now, if neither the split DNS nor the hosts file approach interests you, you still have a simple but effective<br />

alternative to get things working. What you can do is add some specific rules to your rc.firewall−* ruleset.<br />

Please see the "PORTFW Redirection of Internal requests" section under the Section 6.7 chapter.<br />

Why didn't I mention this alternative solution first? <strong>The</strong> main reason is that it's not the ideal solution. <strong>The</strong><br />

primary problem with this approach is that every packet will be going from the internal MASQed client to the<br />

MASQ server. <strong>The</strong>re, the MASQ server will SNAT each packet to the internal MASQed WWW server's <strong>IP</strong><br />

and then forward it to the internal web server. Once the packet is received and responded to by the web server,<br />

that response has to go back through all that processing back to the original client machine. This process is<br />

overly wasteful on both network bandwidth and MASQ server CPU cycles!<br />

7.20. ( Logs ) − Now that I have <strong>IP</strong> Masquerading up, I'm<br />

getting all sorts of weird notices and errors in the SYSLOG<br />

log files. How do I read the <strong>IP</strong>TABLES/<strong>IP</strong>CHAINS/<strong>IP</strong>FWADM<br />

firewall errors?<br />

<strong>The</strong>re is probably a few common things that you are going to see:<br />

•<br />

MASQ: Failed TCP Checksum error: You might see this error when a packet coming from the<br />

Internet gets corrupt in the data section of the packet but the rest of it "seems" ok. When the <strong>Linux</strong><br />

box receives this packet, it will calculate the CRC of the packet and determine that its corrupt. On<br />

most machines running OSes like Microsoft Windows, they just silently drop the packets but <strong>Linux</strong> <strong>IP</strong><br />

MASQ reports it. If you get a LOT of them over your PPP link, first follow the FAQ entry above for<br />

"(Performance) − Masq seems is slow".<br />

If the (Performance) FAQ tips don't help and you run PPP over dialup or PPPoE, you might try<br />

adding the line "−vj" (disabled VanJacobson header compression) to your /etc/ppp/options file and<br />

restart the PPPd connection.<br />

• Firewall hits: Because you are on the Internet with a decent firewall, you will be surprised with the<br />

number of users trying to penetrate your <strong>Linux</strong> box! So what do all these firewall logs mean?<br />

More so, if they are filling your logs, see the next FAQ entry on thoughts how to reduce all these log<br />

entries.<br />

• <strong>The</strong> following details are from the TrinityOS − Section 10 documentation I also wrote:<br />

With the use of various firewall rulesets, a given ruleset can either<br />

DENY (silently drop) or REJECT traffic (sends back a ICMP error). If<br />

firewall logging is enabled, the errors will show up in the SYSLOG<br />

"messages" file found at:<br />

Redhat: /var/log<br />

Slackware: /var/adm<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

If you take a look at one of these firewall logs, you would see something<br />

Chapter 7. Frequently Asked Questions 135


like:<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

<strong>IP</strong>TABLES:<br />

−−−−−−−−−<br />

Feb 23 07:37:01 Roadrunner kernel: <strong>IP</strong>TABLES IN=eth0 OUT=<br />

MAC=00:50:da:2e:e5:fb:00:03:47:73:c9:d2:08:00 SRC=12.75.147.174<br />

DST=100.200.0.212 LEN=44 TOS=0x00 PREC=0x00 TTL=64 ID=39034 DF PROTO=TCP<br />

SPT=4313 DPT=23 WINDOW=32120 RES=0x00 SYN URGP=0<br />

<strong>IP</strong>CHAINS:<br />

−−−−−−−−−<br />

Feb 23 07:37:01 Roadrunner kernel: input REJECT eth0 PROTO=6<br />

12.75.147.174:1633 100.200.0.212:23 L=44 S=0x00 I=54054 F=0x0040 T=64<br />

<strong>IP</strong>FWADM:<br />

−−−−−−−−<br />

Feb 23 07:37:01 Roadrunner kernel: <strong>IP</strong> fw−in rej eth0 TCP 12.75.147.174:1633<br />

100.200.0.212:23 L=44 S=0x00 I=54054 F=0x0040 T=64<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

<strong>The</strong>re is a LOT of information in just this one line of SYSLOG. Lets break<br />

out this example. You should refer back to the original firewall hit as you<br />

read this.<br />

−−−−−−−−−−−−−−<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

1. ===================================================================<br />

− This packet firewall "hit" occurred on "Feb 23 07:37:01"<br />

2. ===================================================================<br />

− This packet was logged on the "RoadRunner" computer via the kernel<br />

3. ===================================================================<br />

− <strong>IP</strong>TABLES: the SYSLOG prepend string is "iptables" for information purposes<br />

− <strong>IP</strong>CHAINS: the packet was stopped on the INPUT chain<br />

− <strong>IP</strong>FWADM: the packet was an <strong>IP</strong> packet<br />

4. ===================================================================<br />

− <strong>IP</strong>TABLES: the packet came IN on interface "eth0"<br />

− <strong>IP</strong>CHAINS: the packet was REJECTED (vs. dropped or accepted)<br />

− <strong>IP</strong>FWADM: the packet was stopped on INPUT (vs. "fw−out" for OUT or<br />

"fw−fwd" for FORWARD)<br />

5. ===================================================================<br />

− <strong>IP</strong>TABLES: the packet had NO output interface<br />

− <strong>IP</strong>CHAINS: the packet came in on the "eth0" interface<br />

− <strong>IP</strong>FWADM: the packet was REJECTED "rej" (vs. "deny" or "accept")<br />

Chapter 7. Frequently Asked Questions 136


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

6. ===================================================================<br />

− <strong>IP</strong>TABLES: this display's the MAC address of the source and destination<br />

Ethetnet MAC address (only relivant for Ethernet networks)<br />

− <strong>IP</strong>CHAINS: the packet was <strong>IP</strong> protocol 6 or TCP<br />

* If you don't know that protocol 6 is for TCP, look at<br />

your /etc/protocols file to see what other protocol numbers<br />

are used for.<br />

− <strong>IP</strong>FWADM: the packet on the "eth0" interface<br />

7. ===================================================================<br />

− <strong>IP</strong>TABLES: the packet's source <strong>IP</strong> address was 12.75.147.174<br />

− <strong>IP</strong>CHAINS: the packet's source <strong>IP</strong> address was 12.75.147.174<br />

− <strong>IP</strong>FWADM: the packet was a "TCP" packet<br />

8. ===================================================================<br />

− <strong>IP</strong>TABLES: the packet's destination <strong>IP</strong> address was 100.200.0.212<br />

− <strong>IP</strong>CHAINS: the packet's source PORT was 1633<br />

− <strong>IP</strong>FWADM: the packet's source <strong>IP</strong> address was 12.75.147.174<br />

9. ===================================================================<br />

− <strong>IP</strong>TABLES: the packet's length was 44 bytes<br />

− <strong>IP</strong>CHAINS: the packet's destination <strong>IP</strong> address was 100.200.0.212<br />

− <strong>IP</strong>FWADM: the packet's source PORT was 1633<br />

10. ===================================================================<br />

− <strong>IP</strong>TABLES: the packet's TOS markings (type of service which basically<br />

means class of service) was 0x00 or zero.<br />

− <strong>IP</strong>CHAINS: the packet's destination PORT was 23 (telnet)<br />

* If you don't know that port 23 is for TELNETing, look at<br />

your /etc/services file to see what other ports are used<br />

for.<br />

− <strong>IP</strong>FWADM: the packet's destination <strong>IP</strong> address was 100.200.0.212<br />

11. ===================================================================<br />

− <strong>IP</strong>TABLES: the packet's precedense markings (class of service) was<br />

0x00 or zero.<br />

− <strong>IP</strong>CHAINS: the packet's length was 44 bytes<br />

− <strong>IP</strong>FWADM: the packet's destination PORT was 23 (telnet)<br />

* If you don't know that port 23 is for TELNETing, look at<br />

your /etc/services file to see what other ports are used<br />

for.<br />

12. ==================================================================<br />

Chapter 7. Frequently Asked Questions 137


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

− <strong>IP</strong>TABLES: the packet's TTL or Time to Live was 64 or 64 router hops<br />

* Every router hop over the Internet will subtract (1) from<br />

this number. Usually, packets will start with a number of<br />

255 (depends on the operating system) and if that number<br />

ever reaches (0), it means that realistically, the packet<br />

was lost in a network loop and should be deleted.<br />

− <strong>IP</strong>CHAINS: the packet's TOS markings (type of service which basically<br />

means class of service) was 0x00 or zero.<br />

* divide this by 4 to get the Type of Service (presidence)<br />

− <strong>IP</strong>FWADM: the packet was 44 bytes long<br />

13. ==================================================================<br />

− <strong>IP</strong>TABLES: the packet had various TCP flags set such as SYN, SYN+ACK,<br />

etc. (shown in HEX)<br />

− <strong>IP</strong>CHAINS: the packet had various TCP flags set (shown in hex)<br />

− <strong>IP</strong>FWADM: the packet's TOS markings (type of service which basically<br />

means class of service) was 0x00 or zero.<br />

14. ==================================================================<br />

− <strong>IP</strong>TABLES: the packet's "don't fragment" or DF bit was set from the<br />

source computer<br />

− <strong>IP</strong>CHAINS: the packet had a fragmentation offset of 40 (shown in HEX)<br />

−−Don't worry if you don't understand this..<br />

* A value that started with "0x2..." or "0x3..." means the<br />

"More Fragments" bit was set so more fragmented packets<br />

will be coming in to complete this one BIG packet.<br />

* A value which started with "0x4..." or "0x5..." means that<br />

the "Don't Fragment" bit was set<br />

* Any other values are the Fragment offset (divided by 8) to<br />

be later used to recombine into the original LARGE packet<br />

− <strong>IP</strong>FWADM: the packet had various TCP flags set such as SYN, SYN+ACK,<br />

etc. (shown in HEX)<br />

15. ==================================================================<br />

− <strong>IP</strong>TABLES: the packet was a TCP packet<br />

− <strong>IP</strong>CHAINS: the packet's TTL or Time to Live was 64 or 64 router hops<br />

* Every router hop over the Internet will subtract (1) from<br />

this number. Usually, packets will start with a number of<br />

255 (depends on the operating system) and if that number<br />

ever reaches (0), it means that realistically, the packet<br />

was lost in a network loop and should be deleted.<br />

− <strong>IP</strong>FWADM: the packet had a fragmentation offset of 40 (shown in HEX)<br />

−−Don't worry if you don't understand this..<br />

* A value that started with "0x2..." or "0x3..." means the<br />

"More Fragments" bit was set so more fragmented packets<br />

will be coming in to complete this one BIG packet.<br />

* A value which started with "0x4..." or "0x5..." means that<br />

the "Don't Fragment" bit was set<br />

Chapter 7. Frequently Asked Questions 138


* Any other values are the Fragment offset (divided by 8) to<br />

be later used to recombine into the original LARGE packet<br />

16. ==================================================================<br />

− <strong>IP</strong>TABLES: the packet's soure PORT was 4313<br />

− <strong>IP</strong>CHAINS:<br />

− <strong>IP</strong>FWADM: the packet's TTL or Time to Live was 64 or 64 router hops<br />

* Every router hop over the Internet will subtract (1) from<br />

this number. Usually, packets will start with a number of<br />

255 (depends on the operating system) and if that number<br />

ever reaches (0), it means that realistically, the packet<br />

was lost in a network loop and should be deleted.<br />

17. ==================================================================<br />

− <strong>IP</strong>TABLES: the packet's destination PORT was 23 (telnet)<br />

* If you don't know that port 23 is for TELNETing, look at<br />

your /etc/services file to see what other ports are used<br />

for.<br />

− <strong>IP</strong>CHAINS:<br />

− <strong>IP</strong>FWADM:<br />

18. ==================================================================<br />

− <strong>IP</strong>TABLES: the packet's TCP window (sliding or selective TCP ack)<br />

was 32120 bytes<br />

− <strong>IP</strong>CHAINS:<br />

− <strong>IP</strong>FWADM:<br />

19. ==================================================================<br />

− <strong>IP</strong>TABLES: the packet's TCP reserved bits were 0x00 (HEX) − unused<br />

− <strong>IP</strong>CHAINS:<br />

− <strong>IP</strong>FWADM:<br />

20. ==================================================================<br />

− <strong>IP</strong>TABLES: the packet's TCP header SYN bit was set<br />

* <strong>IP</strong>TABLES displays all the TCP header bits by name and not<br />

by a HEX dump<br />

− <strong>IP</strong>CHAINS:<br />

− <strong>IP</strong>FWADM:<br />

21. ==================================================================<br />

− <strong>IP</strong>TABLES: the packet's TCP header URGENT bit was set − rarely used<br />

− <strong>IP</strong>CHAINS:<br />

− <strong>IP</strong>FWADM:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 7. Frequently Asked Questions 139


7.21. ( Log Reduction ) − My logs are filling up with packet<br />

hits due to the new "stronger" rulesets. How can I fix this?<br />

So your realizing that a good firewall is catching a LOT of bad Internet traffic. That's a good thing but it's also<br />

filling up your logs to the point that you won't read them; that's bad. What to do?<br />

What you need to figure out is what traffic you DON"T want to log, explicitly match those packets in the<br />

firewall, and NOT log the packets when you drop them.<br />

For example, the TrinityOS firewall ruleset in section 10.7 (this would be a "strongest" ruleset in <strong>IP</strong>MASQ<br />

speak) gives some ideas: TrinityOS − Section 10.7<br />

Things I recommend to filter:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• All RFC1918 address space (TCP/<strong>IP</strong> address ranges: 10.x.y.z/8, 172.16−31.y.z/12, and<br />

192.168.y.x/16). You should /never/ receive these packets from an Internet connection. If you do, they<br />

are most likely spoofed packets<br />

• Windows File and Print Sharing (Samba or CIFS): ports 137, 138, 139, and 445. Windows machines<br />

like to talk a lot though most computers don't care what they're saying.<br />

• Class−D Multicast addresses (if you don't use Multicast): 224.0.0.0/4<br />

• Class−E and F "future" addresses: 240.0.0.0/5 and 248.0.0.0/5<br />

To a much lesser extent, you might want to filter other packets. I recommend that you verify that you are<br />

receiving these specific packet types before you filter them out.<br />

• R<strong>IP</strong> (the routing protocol): port 520<br />

• Some specific forms of ICMP packets − NOT all of them (that will break your machine and <strong>IP</strong>MASQ<br />

in general)<br />

Finally, you'll probably find that some individual TCP/<strong>IP</strong> address out on the Internet always seem to attack<br />

your <strong>IP</strong>. So, in addition to filtering various PORTS like above, you might want to also filter by specific<br />

SOURCE <strong>IP</strong> address too. After all, it is *YOUR* firewall.<br />

7.22. ( MASQ Security ) − Can I configure <strong>IP</strong> MASQ to allow<br />

Internet users to directly contact internal MASQed servers?<br />

Yes! With <strong>IP</strong>PORTFW, you can allow ALL or only a select few Internet hosts to contact ANY of your<br />

internal MASQed computers. This topic is completely covered in Section 6.7 in this <strong>HOWTO</strong>.<br />

7.23. ( Free Ports ) − I'm getting "kernel:<br />

ip_masq_new(proto=UDP): no free ports." in my SYSLOG<br />

files. Whats up?<br />

One of your internal MASQed machines are creating an abnormally high number of packets destined for the<br />

Internet. As the <strong>IP</strong> Masq server builds the MASQ table and forwards these packets out over the Internet, the<br />

Chapter 7. Frequently Asked Questions 140


table is quickly filling. Once the table is filled, it will give you this error.<br />

<strong>The</strong> only application that I have known which temporarily creates this situation is a gaming program called<br />

"GameSpy". Why? Gamespy builds a server list and then pings all of the servers in the list (1000s of game<br />

servers). By creating all these pings, it creates 1,000s of quick connections in a VERY short period of time.<br />

Until these sessions timeout via the <strong>IP</strong> MASQ timeouts, the MASQ tables become "FULL".<br />

So what can you do about it? Realistically, don't use programs that do things like this. If you do get this error<br />

in your logs, find it and stop using it. If you really like GameSpy, just don't refresh the server too often.<br />

Regardless, once you stop running this MASQ'ed program, this MASQ error will go away as these<br />

connections will eventually timeout in the MASQ tables.<br />

7.24. ( SETSOCKOPT ) − I'm getting "ipfwadm: setsockopt<br />

failed: Protocol not available" when I try to use <strong>IP</strong>PORTFW!<br />

If you get the error message "ipfwadm: setsockopt failed: Protocol not available", you AREN'T running your<br />

new kernel. Make sure that you moved the new kernel over, re−run LILO, and then reboot again.<br />

Please see the end of Section 6.7 for full details.<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

7.25. ( SAMBA ) − Microsoft File and Print Sharing and<br />

Microsoft Domain clients don't work through <strong>IP</strong> Masq!<br />

To properly support Microsoft's SMB protocol, an <strong>IP</strong> Masq module would need to be written but there are<br />

three viable work−arounds. For more details, please see this Microsoft KnowledgeBase article.<br />

<strong>The</strong> first way to work around this problem is to configure <strong>IP</strong>PORTFW from Section 6.7 and portfw TCP ports<br />

137, 138, and 139 to the internal Windows machine's <strong>IP</strong> address. Though this solution works, it would only<br />

work for ONE internal machine.<br />

<strong>The</strong> second solution is to install and configure Samba on the <strong>Linux</strong> MASQ server. With Samba running, you<br />

can then map your internal Windows File and Print shares onto the Samba server. <strong>The</strong>n, you can mount these<br />

newly mounted SMB shares to all of your external clients. Configuring Samba is fully covered in a <strong>HOWTO</strong><br />

found in a <strong>Linux</strong> <strong>Documentation</strong> <strong>Project</strong> and in the TrinityOS document as well.<br />

<strong>The</strong> third solution is to configure a VPN (virtual private network) between the two Windows machines or<br />

between the two networks. This can either be done via the PPTP or <strong>IP</strong>SEC VPN solutions. <strong>The</strong>re is a Section<br />

7.35 patch for <strong>Linux</strong> and also a full <strong>IP</strong>SEC implementation available for both 2.0.x and 2.2.x kernels. This<br />

solution would probably be the most reliable and secure method of all three solutions.<br />

All of these solutions are NOT covered by this <strong>HOWTO</strong>. I recommend that you look at the TrinityOS<br />

documentation for <strong>IP</strong>SEC help and John Hardin's PPTP page for more information.<br />

Also PLEASE understand that Microsoft's SMB protocol is VERY insecure. Because of this, running<br />

either Microsoft File and Print sharing or Windows Domain login traffic over the Internet without any<br />

encryption is a VERY BAD idea.<br />

Chapter 7. Frequently Asked Questions 141


7.26. ( IDENT ) − IRC won't work properly for MASQed IRC<br />

users. Why?<br />

<strong>The</strong> main possible reason is because most common <strong>Linux</strong> distribution's IDENT or "Identity" servers can't deal<br />

with <strong>IP</strong> <strong>Masquerade</strong>d links. No worries though, there are IDENTs out there that will work.<br />

Installing this software is beyond the scope of this <strong>HOWTO</strong> but each tool has its own documentation. Here<br />

are some of the URLs:<br />

• Oident is a favorite IDENT server for MASQ users.<br />

• Mident is another popular IDENT server.<br />

• Sident<br />

• Other Idents<br />

Please note that some Internet IRC servers still won't allow multiple connections from the same host even if<br />

they get Ident info and the users are different though. Complain to the remote sys admin. :−)<br />

7.27. ( IRC DCC ) − mIRC doesn't work with DCC Sends<br />

This is a configuration problem on your copy of mIRC. To fix this, first disconnect mIRC from the IRC<br />

server. Now in mIRC, go to File −−> Setup and click on the "IRC servers tab". Make sure that it is set to port<br />

6667. If you require other ports, see below. Next, goto File −−> Setup −−> Local Info and clear the fields for<br />

Local Host and <strong>IP</strong> Addresses. Now select the checkboxes for "LOCAL HOST" and "<strong>IP</strong> address" (<strong>IP</strong> address<br />

may be checked but disabled). Next under "Lookup Method", configure it for "normal". It will NOT work if<br />

"server" is selected. That's it. Try to the IRC server again.<br />

If you require IRC server ports other than 6667, (for example, 6969) you need to edit the<br />

/etc/rc.d/rc.firewall−* startup file where you load the IRC MASQ modules. Edit this file and the line for<br />

"modprobe ip_masq_irc" and add to this line "ports=6667,6969". You can add additional ports as long as they<br />

are separated with commas.<br />

Finally, close down any IRC clients on any MASQed machines and re−load the IRC MASQ module:<br />

/sbin/rmmod ip_masq_irc /etc/rc.d/rc.firewall−*<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

7.28. ( <strong>IP</strong> Aliasing ) − Can <strong>IP</strong> <strong>Masquerade</strong> work with only<br />

ONE Ethernet network card?<br />

Yes and no. With the "<strong>IP</strong> Alias" kernel feature, users can setup multiple aliased interfaces such as eth0:1,<br />

eth0:2, etc but its is NOT recommended to use aliased interfaces for <strong>IP</strong> Masquerading. Why? Providing a<br />

secure firewall becomes very difficult with a single NIC card. In addition to this, you will experience an<br />

abnormal amount of errors on this link since incoming packets will almost simultaneously be sent out at the<br />

same time. Because of all this and NIC cards now costs less than $10, I highly recommend to just get a NIC<br />

card for each MASQed network segment.<br />

Users should also understand that <strong>IP</strong> Masquerading will only work with a physical interface such as eth0,<br />

eth1, etc. MASQing out an aliased interface such as "eth0:1, eth1:1, etc" will NOT work. In other words, the<br />

following WILL NOT WORK reliably:<br />

Chapter 7. Frequently Asked Questions 142


• It is rumored that you can simply use the destination <strong>IP</strong> address (the <strong>IP</strong> address associated with the<br />

ALIASed interface like eth0:1, etc.) IN PLACE of specifing the interface (eth0:1). This solution is not<br />

untested −− please email dranch@trinnet.net if you have any positive or negative results<br />

• /sbin/ipchains −A forward −i eth0:1 −s 192.168.0.0/24 −j MASQ"<br />

• /sbin/ipfwadm −F −a m −W eth0:1 −S 192.168.0.0/24 −D 0.0.0.0/0<br />

If you are still interested in using aliased interfaces, you need to enable the "<strong>IP</strong> Alias" feature in the kernel.<br />

You will then need to re−compile and reboot. Once running the new kernel, you need to configure <strong>Linux</strong> to<br />

use the new interface (i.e. eth0:1, etc.). After that, you can treat it as a normal Ethernet interface with some<br />

restrictions like the one above.<br />

7.29. ( Multiple−LANs ) − I have two MASQed LANs but they<br />

cannot communicate with each other!<br />

Please see Section 6.5 for full details.<br />

7.30. ( SHAPING ) − I want to be able to limit the speed of<br />

specific types of traffic<br />

I receive lots of emails from people asking something like the following:<br />

How can I control the internet bandwidth among the LAN PCs behind the <strong>IP</strong>MASQ<br />

server? Some times any local pc is downloading and it it will take the majority<br />

of the bandwidth and thus the other PCs get little bandwidth.<br />

This topic really doesn't have anything to do with <strong>IP</strong>MASQ and everthing to do with <strong>Linux</strong>'s built−in traffic<br />

shaping and rate−limiting abilities. You will find information about this on the LDP such as the ADSL<br />

Bandwidth <strong>HOWTO</strong>, the Advanced Rouring <strong>HOWTO</strong>, and the Bandwidth Limiting <strong>HOWTO</strong>. Please<br />

understand this is an advanced topic and any question you may have will be better served from people from<br />

those forums.<br />

7.31. ( ACCOUNTING ) − I need to do accounting on who is<br />

using the network<br />

Though this doesn't have much to do with <strong>IP</strong>MASQ, here are a few ideas. If you know of a better solution,<br />

please email the author of this <strong>HOWTO</strong> so it can be added to the <strong>HOWTO</strong>.<br />

•<br />

Idea #1: You could run the command:<br />

<strong>IP</strong>CHAINS: "ipchains −L −M"<br />

<strong>IP</strong>TABLES: "cat /proc/net/ip_conntrack"<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

<strong>IP</strong>FWADM:<br />

once a second and log all of those entries. You could then write a program to merge this information<br />

into one large file. Again, this will only provide you with the remote <strong>IP</strong> address and nothing about the<br />

content viewed or downloaded.<br />

• Idea #2: Log every packet: You can match any specific traffic flows but this method will create<br />

VERY LARGE log files. Unfortunately, these log files aren't very readable and it doesn't tell you<br />

what was transfered (FTP files, etc.). Fortunately, setting up this form of accounting is easy.<br />

Chapter 7. Frequently Asked Questions 143


• Idea #3: Say you want to log all traffic going out onto the internet. You can setup a firewall rule to<br />

accept port 80 traffic with with the SYN bit set and log it. Now mind you, this will create smaller log<br />

files than the idea above but you will only know the destination <strong>IP</strong> address and NOT the WWW pages<br />

viewed.<br />

• Idea #4: Transparent Proxy: This method really doesn't use <strong>IP</strong>MASQ since it requires the installation<br />

and setup of the Squid HTTP/FTP proxy server. <strong>The</strong> benefit of this method is that internal users won't<br />

notice anything different in terms of connectivity but now the SysAdmin gets a LOT more<br />

information (files downloaded, etc). But, there are pros/cons to setting this up:<br />

Pro:<br />

♦ + full logging of all transferred files and issues FTP commands<br />

♦ + you can enable caching on the proxy server. With caching, you can save bandwidth since<br />

once a file is downloaded, any identical file requests will be served via the cache and not<br />

redownloaded via the Internet connection.<br />

Con:<br />

♦ − Setting up a transparent proxy is complicated as it requires kernel changes, setting up<br />

Squid, etc.<br />

♦ − Could be overkill for a small installation.<br />

Please see the Advanced Routing <strong>HOWTO</strong> for more details.<br />

7.32. ( MULT<strong>IP</strong>LE <strong>IP</strong>s − DMZ segments) − I have several<br />

EXTERNAL <strong>IP</strong> addresses that I want to PORTFW to several<br />

internal machines. How do I do this?<br />

Though technically possible, DON'T do this with <strong>IP</strong> MASQ. <strong>The</strong>re are far better solutions for this network<br />

design.<br />

MASQ is a 1:Many NAT setup which is the incorrect tool to perform what you are looking for. You are<br />

looking for is either Many:Many NAT solution or a Briding setup.<br />

NOTE: For users out there who are thinking about enabling multiple <strong>IP</strong> addresses on one internal NIC using<br />

"<strong>IP</strong> Alias" and then just PORTFWeding ALL of those ports (0−65535), and and finally use <strong>IP</strong>ROUTE2 to<br />

maintain the proper source/destination <strong>IP</strong> pairs. This has been done SUCCESSFULLY on 2.0.x kernels and<br />

less successfully on 2.2.x kernels. Regardless of success, that isn't the proper way to do it, it's a total HACK,<br />

and it is not a supported MASQ configuration. Please, give <strong>IP</strong>TABLES on the 2.4.x kernels a serious look or<br />

to a much lesser extent, Section 7.30 <strong>IP</strong>ROUTE2 look for 2.2.x kernels.<br />

Anyway, for forwarding external <strong>IP</strong> address to internal hosts, you basically have three possibilites:<br />

• 1. Route the external <strong>IP</strong>s<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

(This does NOT involve <strong>IP</strong>MASQ at all but requires special WAN addressing<br />

and routing setup from your ISP):<br />

Internet −− Some public WAN −− <strong>Linux</strong> −− DMZ segment<br />

<strong>IP</strong> address Server PUBLIC <strong>IP</strong>s<br />

|<br />

+−−−−−− Internal net<br />

private <strong>IP</strong>s<br />

Chapter 7. Frequently Asked Questions 144


• 2. 1:1 NAT<br />

(Most easily done via <strong>IP</strong>TABLES or with <strong>IP</strong>CHAINS and <strong>IP</strong>ROUTE2 but still<br />

some protocols cannot deal with NAT)<br />

Internet −− <strong>Linux</strong> −− DMZ segment<br />

Server Private <strong>IP</strong>s natted to 1:1 PUBLIC <strong>IP</strong>s<br />

|<br />

+−−−−−− Internal net<br />

private <strong>IP</strong>s<br />

• 3. Bridging or ProxyARP:<br />

<strong>The</strong> Bridging method is one of the more popular methods that many commercial<br />

firewalls do and it's very slick. Alternatively, you can use the ProxyARP<br />

method which works well without some of the complications (or benefits of<br />

bridging). With both solutions, all public <strong>IP</strong>s can transparently flow<br />

through the <strong>Linux</strong> server to the DMZ but via firewall inspection.<br />

Internet −− <strong>Linux</strong> −− DMZ segment<br />

Server PUBLIC <strong>IP</strong>s<br />

|<br />

+−−−−−− Internal net<br />

private <strong>IP</strong>s<br />

Each of these solutions have pros and cons<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Item #1: If you're lucky enough to have an ISP that will set this up for you (pretty rare), all you need to do is<br />

use basic 'route' commands to get this running. This is the most rebust solution and doesn't require any form of<br />

<strong>IP</strong>MASQ or NAT to work.<br />

Item #2: 1:1 NAT isn't covered in this <strong>HOWTO</strong> yet but if you need a hand, just email me and I'll give you a<br />

hand.<br />

Item #3: ProxyARP is pretty strait forward but only works in specific situations and only works with Ethernet<br />

networks. Bridging is more powerful but will probably require the re−compiling of the kernel and some<br />

advanced configuration. Ultimately, neither of these solutions are <strong>IP</strong>MASQ anymore and thus I can't help you<br />

set them up. Fortunately, there are other <strong>HOWTO</strong>s out there that cover this topic:<br />

• http://www.tldp.org/<strong>HOWTO</strong>/Proxy−ARP−Subnet/index.html<br />

• http://www.tldp.org/<strong>HOWTO</strong>/Adv−Routing−<strong>HOWTO</strong>/lartc.bridging.html<br />

• http://www.tldp.org/<strong>HOWTO</strong>/Ethernet−Bridge−netfilter−<strong>HOWTO</strong>.html<br />

• http://bridge.sourceforge.net/<br />

NOTE: If you have a bridged DSL or Cablemodem connection (not PPPoE), things are a little more difficult<br />

because your setup isn't routed. No worries though, check out the Bridge+Firewall Mini <strong>HOWTO</strong> and the<br />

Bridge+Firewall+DSL Mini <strong>HOWTO</strong>. <strong>The</strong>se <strong>HOWTO</strong>s will teach you how to get your <strong>Linux</strong> box to support<br />

multiple <strong>IP</strong> addresses on a single interface!<br />

7.33. ( 1:1 NAT ) − I'd like to do 1:1 NAT but I can't figure out<br />

how to do it<br />

Please see the previous FAQ entry named Section 7.32 for all the details.<br />

Chapter 7. Frequently Asked Questions 145


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

7.34. ( Netstat ) − I'm trying to use the NETSTAT command<br />

to show my <strong>Masquerade</strong>d connections but its not working<br />

<strong>The</strong>re might be a problem with the "netstat" program in 2.0.x−based <strong>Linux</strong> distros. After a <strong>Linux</strong> reboot,<br />

running "netstat −M" works fine but after a MASQed computer runs some successful ICMP traffic like ping,<br />

traceroute, etc., you might see something like:<br />

masq_info.c: Internal Error `ip_masquerade unknown type'.<br />

<strong>The</strong> workaround for this is to use the "/sbin/ipfwadm −M −l" command. You will also notice that once the<br />

listed ICMP masquerade entries timeout, "netstat" works again.<br />

7.35. ( VPNs ) − I would like to get Microsoft PPTP (GRE<br />

tunnels) and/or <strong>IP</strong>SEC (<strong>Linux</strong> SWAN) tunnels running<br />

through <strong>IP</strong> MASQ<br />

This IS possible for specific modes. Specifically, all of the kernel versions (2.4.x, 2.2.x, and 2.0.x) support<br />

patches to allow for both ONE or MULT<strong>IP</strong>LE PPTP users behind a <strong>IP</strong>MASQ server to connect to the −same−<br />

PPTP server. <strong>The</strong> 2.4.x kernels currently have a PPTP module now in the newest versions of the <strong>IP</strong>TABLES<br />

program and there is another version available on the <strong>IP</strong>MASQ WWW site. Please check out John Hardin's<br />

PPTP Masq page for details.<br />

7.36. ( Games ) − I want to get the XYZ network game to<br />

work through <strong>IP</strong> MASQ but it won't work. Help!<br />

First, check Steve Grevemeyer's MASQ Applications page. If your solution isn't listed there, try patching your<br />

<strong>Linux</strong> kernel with Glenn Lamb's http://ipmasq.webhop.net/files20/loose−udp−2.0.36.patch.gz LooseUDP<br />

patch which is covered in Section 6.10 above. Also check out Dan Kegel's NAT Page for more information.<br />

If you are technically inclined, use the program "tcpdump" and sniff your network. Try to find out what<br />

protocols and port numbers your XYZ game is using. With this information in hand, subscribe to the <strong>IP</strong> Masq<br />

email list and email your results for help.<br />

7.37. ( Stops working ) − <strong>IP</strong> MASQ works fine for a while but<br />

then it stops working. A reboot seems to fix this. Why?<br />

I bet you are using <strong>IP</strong>AUTOFW and/or you have it compiled into the kernel huh?? This is a known problem<br />

with <strong>IP</strong>AUTOFW. It is recommend to NOT even configure <strong>IP</strong>AUTOFW into the <strong>Linux</strong> kernel and use<br />

<strong>IP</strong>PORTFW option instead. This is covered with more details in Section 6.7.<br />

7.38. ( SMTP Relay ) − Internal MASQed computers cannot<br />

send SMTP or POP−3 mail!<br />

Though this isn't a Masquerading issue but many users do this so it should be mentioned.<br />

Chapter 7. Frequently Asked Questions 146


SMTP: <strong>The</strong> issue is that you are probably using your <strong>Linux</strong> box as an SMTP relay server and get the<br />

following error:<br />

"error from mail server: we do not relay"<br />

Newer versions of Sendmail and other Mail Transfer Agents (MTAs) disable relaying by default (this is a<br />

good thing). So do the following to fix this:<br />

• Sendmail: Enable specific relaying for your internal MASQed machines by editing the<br />

/etc/sendmail.cw file and add the hostname and domain name of your internal MASQed machine.<br />

You should also check to see that the /etc/hosts file has the <strong>IP</strong> address and Fully Qualified Domain<br />

Name (FQDN) configured in it. Once this is done, you need to restart Sendmail for it to re−read its<br />

configuration files. This is covered in TrinityOS − Section 25<br />

POP−3: Some users configure their internal MASQ'ed computer's POP−3 clients to connect to some external<br />

SMTP server. While this is fine, many SMTP servers out there will try to IDENT your connection on port<br />

113. Most likely your problem stems around your default <strong>Masquerade</strong> policy being set to DENY. This is<br />

BAD. Set it to REJECT and re−run your rc.firewall−* ruleset.<br />

7.39. ( Source Routing ) − I need different internal MASQed<br />

networks to exit on different external <strong>IP</strong> addresses<br />

Say you have the following setup: You have multiple internal networks and also multiple external <strong>IP</strong><br />

addresses and/or networks. What you want to do is have LAN #1 to only use External <strong>IP</strong> #1 but you wan LAN<br />

#2 to use External <strong>IP</strong> #2.<br />

Internal LAN −−−−−−−−−−> official <strong>IP</strong><br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

LAN #1 External <strong>IP</strong> #1 192.168.0.x −−> 123.123.123.11<br />

LAN #2 External <strong>IP</strong> #2 192.168.1.x −−> 123.123.123.12<br />

Basically, what we have described here is routing NOT only on the destination address (typical <strong>IP</strong> routing) but<br />

also routing based upon the SOURCE address as well. This is typically called "policy−based routing" or<br />

"source routing". This functionality is NOT available in 2.0.x kernels, it *IS* available for 2.2.x kernels via<br />

the <strong>IP</strong>ROUTE2 package, and it is built into the new 2.4.x kernels using <strong>IP</strong>TABLES.<br />

First, you have to understand that both <strong>IP</strong>FWADM and <strong>IP</strong>CHAINS get involved *AFTER* the routing system<br />

has decided where to send a given packet. This statement really ought to be stamped in big red letters on all<br />

<strong>IP</strong>FWADM/<strong>IP</strong>CHAINS/<strong>IP</strong>MASQ documentation. <strong>The</strong> reason for this is that users MUST first have their<br />

routing setup correct, then start adding <strong>IP</strong>FWADM/<strong>IP</strong>CHAINS and/or Masq features.<br />

Anyways, for the example case shown above, you will need to persuade the routing system to direct packets<br />

from 192.168.0.x via 123.123.1233.11 and packets from 192.168.1.x via 123.123.123.12. That is the hardest<br />

part and adding Masq on top of correct routing is easy.<br />

To do this fancy routing, you will use <strong>IP</strong>ROUTE2. Because this functionality has NOTHING to do with<br />

<strong>IP</strong>MASQ, this <strong>HOWTO</strong> does not cover this topic in great detail. Please see Section 2.7 for complete URLs<br />

and documentation for this topic.<br />

Chapter 7. Frequently Asked Questions 147


<strong>The</strong> "iprule" and "iproute" commands are the same as "ip rule" and "ip route" commands (I prefer the former<br />

since it is easier to search for.) All the commands below are completely untested, if they do not work, please<br />

let David Ranch know about it but please contact the <strong>IP</strong>ROUTE2 email list for help. This function has<br />

NOTHING to do with <strong>IP</strong> Masquerading.<br />

2.4.x. kernels:<br />

<strong>The</strong> following would be integrated into the END of your rc.firewall−iptables ruleset<br />

EXTIF="eth0"<br />

INTNET1="192.168.0.0/24"<br />

INTNET2="192.168.1.0/24"<br />

EXT<strong>IP</strong>1="123.123.123.11"<br />

EXT<strong>IP</strong>2="123.123.123.12"<br />

iptables −t nat −A POSTROUTING −o $EXTIF −s $INTNET1 −j SNAT −−to $EXT<strong>IP</strong>1<br />

iptables −t nat −A POSTROUTING −o $EXTIF −s $INTNET2 −j SNAT −−to $EXT<strong>IP</strong>2<br />

2.2.x. kernels:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

<strong>The</strong> first few commands only need to be done once at boot, say in /etc/rc.d/rc.local file.<br />

# Allow internal LANs to route to each other, no masq.<br />

/sbin/iprule add from 192.168.0.0/16 to 192.168.0.0/16 table main pref 100<br />

# All other traffic from 192.168.1.x is external, handle by table 101<br />

/sbin/iprule add from 192.168.1.0/24 to 0/0 table 101 pref 102<br />

# All other traffic from 192.168.2.x is external, handle by table 102<br />

/sbin/iprule add from 192.168.2.0/24 to 0/0 table 102 pref 102<br />

<strong>The</strong>se commands need to be issued when eth0 is configured, perhaps in<br />

/etc/sysconfig/network−scripts/ifup−post (for Redhat systems). Be sure to<br />

do them by hand first to make sure they work.<br />

# Table 101 forces all assigned packets out via 123.123.123.11<br />

/sbin/iproute add table 101 via 123.123.123.11<br />

# Table 102 forces all assigned packets out via 123.123.123.12<br />

/sbin/iproute add table 102 via 123.123.123.12<br />

At this stage, you should find that packets from 192.168.1.x to the<br />

outside world are being routed via 123.123.123.11, packets from<br />

192.168.2.x are routed via 123.123.123.12.<br />

It is IMPORTANT that these <strong>IP</strong>ROUTE2 rules be run /BEFORE/ the rc.firewall−*<br />

ruleset is run.<br />

If everything hangs together, the masq code will see packets being<br />

routed out on 123.123.123.11 and 123.123.123.12 and will use those addresses<br />

as the masq source address.<br />

7.40. ( <strong>IP</strong>CHAINS rulesets on 2.4.x kernels ) − What the<br />

ipchains.o module can do on 2.4.x kernels<br />

Some people would like to continue using their legacy <strong>IP</strong>CHAINS rulesets on 2.4.x−based kernelw.<br />

Unfortunately, unless you are only doing packet firewalling and not trying to do any NATing (MASQ),<br />

PORTFW, or other advanced features, you're in trouble.<br />

Chapter 7. Frequently Asked Questions 148


•<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

If you ARE only doing <strong>IP</strong>CHAINS filtering, all you need to do is unload all <strong>IP</strong>TABLES modules<br />

shown from the "/sbin/lsmod" command. After that, load the <strong>IP</strong>CHAINS module by running<br />

"/sbin/modprobe ipchains". After that, load your <strong>IP</strong>CHAINS ruleset as normal.<br />

♦ Please note that if you compiled <strong>IP</strong>TABLES support statically into the kernel, you CANNOT<br />

load the "ipchains" module (it shouldn't be even present) as it will conflict with the<br />

<strong>IP</strong>TABLES kernel code. Your ONLY option in this case is to recompile your kernel but make<br />

the <strong>IP</strong>TABLES and <strong>IP</strong>CHAINS options as modules.<br />

So why can't you run <strong>IP</strong>CHAINS MASQ/PORTFW functionality with a 2.4.x kernel? Once the <strong>IP</strong>CHAINS<br />

module is loaded, you CANNOT use any <strong>IP</strong>TABLES commands or modules since the code conflicts. In<br />

addition to this, you cannot use any legacy 2.2.x <strong>IP</strong>CHAINS masq modules on a 2.4.x kernel as the kernels are<br />

so radically different. Plus, this really shouldn't be an issue as all of this functionality is available via native<br />

<strong>IP</strong>TABLES modules now. Finally, you cannot use the <strong>IP</strong>MASQADM tool with a 2.4.x kernel as the program<br />

both won't compile and ultimately the PORTFW kernel handlers aren't present anymore (it's now done<br />

natively by the <strong>IP</strong>TABLES code). So, considering all of these facts:<br />

• You cannot run any form of PORTFW on this 2.4.x machine<br />

• Protocols that require special handling like FTP, IRC, CuSeeme, RealAudio, etc. will no longer work<br />

Basically, the ipchains kernel module included with the 2.4.x kernels is intended for basic packet firewall<br />

compatibility and NOT any NAT(MASQ) functionality.<br />

7.41. ( <strong>IP</strong>TABLES vs. <strong>IP</strong>CHAINS vs. <strong>IP</strong>FWADM ) − Why do the<br />

2.4.x, 2.2.x, and 2.0.x kernels use different firewall systems?<br />

<strong>IP</strong>TABLES supports the following features that <strong>IP</strong>CHAINS and <strong>IP</strong>FWADM doesn't:<br />

• Stateful <strong>IP</strong>v4 protocol and application tracking<br />

• Stateful <strong>IP</strong>v6 protocol tracking<br />

• True 1:1 and 1:Many NAT<br />

• Built−in PORTFW functionality<br />

• See the Section 2.6 section for more details<br />

<strong>IP</strong>CHAINS supports the following features that <strong>IP</strong>FWADM doesn't:<br />

• "Quality of Service" (QoS support)<br />

• A TREE style chains system vs. LINEAR system like <strong>IP</strong>FWADM (Eg. this allows something like "if<br />

it is ppp0, jump to this chain (which contains its own difference set of rules)"<br />

• <strong>IP</strong>CHAINS is more flexible with configuration. For example, it has the "replace" command (in<br />

addition to "insert" and "add"). You can also negate rules (e.g. "discard any outbound packets that<br />

don't come from my registered <strong>IP</strong>" so that you aren't the source of spoofed attacks).<br />

• <strong>IP</strong>CHAINS can filter any <strong>IP</strong> protocol explicitly, not just TCP, UDP, ICMP<br />

7.42. ( Upgrades ) − I've just upgraded to the x.y.z kernel,<br />

why isn't <strong>IP</strong> <strong>Masquerade</strong> working?<br />

Chapter 7. Frequently Asked Questions 149


<strong>The</strong>re are several things you should check assuming your <strong>Linux</strong> <strong>IP</strong> Masq box already has proper connections<br />

to the Internet and your LAN:<br />

• Make sure you have the necessary features and modules are compiled and loaded. See earlier sections<br />

for details.<br />

• Check /usr/src/linux/<strong>Documentation</strong>/Changes and make sure you have the minimal<br />

requirement for the network tools installed.<br />

• Make sure you followed all of the tests in Chapter 5 of the <strong>HOWTO</strong>.<br />

• Make sure you are using the proper firewall tool for you kernel be it <strong>IP</strong>TABLES, <strong>IP</strong>CHAINS, or<br />

<strong>IP</strong>FWADM.<br />

• If you are doing PORTFW functionality, make sure you use the correct tool for your kernel version.<br />

<strong>IP</strong>TABLES has everything built−in, <strong>IP</strong>CHAINS requires the use of <strong>IP</strong>MASQADM, and <strong>IP</strong>FWADM<br />

reaquires the use of <strong>IP</strong>PORTFW or <strong>IP</strong>AUTOFW. This is completely covered in Section 6.7.<br />

• Go through all setup and configuration again! Usually, it's just a typo or a simple mistake you are<br />

overlooking.<br />

7.43. ( EQL ) − I need help with EQL connections and <strong>IP</strong><br />

Masq<br />

EQL has nothing to do with <strong>IP</strong> Masq though they are commonly teamed up on <strong>Linux</strong> boxes. Because of this, I<br />

recommend checking out the NEW version of Robert Novak's EQL <strong>HOWTO</strong> for all your EQL needs.<br />

7.44. ( Wussing out ) − I can't get <strong>IP</strong> <strong>Masquerade</strong> to work!<br />

What options do I have for Windows Platforms?<br />

Looking to give up a free, reliable, high performance solution that works on minimal hardware and pay a<br />

fortune for something that needs more hardware, is lower performance and did I say less reliable? (IMHO.<br />

And yes, I have real life experience with these ;−)<br />

Okay, it's your call. If you want a Windows NAT and/or proxy solution, here is a decent listing. I don't prefer<br />

any one of these tools over another, especially since I haven't used them before.<br />

• Firesock (from the makers of Trumpet Winsock)<br />

♦ Does Proxy<br />

♦ http://www.trumpet.com.au<br />

• Iproute<br />

♦ DOS program designed to run on 286+ class computers<br />

♦ requires another box like <strong>Linux</strong> MASQ<br />

♦ (UNAVAILABLE) www.mischler.com/iproute/<br />

• Microsoft Proxy<br />

♦ Requires Windows NT Server<br />

♦ Quite expensive<br />

♦ http://www.microsoft.com<br />

• NAT32<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Chapter 7. Frequently Asked Questions 150


♦ Windows 95/98/NT compatible<br />

♦ http://www.nat32.com<br />

♦ Roughly $25 for Win9x and $47 for Win9x and WinNT<br />

• SyGate<br />

♦ http://www.sygate.com<br />

• Wingate<br />

♦ Does proxy<br />

♦ Costs roughly $30 for 2−3 <strong>IP</strong>s<br />

♦ http://www.wingate.com<br />

• Winroute<br />

♦ Does NAT<br />

♦ WinRoute<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

Lastly, do a web search on "MS Proxy Server", "Wingate", "WinProxy", or goto www.download.com. And<br />

definitely DON'T tell anyone that we sent you.<br />

7.45. ( Developers ) − I want to help with <strong>IP</strong> <strong>Masquerade</strong><br />

development. What can I do?<br />

Join the <strong>Linux</strong> <strong>IP</strong> Masquerading DEVELOPERS list and ask the developers there what you can do to help.<br />

For more details on joining the list, check out Section 7.5 FAQ section.<br />

Please DON'T ask NON−<strong>IP</strong>−<strong>Masquerade</strong> development related questions there!!!!<br />

7.46. ( More INFO ) − Where can I find more information on<br />

<strong>IP</strong> <strong>Masquerade</strong>?<br />

You can find more information on <strong>IP</strong> <strong>Masquerade</strong> at the <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> Resource that Ambrose Au<br />

maintains.<br />

You can also find more information at Dranch's <strong>Linux</strong> page where the TrinityOS and other <strong>Linux</strong> documents<br />

are kept.<br />

You may also find more information at <strong>The</strong> Semi−Original <strong>Linux</strong> <strong>IP</strong> Masquerading Web Site maintained by<br />

Indyramp Consulting, who also provides the <strong>IP</strong> Masq mailing list.<br />

Lastly, you can look for specific questions in the <strong>IP</strong> MASQ and <strong>IP</strong> MASQ DEV email archives or ask a<br />

specific question on these lists. Check out Section 7.5 FAQ item for more details.<br />

7.47. ( Translators ) − I want to translate this <strong>HOWTO</strong> to<br />

another language, what should I do?<br />

Make sure the language you want to translate to is not already covered by someone else. But, most of the<br />

translated <strong>HOWTO</strong>s are now OLD and need to be updated. A list of available <strong>HOWTO</strong> translations are<br />

Chapter 7. Frequently Asked Questions 151


available at the <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> Resource.<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

If a copy of a current <strong>IP</strong> MASQ <strong>HOWTO</strong> isn't in your proposed language, please download the newest copy<br />

of the <strong>IP</strong>−MASQ <strong>HOWTO</strong> SGML code from the <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> Resource. From there, begin your<br />

work while maintaining good SGML coding. For more help on SGML, check out www.sgmltools.org<br />

7.48. ( Updates ) − This <strong>HOWTO</strong> seems out of date, are you<br />

still maintaining it? Can you include more information on<br />

...? Are there any plans for making this better?<br />

Yes, this <strong>HOWTO</strong> is still being maintained. In the past, Ambrose was guilty of being too busy working on<br />

two jobs and didn't have much time to work on this, my apologies. As of v1.50, David Ranch revamped the<br />

document and got it current again.<br />

If you think of a topic that could be included in the <strong>HOWTO</strong>, please send email dranch@trinnet.net. It will be<br />

even better if you can provide that information. We will then include the information into the <strong>HOWTO</strong> once it<br />

is both found appropriate and tested. Many thanks for your contributions!<br />

We have a lot of new ideas and plans for improving the <strong>HOWTO</strong>, such as case studies that will cover<br />

different network setup involving <strong>IP</strong> <strong>Masquerade</strong>, more on security via strong <strong>IP</strong>FWADM/<strong>IP</strong>CHAINS<br />

firewall rulesets, <strong>IP</strong>CHAINS usage, more FAQ entries, etc. If you think you can help, please do! Thanks.<br />

7.49. ( Thanks ) − I got <strong>IP</strong> <strong>Masquerade</strong> working, it's great! I<br />

want to thank you guys, what can I do?<br />

• Can you translate the newer version of the <strong>HOWTO</strong> to another language?<br />

• Thank the developers and appreciate the time and effort they spent on this.<br />

• Join the <strong>IP</strong> <strong>Masquerade</strong> email list and support new MASQ users<br />

• Send an email to us and let us know how happy you are<br />

• Introduce other users to <strong>Linux</strong> and help them when they have problems.<br />

Chapter 7. Frequently Asked Questions 152


Chapter 8. Miscellaneous<br />

8.1. Useful Resources<br />

• <strong>IP</strong> <strong>Masquerade</strong> Resource page Will have all the current information for setting up <strong>IP</strong> <strong>Masquerade</strong> on<br />

2.0.x, 2.2.x, and even old 1.2 kernels!<br />

• Juan Jose Ciarlante's WWW site (mirror) who is one of the current <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> maintainers.<br />

• <strong>IP</strong> <strong>Masquerade</strong> mailing list Archives contains the recent messages sent to the mailing lists.<br />

• David Ranch's <strong>Linux</strong> page including the TrinityOS <strong>Linux</strong> document and current versions of the<br />

<strong>IP</strong>−MASQ−<strong>HOWTO</strong>.. Topics such as <strong>IP</strong> MASQ, strong <strong>IP</strong>FWADM/<strong>IP</strong>CHAINS rulesets, PPP, Diald,<br />

Cablemodems, DNS, Sendmail, Samba, NFS, Security, etc. are covered.<br />

• <strong>The</strong> <strong>IP</strong> Masquerading Applications page: A comprehensive list of applications that work or can be<br />

tuned to work through a <strong>Linux</strong> <strong>IP</strong> masquerading server.<br />

• For users setting up <strong>IP</strong> Masq on Mk<strong>Linux</strong>, email Taro Fukunaga at tarozax@earthlink.net for a copy<br />

of his short Mk<strong>Linux</strong> version of this <strong>HOWTO</strong>.<br />

• <strong>IP</strong> masquerade FAQ has some general information<br />

• Paul Russel's http://www.netfilter.org/ipchains/ doc and its possibly older backup at <strong>Linux</strong><br />

<strong>IP</strong>CHAINS <strong>HOWTO</strong>. This <strong>HOWTO</strong> has lots of information for <strong>IP</strong>CHAINS usage, as well as source<br />

and binaries for the ipchains tool.<br />

• X/OS Ipfwadm page contains sources, binaries, documentation, and other information about the<br />

ipfwadm package<br />

• Check out the GreatCircle's Firewall mailing list for a great resource about strong firewall rulesets.<br />

• <strong>The</strong> LDP Network Administrator's Guide is a MUST for the beginner <strong>Linux</strong> administrator trying to<br />

set up a network.<br />

• <strong>The</strong> <strong>Linux</strong> NET <strong>HOWTO</strong> is also another comprehensive document on how to setup and configure<br />

<strong>Linux</strong> networking.<br />

• <strong>Linux</strong> ISP Hookup <strong>HOWTO</strong> and <strong>Linux</strong> PPP <strong>HOWTO</strong> gives you information on how to connect your<br />

<strong>Linux</strong> host to the Internet<br />

• <strong>Linux</strong> Ethernet−Howto is a good source of information about setting up a LAN running over<br />

Ethernet.<br />

• Donald Becker's NIC drivers and Support Utils<br />

• You may also be interested in <strong>Linux</strong> Firewalling and Proxy Server <strong>HOWTO</strong><br />

• <strong>Linux</strong> Kernel <strong>HOWTO</strong> will guide you through the kernel compilation process<br />

• Other <strong>Linux</strong> <strong>HOWTO</strong>s such as Kernel <strong>HOWTO</strong><br />

• Posting to the USENET newsgroup: comp.os.linux.networking<br />

8.2. <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> Resource<br />

<strong>The</strong> <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> Resource is a website dedicated to <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> information also<br />

maintained by Ambrose Au. It has the latest information related to <strong>IP</strong> <strong>Masquerade</strong> and may have information<br />

that is not being included in the <strong>HOWTO</strong>.<br />

You may find the <strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> Resource at the following locations:<br />

• http://ipmasq.webhop.net/, Primary Site, redirected to http://ipmasq.webhop.net/<br />

• http://ipmasq2.webhop.net/, Secondary Site, redirected to http://www.e−infomax.com/ipmasq<br />

Chapter 8. Miscellaneous 153


8.3. Thanks to the following supporters..<br />

In Alphabetical order:<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• Gabriel Beitler, gabrielb@voicenet.com on providing section 3.3.8 (setting up Novell)<br />

• Juan Jose Ciarlante, irriga@impsat1.com.ar for contributing his work on the <strong>IP</strong>MASQADM port<br />

forward tool, the 2.1.x and 2.2.x kernel code, and the original LooseUDP patch, etc.<br />

• Steven Clarke, steven@monmouth.demon.co.uk for contributing his <strong>IP</strong>PORTFW <strong>IP</strong> port forwarder<br />

tool<br />

• Andrew Deryabin, djsf@usa.net for contributing his ICQ MASQ module<br />

• Ed Doolittle, dolittle@math.toronto.edu for suggestions to −V option in theipfwadm command for<br />

improved security<br />

• Matthew Driver, mdriver@cfmeu.asn.au for helping extensively on this <strong>HOWTO</strong>, and providing<br />

section 3.3.1 (setting up Windows 95)<br />

• Ken Eves, ken@eves.com for the FAQ that provides invaluable information for this <strong>HOWTO</strong><br />

• John Hardin, jhardin@impsec.org for his PPTP and <strong>IP</strong>SEC forwarding tools<br />

• Glenn Lamb, mumford@netcom.com for the LooseUDP patch<br />

• Ed. Lott, edlott@neosoft.com for a long list of tested system and software<br />

• Nigel Metheringham, Nigel.Metheringham@theplanet.net for contributing his version of the <strong>IP</strong><br />

Packet Filtering and <strong>IP</strong> Masquerading <strong>HOWTO</strong>, which makes this <strong>HOWTO</strong> a better and in−depth<br />

technical document section 4.1, 4.2, and others<br />

• Keith Owens, kaos@ocs.com.au for providing an excellent guide on ipfwadm section 4.2 on<br />

correction to ipfwadm −deny option which avoids a security hole, and clarified the status of ping<br />

over <strong>IP</strong> <strong>Masquerade</strong><br />

• Michael Owings, mikey@swampgas.com for providing the section about CU−SeeMe and <strong>Linux</strong><br />

<strong>IP</strong>−<strong>Masquerade</strong> Teeny How−To<br />

• Rob Pelkey, rpelkey@abacus.bates.edu for providing section 3.3.6 and 3.3.7 (setting up MacTCP and<br />

Open Transport)<br />

• Harish Pillay, h.pillay@ieee.org for providing section 4.5 (dial−on−demand using Diald)<br />

• Mark Purcell, purcell@rmcs.cranfield.ac.uk for providing section 4.6 (<strong>IP</strong>autofw)<br />

• David Ranch, dranch@trinnet.net for maintaining the <strong>HOWTO</strong>, helping with the <strong>Linux</strong> <strong>IP</strong><br />

<strong>Masquerade</strong> Resource Page, the TrinityOS document, ..., too many to list here :−)<br />

• Paul Russell, rusty@linuxcare.com.au for all his work on <strong>IP</strong>TABLES, <strong>IP</strong>CHAINS, the <strong>IP</strong> <strong>Masquerade</strong><br />

kernel patches in general, etc. <strong>The</strong> man is a <strong>IP</strong> NATing fool!<br />

• Ueli Rutishauser, rutish@ibm.neton providing section 3.3.9 (setting up OS/2 Warp)<br />

• Steve Grevemeyer, grevemes@tsmservices.com for taking over the <strong>IP</strong> Masq Applications page from<br />

Lee Nevo and updating it to a full DB backend.<br />

• Fred Viles, fv@episupport.com for his patches on proper port forarding of FTP.<br />

• John B. (Brent) Williams, forerunner@mercury.net on providing section 3.3.7 (setting up Open<br />

Transport)<br />

• Enrique Pessoa Xavier, enrique@labma.ufrj.bron the BOOTp setup suggestion<br />

• All the users on the <strong>IP</strong>−MASQ email list, masq@indyramp.com for their help and support for all the<br />

new <strong>Linux</strong> MASQ users.<br />

• Other code and documentation developers of <strong>IP</strong> <strong>Masquerade</strong> for this great feature<br />

• Delian Delchev, delian@wfpa.acad.bg<br />

• David DeSimone (FuzzyFox), fox@dallas.net<br />

• Jeanette Pauline Middelink, middelin@polyware.iaf.nl<br />

• Miquel van Smoorenburg, miquels@q.cistron.nl<br />

• Jos Vos, jos@xos.nl<br />

• And others who I may have failed to mention here (please let me know)<br />

Chapter 8. Miscellaneous 154


• All users sending feedback and suggestions to the mailing list, especially those who reported errors in<br />

the document and the clients who are supported and not supported<br />

• We apologize if we have omitted any important names, not included information that some fellow<br />

users have sent us yet, etc. <strong>The</strong>re were many suggestions and ideas sent but there wasn't enough time<br />

to verify and integrate these changes. David Ranch is constantly trying his best to incorporate all of<br />

the information sent to me into the <strong>HOWTO</strong>. I thank you for the effort, and I hope you understand our<br />

situation.<br />

8.4. Reference<br />

• Original <strong>IP</strong> masquerade FAQ by Ken Eves<br />

• <strong>IP</strong> masquerade mailing list archive by Indyramp Consulting<br />

• <strong>IP</strong> <strong>Masquerade</strong> WWW site by Ambrose Au<br />

• Ipfwadm page by X/OS<br />

• Various networking related <strong>Linux</strong> <strong>HOWTO</strong>s<br />

• Some topics covered in TrinityOS by David Ranch<br />

8.5. ChangeLOG<br />

TO do − <strong>HOWTO</strong>:<br />

• Add the scripted <strong>IP</strong>MASQADM example to the Forwarders section. Also confirm the syntax.<br />

• Add a little section on having multiple subnets behind a MASQ server<br />

• Confirm the <strong>IP</strong>CHAINS ruleset and make sure it is consistant with the <strong>IP</strong>FWADM ruleset<br />

TO DO − WWW page:<br />

• Update the PPTP patch on the masq site<br />

• Update the portfw FTP patch<br />

Changes from 05/22/05 to 11/13/05<br />

• 11/13/05 − Fix a bug where the PORTFW example rule in section 6.7 was incorrect. Updated the<br />

<strong>IP</strong>TABLES PORTFW section to include state tracking for the pre−routing rule, added a<br />

cross−reference to the PORTFW FAQ entry, and reduced some duplicate PORTFW examples in<br />

different chapters of the <strong>HOWTO</strong>. Thanks to Thomas Zajic for bringing this to my attention.<br />

• 10/23/05 − Updated the dynamic <strong>IP</strong> FAQ section to give complete examples on how to re−run the<br />

rc.firewall−* scripts for various different DHCP clients<br />

• 10/19/05 − Updated the <strong>HOWTO</strong> to be very clear on loading the various rc.firewall−* rulesets (there<br />

are 6 of them in this <strong>HOWTO</strong> both simple and stronger versions for <strong>IP</strong>TABLES, <strong>IP</strong>CHAINS, and<br />

<strong>IP</strong>FWADM) files vs. loading a generic rc.firewall file. I also updated the troubleshooting section to<br />

reflect this possibly confusing point.<br />

• 05/27/05 − Updated the Multiple NAT situation to include ProxyARP solutions<br />

• 05/26/05 − Clarified the section for <strong>IP</strong>MASQ on multiple internal LAN segments<br />

Changes from 05/03/05 to 05/22/05<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• 05/22/05 − Updated the rc.firewall−iptables−stronger ruleset to 0.87s. Removed the unused<br />

drop−and−logit chain as it was only later being deleted anyway. Thanks to Matthew Concannon for<br />

Chapter 8. Miscellaneous 155


this one.<br />

• 05/21/05 − Updated the Multiple−<strong>IP</strong>s FAQ entry a bit<br />

Changes from 04/17/05 to 05/03/05<br />

• 05/03/05 − Updated the rc.firewall−iptables−stronger ruleset to fix a typo<br />

Changes from 03/19/04 to 04/17/05<br />

• 04/30/05 − Updated the <strong>IP</strong> address for unc.metalab.org and published the <strong>HOWTO</strong> to the web.<br />

• 12/18/04 − Added some comments in the <strong>IP</strong>TABLES, <strong>IP</strong>CHAINS, and <strong>IP</strong>FWADM rulesets why the<br />

default policy is ACCEPT and not something like DROP.<br />

• 07/24/04: Renamed the rc.firewall−2.4/2.2/2.0−* rulesets to rc.firewall−iptables/ipchains/ipfwadm−*.<br />

This change better reflects that these rulesets can run on different kernel versions (such as 2.6.x).<br />

Updated the rc.firewall−iptables−stronger ruleset to 0.85s to fix an improper /24 netmask for the<br />

INT<strong>IP</strong> variable.<br />

• 04/10/04: Updated the rc.firewall−2.4−stronger ruleset to use the 192.16.0.x network instead of<br />

192.168.1.x network to better align with the rest of the <strong>HOWTO</strong><br />

• 04/04/04: Added that Redhat9 supports <strong>IP</strong>MASQ<br />

Changes from 11/10/03 to 03/18/04<br />

• 03/18/04: Added a sub−section for supporting multiple internal networks for <strong>IP</strong>TABLES<br />

• 02/02/04: Updated some old jhardin rubyriver to impsec.org URLs<br />

• 01/10/04: Updated the rc.firewall−2.4−stronger and 2.2 rulesets to make placement of PORTFW<br />

configs more obvious<br />

• 01/01/04: Some systems require that the /etc/rc.d/init.d/firewall−2.* files be executable. Fixed.<br />

Thanks to Chris Carter and others for the nudge.<br />

• 01/01/04: Some systems require that the /etc/rc.d/init.d/firewall−2.* files be executable. Fixed.<br />

Thanks to Chris Carter and others for the nudge.<br />

• 01/01/04: Added an additional chkconfig check on Redhat systems to make sure that the firewall will<br />

load upon init level change. Thanks to Chris Carter for the idea.<br />

• 12/19/03: Updated the rc.firewall−2.4−stronger ruleset to 0.82. This new ruleset has a special ICMP<br />

filter to work around a Netfilter bug. Also, the drop−and−log−it chain has been renamed to<br />

reject−and−log−it since that's actually what it's doing. Thanks to Bart Martens for the<br />

recommendations.<br />

• 12/13/03: Fixed some minor grammar issues. Thanks to Lawrence Berlinsk for pointing them out.<br />

• 11/30/03: Updated the rc.firewall−2.4−stronger ruleset to 0.81s, the rc−firewall−2.2−stronger ruleset<br />

to 0.72s, and updated the rc.firewall−2.0−stronger ruleset to 0.72s (never had a version # before).<br />

<strong>The</strong>se changes reflect either the ruleset not having strong enough comments or allowing all traffic<br />

destined to the MASQ server itself from being protected. It's recommend that if you want to enable<br />

access to servers running on the MASQ server itself (http, ssh, etc.), selectively enable them under the<br />

OPTIONAL INPUT section.<br />

• 11/03/03: Updated the rc.firewall−2.2−stronger ruleset where an INTLAN rule that was allowing<br />

traffic from ANY <strong>IP</strong> address instead of the proper INT<strong>IP</strong> <strong>IP</strong> address only. This aligns the <strong>IP</strong>CHAINS<br />

ruleset with the <strong>IP</strong>TABLES and <strong>IP</strong>FWADM ruleset examples<br />

• 11/10/03: Deleted all kernelnotes.org URLS (juanjox URLs)<br />

Changes from 06/22/03 to 11/09/03<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• 10/25/03: Fixed a dead RFC1918 URL in section 3.3. Thanks to Mark Sobell for the report.<br />

Chapter 8. Miscellaneous 156


• 07/07/03: Added the "reducing−masq−log" FAQ entry to help people reduce the size of their firewall<br />

logs.<br />

• 06/27/03: Updated the rc.firewall−2.4−stronger ruleset to 0.80s. Added a DISABLED ip_nat_irc<br />

kernel module section, changed the default of the ip_conntrack_irc to NOT load by default, and added<br />

additional kernel module comments.<br />

• 06/27/03: Updated the rc.firewall−2.4 ruleset to 0.75. Added additional iptables kernel module<br />

comments.<br />

• 06/24/03: Added Debian 3.0 to the supported distro list<br />

• 06/23/03: Change the PMTU URLs to point to Phil's primary www site<br />

Changes from 05/26/03 to 06/22/03<br />

• 06/22/03: Updated the various Indyramp MASQ email URLs again as things seemed to have changed.<br />

Again.<br />

• 06/21/03: Rewrote the MTU FAQ section to be more clear, include specific information of the<br />

problems, and also fixed a bad typo for PPPoE users who were trying to configure<br />

"−−clamp−mss−to−mtu" when it should have been "−−clamp−mss−to−pmtu" (missing the p in pmtu).<br />

• 06/13/03: Added kernel info for Mandrake 8.1<br />

• 06/02/03: Fixed a typo where extended 2.2.x kernel checks for <strong>IP</strong>MASQ functionality was using "cat"<br />

and not "ls"<br />

Changes from 04/08/03 to 05/26/03<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• 05/26/03: updated the firewall rulesets: rc.firewall−2.4 (to 0.74), rc.firewall−2.2 (to 1.22),<br />

rc.firewall−2.4−stronger (to 0.79s), and rc.firewall−2.2−strongerw (to 0.71s) to use modprobe instead<br />

of insmod.<br />

• 05/26/03: Added how to dump <strong>IP</strong>TABLES MASQ entries in the Accounting FAQ section<br />

• 05/26/03: Added Clamp−MSS recommendations to the MTU faq section<br />

• 05/26/03: Added additional troubleshooting steps in Section 5 when the MASQ client cannot ping the<br />

MASQ server.<br />

• 05/26/03: Added additional traffic shaping / traffic limiter URLs to the SHAPING FAQ entry<br />

• 05/26/03: Renamed the "<strong>IP</strong>ROUTE2" FAQ entry to "Souce Routing"; Added <strong>IP</strong>TABLES examples to<br />

the section; fixed an incorrect <strong>IP</strong> address of 62123.123.123.123<br />

• 05/25/03: Fixed a SGML script that was improperly converting ampersands for the downloadable<br />

firewall−* and rc.firewall−* scripts. Also caught a SGML ampersand bug in a comment section of the<br />

rc.firewall−2.0 file<br />

• 05/25/03: Deleted several dead links: ftp.gts.cz, novell.com LWP5, Old Juanjox mirror (geocities),<br />

old ipmasq2.webhop.net URL, old zzdmacka NAT information URL, old linux.org/uk/VERSION url,<br />

old netfilter.samba.org URLs (no longer a netfilter mirror − redirect), old Activision BattleZone DLL<br />

url, old iproute2 (rpms, ras.ru, donlug, dontsk, tusur, waaug, etc.) urls, old rlynch ipautofw mirror<br />

• 05/25/03: Updated several URLs: suse/proxy_suite/, www.indyramp.net URLs, several urls with " ~ "<br />

in it became ~732 for some reason, updated all of the jhardin URls to point from wolfnet.com to<br />

impsec.org, updated all LDP urls (linuxdoc.org to tldp.org), <strong>IP</strong>CHAINS patches for 2.0.x kernels,<br />

metalab to tldp.org, winfiles.com to download.com, Microsoft technet article 172227, Oidentd,<br />

mumford LooseUDP URL, 2.2.x PORT−FTP URL, IRQTUNE url, midentd URL<br />

• 05/25/03: Pending updates from remote webmasters: Indyramp EQL URL, insecurity.net sidentd<br />

• 05/25/03: Lots of little updates like:: updated the Intro section verbage a little to reflect BETA kernels<br />

and not OLD kernels; Updated the Forward section (not PORTFW) to be a little more generic; Added<br />

a link in the Forward to the <strong>IP</strong>MASQ email list; Updated the dates in the copyright notice;<br />

• 05/24/03: Updated the "Current Status" to add the remark that some programs have been updated to<br />

use NAT−friendly protocols and thus special NAT modules are no longer required<br />

Chapter 8. Miscellaneous 157


• 05/24/03: Updated the 2.4 Requirements section: deleted a duplicate line (true 1:1 NAT); cleaned<br />

some addition things up; Added CuSeeme to the 2.4 ported list<br />

• 05/24/03: Updated the 2.2 / 2.0 Requirements section: Deleted the reference to the obsoltele <strong>IP</strong>MASQ<br />

ICQ module; Updated the link for the LooseUDP URL;<br />

• 05/24/03: Updated the Compiling <strong>Linux</strong> 2.2.x / 2.0.x section: Deleted the recommendations to load<br />

the rc.firewall ruleset via rc.local. This should come later in the <strong>HOWTO</strong> and offer other methods for<br />

different <strong>Linux</strong> distributions<br />

• 05/24/03: Updated the ICQ Application section to say that these steps are /not/ required for modern<br />

ICQ clients. I've left this section in the <strong>HOWTO</strong> to demonstrate a large PORTFW example<br />

• 05/24/03: Made some of the FAQ entries more kernel version generic and also deleted the 2.0.x<br />

"upgrades−cont.html" FAQ entry as it was basically a duplicate<br />

• 05/24/03: Updated the LooseUDP game section to explain how it works, explain how much of this<br />

was properly solved under the stateful <strong>IP</strong>TABLES systtem, and also say that it is NOT available for<br />

the 2.4.x kernels. If <strong>IP</strong>TABLES's stateful UDP tracking doesn't work for, you're probably out of luck.<br />

• 05/24/03: Mentioned in the FAQ section that MASQ timers are NOT adjustable under <strong>IP</strong>TABLES<br />

• 05/24/03: Vastly expanded the packet firewall log FAQ entry and finally added a <strong>IP</strong>TABLES packet<br />

log description section. I also aligned the <strong>IP</strong>CHAINS example to match the <strong>IP</strong>FWADM entry<br />

• 04/11/03: Fixed a incorrect echo statement saying the <strong>IP</strong>TABLES policy was being set to REJECT<br />

and not DROP.<br />

Changes from 01/31/03 to 04/08/03<br />

• 04/08/03: Added additional formatting and the "ip_masquerade" /proc entry into Section 3.2. This<br />

helps users determine if their kernel is MASQ−ready.<br />

• 03/08/03: Added the EXT<strong>IP</strong> variable to the 2.4.x PORTFW example as several people were trying to<br />

use this with the BASIC ruleset and I had assumed they were using the STRONGER ruleset. Thanks<br />

to Greg Lukins for bringing this to my attention.<br />

• 03/08/03: Added Distros to the MASQ compatibility list: Mandrake, Gentoo<br />

• 02/08/03: Forgot to update the VERSION number for the rc.firewall−2.4−stronger rulese. Added<br />

some additional formatting<br />

• 02/01/03: Added additional checking in the kernel compiling section to understand if your kernel<br />

supports <strong>IP</strong>MASQ via modules or by being statically compiled in.<br />

Changes from 01/12/03 to 01/31/03<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• 01/31/03: Doh. I should have read my own comments. I've reversed the 2.4.x. policy settings from<br />

REJECT back to DROP. REJECT, for some lame reason, is not a legal policy. <strong>The</strong> recommended<br />

REJECT action is still carried out via the "drop−and−log−it" user chain.<br />

• 01/30/03: Updated the Multiple−<strong>IP</strong>s FAQ entry to better describe how users that want to put external<br />

<strong>IP</strong>s behind a <strong>Linux</strong> router. Added additional URLs and cleaned up the text a bit too.<br />

• 01/30/03: Updated the 2.4.x requirement section to reflect more of the pros of <strong>IP</strong>TABLES as well as<br />

updated the update status of some old legacy 2.2.x modules<br />

• 01/30/03: Added an additional FAQ entry that clearly explains what the ipchains.o module can and<br />

CANNOT do on 2.4.x. kernels<br />

• 01/28/03: Extensively updated the 2.4.x kernel compilation section to reflect a 2.4.20 kernel with<br />

<strong>IP</strong>TABLES 1.2.7a. <strong>The</strong> section also reflects the new methods to compile <strong>IP</strong>TABLES, apply<br />

Patch−O−Matic patches, and also included lots of example output too.<br />

• 01/28/03: Updated the kernel compiling section to be a little more clear on how different <strong>Linux</strong><br />

distros can have different kernels (modules vs. monolithic)<br />

• 01/17/03: Fixed a major issue where the rc.firewall−2.2−stronger ruleset was referencing missing<br />

executable variables. This was taken from the 2.4−stronger ruleset but I guess I forgot to finish it off.<br />

Chapter 8. Miscellaneous 158


Fixed. Thanks to Samuel Kim for catching this!<br />

• 01/17/03: Fixed an issue where the rc.firewall−2.2−stronger's commented HTTP section was missing<br />

the "−p tcp" option. Thanks to Samuel Kim for catching this!<br />

• 01/16/03: Updated the URL for DJSF's ICQ module<br />

• 01/16/03: Changed the default policy and drop chain from DENY to REJECT on both <strong>IP</strong>TABLES<br />

rulesets and on the advanced <strong>IP</strong>FWADM rulset. Thanks to Jonathan Hutchins for bringing this to my<br />

attention.<br />

• 01/16/03: Fixed a typo in the commented out HTTPd OUTPUT section of the rc.firewall−2.2−s<br />

ruleset<br />

• 01/13/03: Updated the <strong>IP</strong>MASQ www site URL from ipmasq.cjb.net to ipmasq.webhop.net. CJB<br />

started to change their policies so we switched.<br />

• 01/13/03: Added to the 2.4.x Requirements section that <strong>IP</strong>TABLES v1.2.7a is out and recommended.<br />

• 01/13/03: Added an additional test item to the "Test Section − Section 5" for versions of <strong>IP</strong>TABLES<br />

that are too old. I also cleaned up this section to read easier.<br />

• 01/13/03: Updated the rc.firewall−2.4−stronger ruleset to include commented rules to allow in HTTP<br />

traffic to a local HTTP server. Also added a rule comment in the FORWARD section to help users<br />

know where to put PORTFW commands.<br />

• 01/13/03: Updated the rc.firewall−2.2−stronger ruleset to include commented rules to allow in HTTP<br />

traffic to a local HTTP server. Also added a rule comment in the FORWARD section to help users<br />

know where to put PORTFW commands.<br />

• 01/13/03: Clarified the PORTFW section to help users better understand where the PORTFW<br />

commands should go in the rc.firewall rulesets. I also cleaned up this section to read a little better.<br />

Changes from 12/13/02 to 01/12/03<br />

• 01/03/03: Added Redhat 7.3 and 8.0 to the compatibility chart.<br />

• 01/03/03: Fixed various typos. Thanks to Gabriel Withington for the sharp eye.<br />

• 12/22/02: Updated the 2.2.x H.323 kernel patch URL. Thanks to Maxime Plante for pointing this out.<br />

• 12/22/02: Updated the 2.4.x kernel compiling section to let users know that most modern kernels don't<br />

need <strong>IP</strong>TABLES Patch−o−matic patches to be applied except to fix bugs or add additional<br />

functionality.<br />

Changes from 10/20/02 to 12/13/02<br />

• 11/27/02: Fixed the init.d scripts to point the header to the correct config file. This must be due to<br />

newer versions of "chkconfig" doing better checking. Please note that this might still be a problem for<br />

the rc.firewall−2.?−stronger rulesets. Thanks to Joris Van Puyenbroeck for the heads up.<br />

• 11/25/02: Updated all the firewall comments to reflect that PPPoE users need to user the "ppp0"<br />

logical interface as their external interface instead of the physical interface such as "eth0". Thanks to<br />

Meng Cheah for the nudge.<br />

• 11/13/02: Updated the URL for the Donald Becker based NIC drivers. Thanks to Bruce Gorgon for<br />

the heads up.<br />

• 11/01/02: Added a new FAQ section that covers redirection of local INTERNAL traffic to internal<br />

PORTFWed servers<br />

• 11/01/02: Updated the PORTFW section to be a little more clear.<br />

Changes from 04/19/02 to 10/20/02<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• 09/29/02: Fixed a stray incorrect <strong>IP</strong> address pointing to metalab.unc.edu<br />

• 08/29/02: Fixed a typo in the firewall−2.2 startup script which was starting the 2.4 firewall and not the<br />

2.2. version. Thanks to Jean−Marc Vanel for catching this.<br />

Chapter 8. Miscellaneous 159


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• 08/25/02: Updated the rc.firewall−2.2−stronger and rc.firewall−2.2 scripts to use shell environment<br />

variables.<br />

• 07/09/02: Updated the FTP PORTFW section to be more readible<br />

• 07/06/02: Replaced all the filewatcher.org URLs with netfilter.org URLs<br />

• 06/12/02: Changed some of the formatting to try and help newbies better understand that the "\"<br />

character is used as a continuation of the previous line.<br />

• 06/12/02: Updated the <strong>IP</strong> address of metalab.unc.edu in Section 5. Thanks to Pete Trachy for bringing<br />

this to my attention but please note that even major sites like Metalab change their <strong>IP</strong>s, subnets, or<br />

even ISPs from time to time.<br />

• 06/02/02: Updated the rc.firewall−2.4 ruleset to include a commented option for NATing IRC DCCs,<br />

added the use of more environment vars, and added additional formatting.<br />

• 05/18/02: Added some extra # lines the commented section of the the rc.firewall−2.4−stronger ruleset<br />

to better serve Cut and Paste users.<br />

• 05/04/02: − Updated the various PPTP MASQ links to point to a valid URL. Also updated the<br />

<strong>HOWTO</strong> to reflect that PPTP is now supported on the 2.4.x kernels.<br />

• 05/03/02: − Updated the 2.4.x kernel requirements section to point out that <strong>IP</strong>CHAINS compatibility<br />

under 2.4.x kernels isn't very good. If you want to use <strong>IP</strong>MASQ under a 2.4.x kernel, you should use<br />

<strong>IP</strong>TABLES rules only.<br />

Changes from 01/05/02 to 04/19/02 − v2.00.041902 pubsished to the LDP<br />

• 04/01/02: − Updated the rc.firewall−2.4−stronger ruleset to denote and disable internal DHCP server<br />

support on the OUTPUT rules<br />

• 02/09/02: − Added Redhat−style init.d scripts to start the rc.firewall files<br />

• 02/09/02: − Updated all the various chapters to use human readable file names vs. things like<br />

x2623.html.<br />

• 02/09/02: − Expanded the <strong>IP</strong>MASQ accounting section<br />

• 02/04/02: − Deleted an extra "$" from the PORTFW variable in section 6.7.1<br />

• 01/31/02: − Updated the URLs for the PPPd and Diald homepages<br />

• 01/26/02: − Fixed some typos and added a LooseUDP clarification to tell users to read the example<br />

rc.firewall−2.2 ruleset comments on how to enable LooseUDP.<br />

• 01/08/02: − Made some slight clarifications to <strong>IP</strong> Alias support<br />

Changes from 11/19/01 to 01/05/02 − 010502 pubsished to the LDP<br />

• 01/05/02: − Added disabled rules to the rc.firewall−2.4−stronger ruleset to support INTERNAL<br />

DHCP server and EXTERNAL access to a WWW server running on the MASQ machine.<br />

• 01/05/02: − Added required changes to the loading of the ip_conntrack_ftp module if people<br />

PORTFW to non−standard FTP ports.<br />

• 01/05/02: − Added an example in the 2.4.x PORTFW section on how to REDIRECT internal traffic<br />

back to an INTERNAL server. This is the same as running REDIR under 2.2.x and 2.0.x kernels.<br />

• 01/05/02: − Added Juanjox mirror URLs to the <strong>HOWTO</strong>.<br />

• 01/04/02: − Clarified and cleaned up the ICQ PORTFW section; Added thoughts on the ip_masq_icq,<br />

PORTFW, and SOCKS solutions<br />

• 01/05/02: − Added Slackware 8.0 to the supported list.<br />

• 01/04/02: − Fixed some spelling mistakes in the 2.4 and 2.2 rulesets. Thanks to Michael Ott for the<br />

sharp eye.<br />

• 12/19/01: − Fixed a minor comment typo in the rc.firewall−2.4 file. Thanks to Bruno Negrao for this<br />

one.<br />

• 12/02/01: − Fixed some minor version typos in the 2.4.x rc.firewall ruleset; Added a missing<br />

$PORTFWIF variable for the 2.4.x PORTFW example. Thanks to Neil Bunn for the errata.<br />

Chapter 8. Miscellaneous 160


• 11/25/01: − Expanded on the ipchains module conflict error messages in Section 5<br />

• 11/23/01: − Updated the <strong>HOWTO</strong> to reflect a new PPTP kernel module for the 2.4.x kernels<br />

• 11/19/01: − Clarified the PPTP supports for 2.4.x kernels<br />

Changes from 08/26/01 to 11/18/01 − 111801 published to the LDP<br />

• 11/12/01: − updated various comments to reflect new versions:linux 2.4.14, iptables 1.2.4, and linux<br />

2.2.20.<br />

• 11/12/01: − Added the rc.firewall−2.4−stronger ruleset to the <strong>HOWTO</strong>, updated the 2.4.x kernel and<br />

<strong>IP</strong>TABLES compiling steps to reflect 2.4.14 and 1.2.4.<br />

• 11/10/01: − Added the directly downloadable versions of the 2.4, 2.4−stronger, 2.2, 2.2−stronger, 2.0,<br />

and and 2.0.x−stronger rulesets to the WWW.<br />

• 11/10/01: − Updated the 2.4.x PORTW example to add the missing FORWARD option.<br />

• 11/10/01: − Updated the DSL−<strong>HOWTO</strong> link in the <strong>HOWTO</strong><br />

• 10/27/01: − Updated the network diagram in section 2.5 to be a little more verbose.<br />

• 09/18/01: − Fixed some broken reference links pointing to the respective 2.4.x, 2.2.x, and 2.0.x kernel<br />

compiling recommendations.<br />

• 09/16/01: − Cleaned up and updated the PORTFW section to also include PREROUTING examples<br />

for 2.4.x kernels.<br />

• 09/13/01: − Updated the <strong>IP</strong>TABLES simple rc.firewall ruleset to 0.62. This fixed a typo on the<br />

MASQ enable line that used eth0 instead of $EXTIF. Thanks to Hafi for reporting this.<br />

• 09/07/01: − It seems that most people who are getting <strong>IP</strong>CHAINS and <strong>IP</strong>TABLES conflicts are<br />

running Redhat 7.1. I have updated section 5 on how to fix this. Thanks to Jason Wenzel for helping<br />

me with this.<br />

• 09/07/01: − Noted that <strong>IP</strong>TABLES v1.2.3 is current version. All versions less than v1.2.3 have an<br />

FTP module bug that can bypass strong firewall rulesets. Please upgrade your copy of <strong>IP</strong>TABLES<br />

now.<br />

• 09/07/01: − Created version numbers for the simple rc.firewall rulesets (<strong>IP</strong>TABLES − v0.61)<br />

(<strong>IP</strong>CHAINS − v1.01) (<strong>IP</strong>FWADM − v2.01). and cleaned up some of the comments in each section.<br />

• 09/07/01: − Added rules to the simple rc.firewall rulesets to flush the various tables. In addition to<br />

this, I have added the use of environment variables and more echo statements in the rulesets to make<br />

things easier to edit and monitor. Thanks to Ian Bishop for the good idea.<br />

• 09/07/01: − Added the use of EXTIF and INTIF interface variables in each of the rc.firewall and<br />

partial firewall rulesets for better clarity (similar to how TrinityOS has been doing for a while now).<br />

Thanks to Sean McKeon for the nudge.<br />

• 09/07/01: − Fixed a typo in the UNIX client configuration section where the network broadcast was<br />

192.168.0.25 instead of .255.<br />

Changes from 2.01 to 2.05 − 08/26/01<br />

• 08/19/01: − Added an additional testing step in Section5 to make sure the rc.firewall file loads ok.<br />

Thanks to Steven Levis for the good idea.<br />

• 08/15/01: − Change the reference for the /etc/hosts file from RFC952 to RFC1035. Thanks to Michael<br />

F. Maggard for the correction.<br />

Changes from 1.96 to 2.01 − 08/12/01<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• 08/12/01: − Updated the basic <strong>IP</strong>TABLES ruleset to 0.60 which fixed a major issue where all<br />

MASQed packets were being dropped. Ultimately, I forgot to add a rule to ACCEPT correct packets<br />

through the forwarding chain.<br />

• − Added an additional rule to log all bogus FORWARD packets<br />

Chapter 8. Miscellaneous 161


• − Load the FTP nat modules now by default<br />

• − Changed the load order of some of the kernel modules to not create bogus error messages<br />

• − Added an <strong>IP</strong>TABLES section on how to MASQ specific hosts vs. an entire subnet<br />

• − Added more MASQ−client compatible operating systems<br />

• 07/19/01: − <strong>The</strong> advanced <strong>IP</strong>CHAINS example for forwarding between multiple interfaces was<br />

missing the critital "−j ACCEPT" to actually let the packets flow. Thanks to Shingo Yamaguchi for<br />

catching this.<br />

Changes from 1.96 to 2.00 − 06/10/01<br />

• 06/21/01: Updated Section 5 (Testing Section) to add an additional test to help users troubleshoot<br />

their MASQ setup. <strong>The</strong>re are now a total of −11− tests. 06/16/01: Updated the intro History section at<br />

the beginning of the <strong>HOWTO</strong>. 06/14/01: Added mirror Netfilter and <strong>IP</strong>CHAINs mirror URLs<br />

06/13/01: Updated the H.323 URL<br />

• 06/10/01: Double DOH! <strong>The</strong> simple rc.firewall script for the 2.4 kernels had two major errors in it.<br />

<strong>The</strong> new version is far more informative and even works! I am continuing to go through the <strong>HOWTO</strong><br />

and cleaning things up but I'm not done quite yet.<br />

• 06/02/01: Updated the lists of known compatible MASQ'ed operating systems (Windows M3, <strong>Linux</strong><br />

2.3, 2.4, etc) Made more references to DHCP and DNS in the various different MASQ client<br />

configuration guides.<br />

• 04/12/01: Thanks to the Joshua X and the other people at Command Prompt, Inc. for the port of the<br />

<strong>HOWTO</strong> from <strong>Linux</strong>Doc to DocBook. Add email list URL to line 126<br />

Changes from 1.90 to 1.95 − 11/11/00<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• A BIG thanks to the Joshua X and the other people at Command Prompt, Inc. for the port of the<br />

<strong>HOWTO</strong> from <strong>Linux</strong>Doc to DocBook.<br />

• Added a quick upfront notice in the intro that running a SINGLE NIC in MASQ mutliple ethernet<br />

segments is NOT recommended and linked to the relivant FAQ entry. Thanks to Daniel Chudnov for<br />

helping the <strong>HOWTO</strong> be more clear.<br />

• Added a pointer in the Intro section to the FAQ section for users looking for how MASQ is different<br />

from NAT and Proxy services.<br />

• Reordered the Kernel requirements sections to be 2.2.x, 2.4.x, 2.0.x<br />

• Expanded the kernel testing in Section 3 to see if a given kernel already supports MASQ or not.<br />

• Reversed the order of the displayed simple MASQ ruleset examples (2.2.x and 2.0.x)<br />

• Cleaned up some formatting issues in the 2.0.x and 2.2.x rc.firewall files<br />

• Noted in the 2.2.x rc.firewall that the defrag option is gone in some distro's proc (Debian,<br />

Turbo<strong>Linux</strong>, etc)<br />

• Added a NOTE #3 to the rc.firewall scripts to include instructions for Pump. Thanks to Ross Johnson<br />

for this one.<br />

• Cleaned up the simple MASQ ruleset examples for both the 2.2.x and 2.2.x kernels<br />

• Updated the simple and stronger <strong>IP</strong>CHAINS and <strong>IP</strong>FWADM rulesets to include the external interface<br />

names (<strong>IP</strong>CHAINS is −i; <strong>IP</strong>FWADM is −W) to avoid some internal traffic MASQing issues.<br />

• Vastly expanded the Section 5 (testing) with even more testing steps with added complete examples<br />

of what the output of the testing commands should look like.<br />

• Moved the H.323 application documentation from NOT supported to Supported. :−)<br />

• Reordered the Multiple LAN section examples (2.2.x then 2.0.x)<br />

• Made some additional clarifications to the Multiple LAN examples<br />

• Fixed a critical typo with multiple NIC MASQing where the network examples had the specified<br />

networks reversed. Thanks to Matt Goheen for catching this.<br />

Chapter 8. Miscellaneous 162


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• Added a little intro to MFW in the PORTFW section.<br />

• Reveresed the 2.0.x and 2.2.x sections for PORTFW<br />

• Updated the news regarding PORTFWing FTP traffic for 2.2.x kernels<br />

NOTE: At this time, there *IS* a BETA level <strong>IP</strong>_MASQ_FTP module<br />

for PORT Forwarding FTP connections 2.2.x kernels which also supports<br />

adding additional PORTFW FTP ports on the fly without the requirement<br />

of unloading and reloading the <strong>IP</strong>_MASQ_FTP module and thus breaking<br />

any existing FTP transfers.<br />

• Added a top level note about PORTFWed FTP support<br />

• Added a noted to the 2.0.x PORTFW'ed FTP example why users DON'T need to PORTFW port 20.<br />

• Updated the PORTFW section to also mention that users can use FTP proxy applications like the one<br />

from SuSe to support PORTFWed FTP−like functionality. Thanks to Stephen Graham for this one.<br />

• Updated the example for how to enable PORTFWed FTP to also include required configurations on<br />

how the ip_masq_ftp module is loaded for users who use multiple PORTs to contact multiple internal<br />

FTP servers. Thanks to Bob Britton for reminding me about this one.<br />

• Added a FAQ entry for users who have embedded ^Ms in their rc.firewall file<br />

• Expanded the FAQ entry talking about how MASQ is different from NAT and Proxy to include some<br />

informative URLs.<br />

• Updated the explanation of the MASQ MTU issue and described the two main explanations for the<br />

issue.<br />

• Clarified that the RFC, PPPoE should only require an MTU of 1492 though some ISPs require a<br />

setting of 1460. Because of this, I have updated the example to show an MTU of 1492.<br />

• Broke out the Windows 9x sections into Win95 and Win98 as they use different settings (DWORD<br />

vs. STRING). I also updated the sections to be clearer and the Registry backup methods have been<br />

updated.<br />

• Fixed a typo where the NT 4.0 Registry entries were backwards (Tcpip/Parameters vs.<br />

Parameters/Tcpip).<br />

• Fixed an issue where the WinNT entry should have been a DWORD and not a STRING.<br />

• A serious thanks goes out to Geoff Mottram for his various PPPoE and various Windows Registry<br />

entry fixes.<br />

• Added an explict URL for Oident in the IRC FAQ entry<br />

• Updated the FAQ section regarding some broken "netstat" versions<br />

• Added new FAQ sections for MASQ accounting ideas and traffic shaping<br />

• Expanded the <strong>IP</strong>ROUTE2 FAQ entry on what Policy−routing is.<br />

• Moved the <strong>IP</strong>ROUTE2 URLs to the 2.2.x Kernel requirements section and also added a few more<br />

URLs as well.<br />

• Corrected the "intnet" varible in the stronger <strong>IP</strong>CHAINS ruleset to reflect the 192.168.0.0 network to<br />

be consistent with the rest of the example. Thanks to Ross Johnson for this one.<br />

• Added a new FAQ section for users asking about forwarding problems between multiple internal<br />

MASQed LANs.<br />

• Added a new FAQ section about users wanting to PORTFW all ports from multiple external <strong>IP</strong><br />

addresses to internal ones. I also touched on users who were trying to PORTFW all ports on multiple<br />

<strong>IP</strong> ALIASed interfaces and also noted the Bridge+Firewall <strong>HOWTO</strong> for DSL and Cablemodem users<br />

who have multiple <strong>IP</strong>s in a non−routed environment.<br />

• Added Mandrake 7.1, Mandrake 7.2, and Slackware 7.1 to the supported list<br />

• Added Redhat 7.0 to the MASQ supported distros. Thanks to Eugene Goldstein for this one.<br />

• Fixed a mathematical error in the "Maximum Throughput" calculation in the FAQ section. Thanks to<br />

Joe White @ ip255@msn.com for this one.<br />

• Fixed the Windows9x MTU changes to be a STRING change and not a DWORD change to the<br />

registry. Thanks to jmoore@sober.com for this one.<br />

Chapter 8. Miscellaneous 163


• Updated the comments in the 2.0.x rc.firewall script to note that the ip_defrag option is for both 2.0<br />

and 2.2 kernels. Thanks to pumilia@est.it for this clarification.<br />

Changes from 1.85 to 1.90 − 07/03/00<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• Updated the URL for TrinityOS to reflect its newest layout<br />

• Caught a typo in the <strong>IP</strong>CHAINS rulesets where I was setting "ip_ip_always_defrag" instead of<br />

"ip_always_defrag"<br />

• <strong>The</strong> URL to Taro Fukunaga was invaild since it was using "mail:" instead of "mailto:"<br />

• Added some clarification to the "Masqing multiple internal interfaces" where some users didn't<br />

understand why eth0 was referenced multiple times.<br />

• Fixed another "space after the EXT<strong>IP</strong> variable" bug in the stronger <strong>IP</strong>CHAINS section. I guess I<br />

missed one.<br />

• In Test #7 of Section 5, I referred users to go back to step #4. That should have been step #6.<br />

• Updated the kernel versions that came with SuSe 5.2 and 6.0<br />

• Fixed a typo (or vs. of) in Section 7.2<br />

• Added Item #9 to the Testing MASQ section to refer users who are still haing MASQ problems to<br />

read the MTU entry in the FAQ<br />

• Improved the itemization in Section 5<br />

• Updated the <strong>IP</strong>CHAINS syntax to show the MASQ/FORWARD table. Before, it was valid to run<br />

"ipchains −F −L" but now only "ipchains −M −L" works.<br />

• Updated the LooseUDP documentation to reflect the new LooseUDP behavior in 2.2.16+ kernels.<br />

Before, it was always enabled, now, it defaults to OFF due to a possible MASQed UDP port scanning<br />

vulnerability. I updated the BASIC and SEMI−STRONG <strong>IP</strong>CHAINS rulesets to reflect this option.<br />

• Updated the recommended 2.2.x kernel to be 2.2.16+ since there is a TCP root exploit vulnerability<br />

on all lesser versions.<br />

• Added Redhat 6.2 to the MASQ supported list<br />

• Updated the link for Sonny Parlin's FWCONFIG to point to fBuilder.<br />

• Updated the various examples of <strong>IP</strong> addresses from 111.222.333.444 to be 111.222.121.212 and<br />

within a valid <strong>IP</strong> address range<br />

• Updated the URL for the BETA H.323 MASQ module<br />

• Finally updated the MTU FAQ section to help out PPPoE DSL and Cablemodem users. Basically,<br />

Section 7.15 now reflects the fact that users can also change the MTU settings of all of their<br />

INTERNAL machines to solve the dreaded MASQ MTU issue.<br />

• Added a clarification to the PORTFW section that PORTFWed connections which work for<br />

EXTERNAL clients but will not work for INTERNAL clients. If you also need INTERNAL portfw,<br />

you will need to also implement the REDIR tool as well. I also noted that this issue is fixed in the<br />

2.4.x kernels with Netfilter.<br />

• I also added a technical explanation from Juanjo to the end of the PORTFW section to why this<br />

senario doesn't work properly.<br />

• Updated all of the <strong>IP</strong>CHAINS URLs to point to Paul Rusty's new site at<br />

http://www.netfilter.org/ipchains/<br />

• Updated Paul Rustys email address<br />

• Added a new FAQ section for users whose connections remain idle for a long period of time and<br />

PORTFWed connections no longer work.<br />

• Updated all the URLs to the LDP that pointed to metalab.unc.edu to the new site of linuxdoc.org<br />

• Updated the Netfilter URLs to point to renamed <strong>HOWTO</strong>s, etc.<br />

• I also updated the status of the 2.4.x support to note that I *will* add full Netfilter support to this<br />

<strong>HOWTO</strong> and if the time comes, then split that support off into a different <strong>HOWTO</strong>.<br />

• Updated the 2.4.x Requirements section to reflect how NetFilter has changed compared to<br />

<strong>IP</strong>FWADM and <strong>IP</strong>CHAINS and gave a PROs/CONs list of new features and changes to old<br />

Chapter 8. Miscellaneous 164


ehaviors.<br />

• Added a TCP/<strong>IP</strong> math example to the "My MASQ connection is slow" FAQ entry to better explain<br />

what a user should expect performance wise.<br />

• Updated the <strong>HOWTO</strong> to reflect that newer versions of the "pump" DHCP client now can run scripts<br />

upon bringup, lease renew, etc.<br />

• Updated the PORTFWing of FTP to reflect that several users say they can successfully forward FTP<br />

traffic to internal machines without the need of a special ip_masq_ftp module. I have made the<br />

<strong>HOWTO</strong> reflect that users should try it without the modified module first and then move to the patch<br />

if required.<br />

Changes from 1.82 to 1.85 − 05/29/00<br />

• Ambrose Au's name has been taken off the title page as David Ranch has been the primary maintainer<br />

for the <strong>HOWTO</strong> for over a year. Ambrose will still be involved with the WWW site though.<br />

• Deleted a stray SPACE in section 6.4<br />

• Re−ordered the compatible MASQ'ed OS section and added instructions for setting up a AS/400<br />

system running on OS/400. Thanks to jaco@libero.it for the notes.<br />

• Added an additional PORFW−FTP patch URL for FTP access if HTTP access fails.<br />

• Updated the kernel versions for Redhat 5.1 & 6.1 in the FAQ<br />

• Added FloppyFW to the list of MASQ−enabled <strong>Linux</strong> distros<br />

• Fixed an issue in the Stronger <strong>IP</strong>FWADM rule set where there were spaces between "ppp_ip" and the<br />

"=".<br />

• In the kernel compiling section for 2.2.x kernels, I removed the reference to enable<br />

"CONFIG_<strong>IP</strong>_ALWAYS_DEFRAG". This option was removed from the compiling section and<br />

enabled by default with MASQ enabled in 2.2.12.<br />

• Because of the above change in the kernel behavior, I added the enabling of ip_always_defrag to all<br />

the rc.firewall examples.<br />

• Updated the status of support for H.323. <strong>The</strong>re are now ALPHA versions of modules to support<br />

H.323 on both 2.0.x and 2.2.x kernels.<br />

• Added Debian v2.2 to the supported MASQ distributions list<br />

• Fixed a long standing issue where the section that covered explict filtering of <strong>IP</strong> addresses for<br />

<strong>IP</strong>CHAINS had old <strong>IP</strong>FWADM syntax. I've also cleaned this section up a little and made it<br />

understandable.<br />

• Doh! Added Juan Ciarlante's URL to the important MASQ resources section. Man.. you guys need to<br />

make me more honest than this!!<br />

• Updated the <strong>HOWTO</strong> to reflect kernels 2.0.38 and 2.2.15<br />

• Reversed the order shown to compile kernels to show 2.2.x kernels first as 2.0.x is getting pretty old.<br />

• Updated the 2.2.x kernel compiling section to reflect the changed options for the latter 2.2.x kernels.<br />

• Added a a possible solution for users that fail to get past MASQ test #5.<br />

Changes from 1.81 to 1.82 − 01/22/00<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• Added a missing subsection for /proc/sys/net/ipv4/ip_dynaddr in the stronger <strong>IP</strong>CHAINS ruleset.<br />

Section 6.5<br />

• Changed the <strong>IP</strong> Masq support for Debian 2.1 to YES<br />

• Reorganized and updated the "Masq is slow" FAQ section to include fixing Ethernet speed and<br />

duplex issues.<br />

• Added a link to Donald Becker's MII utilities for Ethernet NIC cards<br />

• Added a missing ")" for the 2.2.x section (previously fixed it only for the 2.0.x version) to the ICQ<br />

portfw script and changed the evaluation from −lt to −le<br />

• Added Caldera eServer v2.3 to the MASQ supported list<br />

Chapter 8. Miscellaneous 165


• Added Mandrake 6.0, 6.1, 7.0 to the MASQ supported list<br />

• Added Slackware v7.0 to the MASQ supported list<br />

• Added Redhat 6.1 to the MASQ supported list<br />

• Added Turbo<strong>Linux</strong> 4.0 Lite to the MASQ supported list<br />

• Added SuSe 6.3 to the MASQ supported list<br />

• Updated the recommended stable 2.2.x kernel to be anything newer than 2.2.11<br />

• In section 3.3, the <strong>HOWTO</strong> forgot how to tell the user how to load the /etc/rc.d/rc.firewall upon each<br />

reboot. This has now been covered for Redhat (and Redhat−based distros) and Slackware.<br />

• Added clarification in the Windows WFWG v3.x and NT setup sections why users should NOT<br />

configure the DHCP, WINS, and Forwarding options.<br />

• Added a FAQ section on how to fix FTP problems with MASQed machines.<br />

• Fixed a typo in the Stronger firewall rulesets. <strong>The</strong> "extip" variabl cannot have the SPACE between the<br />

variable name and the "=" sign. Thanks to johnh@mdscomp.com for the sharp eye.<br />

• Updated the compatibly section: Mandrake 7.0 is based on 2.2.14 and Turbo<strong>Linux</strong> v6.0 runs 2.2.12<br />

Changes from 1.80 to 1.81 − 01/09/00<br />

• Updated the ICQ section to reflect that the new ICQ Masq module supports file transfer and real−time<br />

chat. <strong>The</strong> 2.0.x module still has those limitations.<br />

• Updated Steven E. Grevemeyer's email address. He is the maintainer of the <strong>IP</strong> Masq Applications<br />

page.<br />

• Fixed a few lines that were missing the work AREN'T for the "setsockopt" errors.<br />

• Updated a error the strong <strong>IP</strong>CHAINS ruleset where it was using the variable name "ppp_ip" instead<br />

of "extip".<br />

• Fixed a "." vs a "?" typo in section 3.3.1 in the DHCP comment section.<br />

• Added a missing ")" to the ICQ portfw script and changed the evaluation from −lt to −le<br />

• Updated the Quake Module syntax to NOT use the "ports=" verbage<br />

Changes from 1.79 to 1.80 − 12/26/99<br />

• Fixed a space typo when setting the "ppp_ip" address.<br />

• Fixed a typo in the simple <strong>IP</strong>CHAINS ruleset. "deny" to "DENY"<br />

• Updated the URLs for Bjorn's "modutils" for <strong>Linux</strong><br />

• Added verbage about NetFilter and <strong>IP</strong>Tables and gave URLs until it is added to this <strong>HOWTO</strong> or a<br />

different <strong>HOWTO</strong>.<br />

• Updated the simple /etc/rc.d/rc.firewall examples to notify users about the old Quake module bug.<br />

• Updated the STRONG <strong>IP</strong>FWADM /etc/rc.d/rc.firewall to clarify users about dynamic <strong>IP</strong> addresses<br />

(PPP & DHCP), newer DHCPCD syntax, and the old Quake module bug.<br />

• Updated the STRONG <strong>IP</strong>CHAINS /etc/rc.d/rc.firewall to ADD a missing section on dynamic <strong>IP</strong><br />

addresses (PPP & DHCP) and the old Quake module bug.<br />

• Added a note in the "Applications that DO NOT work" section that there IS a beta module for<br />

Microsoft NetMeeting (H.323 based) v2.x on 2.0.x kernels. <strong>The</strong>re is NO versions available for<br />

Netmeeting 3.x and/or 2.2.x kernels as of yet.<br />

Changes from 1.78 to 1.79 − 10/21/99<br />

• Updated the <strong>HOWTO</strong> name to reflect that it isn't a MINI anymore!<br />

Changes from 1.77 to 1.78 − 8/24/99<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• Fixed a typo in "Section 6.6 − Multiple Internal Networks" where the −a policy was ommited.<br />

Chapter 8. Miscellaneous 166


• Deleted the 2.2.x kernel configure option "Drop source routed frames" since it is now enabled by<br />

default and the kernel compile option was removed.<br />

• Updated the 2.2.x and all other <strong>IP</strong>CHAINS sections to notify users of the <strong>IP</strong>CHAINS fragmentation<br />

bug.<br />

• Updated all of the URLs pointing at Lee Nevo's old <strong>IP</strong> Masq Applications page to Seg's new page.<br />

Changes from 1.76 to 1.77 − 7/26/99<br />

• Fixed a typo in the Port fowarding section that used "ipmasqadm ipportfw −C" instead of "ipmasqadm<br />

portfw −f"<br />

Changes from 1.75 to 1.76 − 7/19/99<br />

• Updated the "ipfwadm: setsockopt failed: Protocol not available" message in the FAQ to be clearer<br />

instead of making the user hunt for the answer in the Forwarders section.<br />

• Fixed incorrect syntax in section 6.7 for <strong>IP</strong>MASQADM and "portfw"<br />

Changes from 1.72 to 1.75 − 6/19/99<br />

<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• Fixed the quake module port setup order for the weak <strong>IP</strong>FWADM & <strong>IP</strong>CHAINS ruleset and the<br />

strong <strong>IP</strong>FWADM ruleset as well.<br />

• Added a user report about port forwarding ICQ 4000 directly in and using ICQ's default settings<br />

WITHOUT enabling the "Non−Sock" proxy setup.<br />

• Updated the URLs for the <strong>IP</strong>MASQADM tool<br />

• Added references to Taro Fukunaga, tarozax@earthlink.net for his Mk<strong>Linux</strong> port of the <strong>HOWTO</strong><br />

• Updated the blurb about Sonny Parlin's FWCONFIG tool to note new <strong>IP</strong>CHAINS support<br />

• Noted that Fred Vile's patch for portfw'ed FTP access is ONLY available for the 2.0.x kernels<br />

• Updated the 2.2.x kernel step with a few clarifications on the Experiemental tag<br />

• Added Glen Lamb's name to the credits for the LooseUDP patch<br />

• Added a clarification on installing the LooseUDP patch that it should use "cat" for non−compressed<br />

patches.<br />

• Fixed a typo in the <strong>IP</strong>AUTO FAQ section<br />

• I had the DHCP client port numbers reversed for the <strong>IP</strong>FWADM and <strong>IP</strong>CHAINS rulesets. <strong>The</strong> order I<br />

had was if your <strong>Linux</strong> server was a DHCP SERVER.<br />

• Added explict /sbin path to all weak and strong ruleset examples.<br />

• Made some clarifications in the strong <strong>IP</strong>FWADM section regarding Dynamic <strong>IP</strong> addresses for PPP<br />

and DHCP users. I also noted that the strong rulesets should be re−run when PPP comes up or when a<br />

DHCP lease is renewed.<br />

• Added references in the 2.2.x requirements, updated the ICQ FAQ section, and added Andrew<br />

Deryabin to the credits section for his ICQ MASQ module.<br />

• Added some clarifcations to the FAQ section explaining why the 2.1.x and 2.2.x kernels went to<br />

<strong>IP</strong>CHAINS.<br />

• Added a little FAQ section on Microsoft File/Print/Domain services (Samba) through a MASQ server.<br />

I also added an URL to a Microsoft Knowledge based document for more details.<br />

• Added clarifications to the FAQ section that NO Debian distribution supports <strong>IP</strong> masq out of the box.<br />

• Updated the supported MASQ distributions in the FAQ section.<br />

• Added to the Aliased NIC section of the FAQ that you CANNOT masq out of an aliased interface.<br />

• Wow.. never caught this before but the "ppp−ip" variable in the strong ruleset section is an invalid<br />

variable name! It has been renamed to "ppp_ip"<br />

• In both the <strong>IP</strong>FWADM and <strong>IP</strong>CHAINS simple ruleset setup areas, I had a commented out section on<br />

enabling DHCP traffic. Problem is, it was below the final reject line! Doh! I moved both up a section.<br />

Chapter 8. Miscellaneous 167


<strong>Linux</strong> <strong>IP</strong> <strong>Masquerade</strong> <strong>HOWTO</strong><br />

• In the simple <strong>IP</strong>CHAINS setup, the #d out line for DHCP users, I was using the <strong>IP</strong>FWADM "−W"<br />

command instead of <strong>IP</strong>CHAINS's "−i" parameter.<br />

• Added a little blurb to the Forwarders section the resolution to the famous "ipfwadm: setsockopt<br />

failed: Protocol not available" error. This also includes a little /proc test to let users confirm if<br />

<strong>IP</strong>PORTFW is enabled in the kernel. I also added this error to a FAQ section for simple searching.<br />

• Added a Strong <strong>IP</strong>CHAINS ruleset to the <strong>HOWTO</strong><br />

• Added a FAQ section explaining the "kernel: ip_masq_new(proto=UDP): no free ports." error.<br />

• Added an example of scripting <strong>IP</strong>MASQADM PORTFW rules<br />

• Updated a few of the <strong>Linux</strong> <strong>Documentation</strong> <strong>Project</strong> (LDP) URLs<br />

• Added Quake III support in the module loading sections of all the rc.firewall rulesets.<br />

• Fixed the <strong>IP</strong>MASQADM forwards for ICQ<br />

• 1.72 − 4/14/99 − Dranch: Added a large list of Windows NAT/Proxy alternatives with rough pricing<br />

and URLs to the FAQ.<br />

• 1.71 − 4/13/99 − Dranch: Added <strong>IP</strong>CHAINS setups for multiple internal MASQed networks.<br />

Changed the ICQ setup to use ICQ's default 60 second timeout and changed <strong>IP</strong>FWADM/<strong>IP</strong>CHAINS<br />

timeout to 160 seconds. Updated the MASQ and MASQ−DEV email list and archive subscription<br />

instructions.<br />

• 1.70 − 3/30/99 − Dranch: Added two new FAQ sections that cover SMTP/POP−3 timeout problems<br />

and how to masquerade multiple internal networks out onto different external <strong>IP</strong> addresses with<br />

<strong>IP</strong>ROUTE2.<br />

• 1.65 − 3/29/99 − Dranch: Typo fixes, clarifications of required 2.2.x kernel options, added dynamic<br />

PPP <strong>IP</strong> address support to the strong firewall section, additional quake II module ports, noted that the<br />

LooseUDP patch is built into later 2.2.x kernels and its from Glenn Lamb and not Dan Kegel, added<br />

more game info in the compatibility section.<br />

• 1.62 − Dranch: Make the final first−draft changes to the doc and now announce it in the MASQ email<br />

list.<br />

• 1.61 − Dranch: Made editorial changes, cleaned things up and fixed some errors in the Windows95<br />

and NT setups.<br />

• 1.58 − Dranch: Addition of the port forwarding sections; LooseUDP setup; Ident servers for IRC<br />

users, how to read firewall logs, deleted the CuSeeme Mini−<strong>HOWTO</strong> since it is rarely used.<br />

• 1.55 − Dranch: Complete overhaul, feature and FAQ addition, and editing sweep of the v1.50<br />

<strong>HOWTO</strong>. Completed the 2.2.x kernel and <strong>IP</strong>CHAINS configurations. Did a conversion from<br />

<strong>IP</strong>AUTOFW to <strong>IP</strong>PORTFW for the examples that applied. Added many URLs to various other<br />

documentation and utility sites. <strong>The</strong>re are so many changes.. I hope everyone likes it. Final publishing<br />

of this new rev of the <strong>HOWTO</strong> to the LDP project won't happen until the doc is looked over and<br />

approved by the <strong>IP</strong> MASQ email list (then v2.00).<br />

• 1.50 − Ambrose: A serious update to the <strong>HOWTO</strong> and the initial addition of the 2.2.0 and <strong>IP</strong>CHAINS<br />

configurations.<br />

• 1.20 − Ambrose: One of the more recent <strong>HOWTO</strong> versions that solely dealt with < 2.0.x kernels and<br />

<strong>IP</strong>FWADM.<br />

Chapter 8. Miscellaneous 168

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!