View | Details | Raw Unified | Return to bug 75422
Collapse All | Expand All

(-)chapter.sgml Wed Dec 22 21:18:52 2004 (-191 / +198 lines)
Lines 114-120 Link Here
114
    <para>There are two basic ways to create firewall rulesets:
114
    <para>There are two basic ways to create firewall rulesets:
115
      <quote>inclusive</quote> or <quote>exclusive</quote>.  An
115
      <quote>inclusive</quote> or <quote>exclusive</quote>.  An
116
      exclusive firewall allows all traffic through except for the
116
      exclusive firewall allows all traffic through except for the
117
      traffic matching the ruleset.  An inclusive firewall does the
117
      traffic matching the rule set.  An inclusive firewall does the
118
      reverse.  It only allows traffic matching the rules through and
118
      reverse.  It only allows traffic matching the rules through and
119
      blocks everything else.</para>
119
      blocks everything else.</para>
120
120
Lines 137-154 Link Here
137
  <sect1 id="firewalls-apps">
137
  <sect1 id="firewalls-apps">
138
    <title>Firewall Software Applications</title>
138
    <title>Firewall Software Applications</title>
139
139
140
    <para>&os; has three different firewall software products built into
140
    <para>&os; has three different firewall software products built
141
      the base system. They are IPFILTER (also known as IPF),
141
      into the base system. They are IPFILTER (also known as IPF),
142
      IPFIREWALL (also known as IPFW) and PF (OpenBSD's PacketFilter).  IPFIREWALL has the built
142
      IPFIREWALL (also known as IPFW) and PF (OpenBSD's PacketFilter).
143
      in DUMMYNET traffic shaper facilities for controlling bandwidth
143
      IPFIREWALL has the built in DUMMYNET traffic shaper facilities
144
      usage. IPFILTER does not have a built in traffic shaper facility
144
      for controlling bandwidth usage. IPFILTER does not have a built
145
      for controlling bandwidth usage, but the ALTQ port application
145
      in traffic shaper facility for controlling bandwidth usage, but
146
      can be used to accomplish the same function.  The DUMMYNET
146
      the ALTQ framework can be used to accomplish the same
147
      feature and <acronym>ALTQ</acronym> is generally useful only to
147
      function.  The DUMMYNET feature and <acronym>ALTQ</acronym> is
148
      large ISPs or commercial users.  IPF, IPFW and PF use rules to
148
      generally useful only to large ISPs or commercial users.  IPF,
149
      control the access of packets to and from your system, although
149
      IPFW and PF use rules to control the access of packets to and
150
      they go about it different ways and have different rule
150
      from your system, although they go about it different ways and
151
      syntaxes.</para>
151
      have different rule syntaxes.</para>
152
152
153
    <para>The IPFW sample rule set (found in
153
    <para>The IPFW sample rule set (found in
154
      <filename>/etc/rc.firewall</filename>) delivered in the basic
154
      <filename>/etc/rc.firewall</filename>) delivered in the basic
Lines 197-205 Link Here
197
      known as <acronym>PF</acronym> was ported to &os;&nbsp;5.3.
197
      known as <acronym>PF</acronym> was ported to &os;&nbsp;5.3.
198
      <acronym>PF</acronym> is a complete, fully featured firewall
198
      <acronym>PF</acronym> is a complete, fully featured firewall
199
      that contains <acronym>ALTQ</acronym> for bandwidth usage
199
      that contains <acronym>ALTQ</acronym> for bandwidth usage
200
      management in a way similar to the dummynet provides in
200
      management in a way similar to what DUMMYNET provides for
201
      <acronym>IPFW</acronym>.  The OpenBSD project does an
201
      <acronym>IPFW</acronym>.  The OpenBSD project does an
202
      outstanding job of maintaining the PF users' guide that it will
202
      outstanding job of maintaining the PF user's guide that it will
203
      not be made part of this handbook firewall section as that would
203
      not be made part of this handbook firewall section as that would
204
      just be duplicated effort.</para>
204
      just be duplicated effort.</para>
205
205
Lines 223-231 Link Here
223
    <sect2>
223
    <sect2>
224
      <title>Enabling PF</title>
224
      <title>Enabling PF</title>
225
      <para>PF is included in the basic &os; install for versions newer than
225
      <para>PF is included in the basic &os; install for versions newer than
226
        5.3 as a separate run time loadable module. PF will dynamically load
226
        5.3 as a separate run time loadable module. The system will
227
               its kernel loadable module when the rc.conf statement
227
        dynamically load PF kernel loadable module when the rc.conf
228
        <literal>pf_enable="YES"</literal> is used. The
228
        statement <literal>pf_enable="YES"</literal> is used. The
229
        loadable module was created with &man.pflog.4; logging
229
        loadable module was created with &man.pflog.4; logging
230
        enabled.</para>
230
        enabled.</para>
231
    </sect2>
231
    </sect2>
Lines 256-262 Link Here
256
      <para><literal>device pfsync</literal> enables the optional
256
      <para><literal>device pfsync</literal> enables the optional
257
        &man.pfsync.4; pseudo network device that is used to monitor
257
        &man.pfsync.4; pseudo network device that is used to monitor
258
        <quote>state changes</quote>. As this is not part of the loadable
258
        <quote>state changes</quote>. As this is not part of the loadable
259
        module one has to build a custom kernel to use it.</para>
259
        module a custom kernel is needed to use it.</para>
260
260
261
      <para>These settings will take affect only after you have built and
261
      <para>These settings will take affect only after you have built and
262
                installed a kernel with them set.</para>
262
                installed a kernel with them set.</para>
Lines 288-298 Link Here
288
    <title>The IPFILTER (IPF) Firewall</title>
288
    <title>The IPFILTER (IPF) Firewall</title>
289
289
290
    <para>The author of IPFILTER is Darren Reed. IPFILTER is not
290
    <para>The author of IPFILTER is Darren Reed. IPFILTER is not
291
      operating system dependent. IPFILTER is a open source
291
      operating system dependent: is a open source application and has
292
      application and has been ported to &os;, NetBSD, OpenBSD, SunOS,
292
      been ported to &os;, NetBSD, OpenBSD, SunOS, HP/UX, and Solaris
293
      HP/UX, and Solaris operating systems. IPFILTER is actively being
293
      operating systems. IPFILTER is actively being supported and
294
      supported and maintained, with updated versions being released
294
      maintained, with updated versions being released regularly.</para>
295
      regularly.</para>
296
295
297
    <para>IPFILTER is based on a kernel-side firewall and
296
    <para>IPFILTER is based on a kernel-side firewall and
298
      <acronym>NAT</acronym> mechanism that can be controlled and
297
      <acronym>NAT</acronym> mechanism that can be controlled and
Lines 326-335 Link Here
326
      and also control the services which can originate from the
325
      and also control the services which can originate from the
327
      public Internet accessing your private network. Everything else
326
      public Internet accessing your private network. Everything else
328
      is blocked and logged by default design. Inclusive firewalls are
327
      is blocked and logged by default design. Inclusive firewalls are
329
      much, much more secure than exclusive firewall rule sets and is
328
      much, much more secure than exclusive ones and only this rule
330
      the only rule set type covered here in.</para>
329
      set type is covered here.</para>
331
330
332
    <para>For detailed explanation of the legacy rules processing
331
    <para>For a detailed explanation of the legacy rules processing
333
      method see: <ulink
332
      method see: <ulink
334
      url="http://www.obfuscation.org/ipf/ipf-howto.html#TOC_1"></ulink>
333
      url="http://www.obfuscation.org/ipf/ipf-howto.html#TOC_1"></ulink>
335
      and <ulink
334
      and <ulink
Lines 340-355 Link Here
340
      url="http://www.phildev.net/ipf/index.html"></ulink>.</para>
339
      url="http://www.phildev.net/ipf/index.html"></ulink>.</para>
341
340
342
    <sect2>
341
    <sect2>
343
      <title>Enabling IPF</title>
342
      <title>Enabling IPF</title> 
344
      <para>IPF is included in the basic &os; install as a separate
343
      <para>IPF is included in the basic &os; install as a separate
345
        run time loadable module. IPF will dynamically load its kernel
344
        run time loadable module. The system will dynamically load IPF
346
        loadable module when the rc.conf statement <literal>
345
        kernel loadable module when the rc.conf statement <literal>
347
        ipfilter_enable="YES"</literal> is used. The loadable
346
        ipfilter_enable="YES"</literal> is used. The loadable module
348
        module was created with logging enabled and the <literal>default
347
        was created with logging enabled and the <literal>default pass
349
        pass all</literal> options. You do not need to compile IPF into
348
        all</literal> option. You do not need to compile IPF into the
350
        the &os; kernel just to change the default to <literal>block all
349
        &os; kernel just to change the default to <literal>block all
351
        </literal>, you can do that by just coding a block all rule at
350
        </literal>, you can do that by just coding a <literal>block
352
        the end of your rule set.</para>
351
        all</literal> rule at the end of your rule set.</para> 
353
    </sect2>
352
    </sect2>
354
353
355
    <sect2>
354
    <sect2>
Lines 369-376 Link Here
369
options IPFILTER_LOG
368
options IPFILTER_LOG
370
options IPFILTER_DEFAULT_BLOCK</programlisting>
369
options IPFILTER_DEFAULT_BLOCK</programlisting>
371
370
372
      <para><literal>options IPFILTER</literal> tells the compile
371
      <para><literal>options IPFILTER</literal> enables support for
373
        to include IPFILTER as part of its core kernel.</para>
372
      the <quote>IPFILTER</quote> firewall.</para>
374
373
375
      <para><literal>options IPFILTER_LOG</literal> enables the
374
      <para><literal>options IPFILTER_LOG</literal> enables the
376
        option to have IPF log traffic by writing to the ipl packet
375
        option to have IPF log traffic by writing to the ipl packet
Lines 416-430 Link Here
416
415
417
     <programlisting><command>ipf -Fa -f /etc/ipf.rules</command></programlisting>
416
     <programlisting><command>ipf -Fa -f /etc/ipf.rules</command></programlisting>
418
417
419
     <para><option>-Fa</option> means flush all internal rules tables.</para>
418
     <para><option>-Fa</option> means "flush all internal rules tables".</para>
420
     <para><option>-f</option> means this is the file to read for the rules to load.</para>
419
     <para><option>-f</option> means "this is the file to read for the
420
     rules to load".</para>
421
421
422
     <para>This gives you the ability to make changes to their custom
422
     <para>This gives you the ability to make changes to a custom
423
       rules file, run the above IPF command thus updating the running
423
       rules file. Run the above IPF command thus updating the running
424
       firewall with a fresh copy of all the rules without having to
424
       firewall with a fresh copy of all the rules without having to
425
       reboot the system. This method is very convenient for testing new
425
       reboot the system. This method is very convenient for testing
426
       rules as the procedure can be executed as many times as needed.
426
       new rules as the procedure can be executed as many times as
427
       </para>
427
       needed.  </para>
428
     <para>See the &man.ipf.8; manual page for details on the other flags
428
     <para>See the &man.ipf.8; manual page for details on the other flags
429
       available with this command.</para>
429
       available with this command.</para>
Lines 433-439 Link Here
433
       standard text file. It will not accept a rules file written as a
433
       standard text file. It will not accept a rules file written as a
434
       script with symbolic substitution.</para>
434
       script with symbolic substitution.</para>
435
435
436
     <para>There is a way to build IPF rules that utilities the power of
436
     <para>There is a way to build IPF rules that use the power of
437
       script symbolic substitution.  For more information, see <xref
437
       script symbolic substitution.  For more information, see <xref
438
       linkend="firewalls-ipfw-rules-script">.</para>
438
       linkend="firewalls-ipfw-rules-script">.</para>
439
     </sect2>
439
     </sect2>
Lines 557-563 Link Here
557
     <sect2>
557
     <sect2>
558
       <title>IPMON Logging</title>
558
       <title>IPMON Logging</title>
559
559
560
       <para>Syslogd uses its own special method for segregation of log
560
       <para>Syslogd uses its own special method for aggregation of log
561
         data. It uses special grouping called <quote>facility</quote>
561
         data. It uses special grouping called <quote>facility</quote>
562
         and <quote>level.</quote> IPMON in <option>-Ds</option> mode uses Local0 as the
562
         and <quote>level.</quote> IPMON in <option>-Ds</option> mode uses Local0 as the
563
         <quote>facility</quote> name. All IPMON logged data goes to
563
         <quote>facility</quote> name. All IPMON logged data goes to
Lines 575-582 Link Here
575
575
576
       <programlisting><command>touch /var/log/ipfilter.log</command></programlisting>
576
       <programlisting><command>touch /var/log/ipfilter.log</command></programlisting>
577
577
578
       <para>The syslog function is controlled by definition statements
578
       <para>The syslog function is controlled by definition
579
         in the <filename>/etc/syslog.conf</filename> file. The <filename>syslog.conf</filename> file offers
579
         statements in the <filename>/etc/syslog.conf</filename>
580
         file. The <filename>syslog.conf</filename> file offers
580
         considerable flexibility in how syslog will deal with system
581
         considerable flexibility in how syslog will deal with system
581
         messages issued by software applications like IPF.</para>
582
         messages issued by software applications like IPF.</para>
582
583
Lines 585-600 Link Here
585
586
586
       <programlisting>Local0.* /var/log/ipfilter.log</programlisting>
587
       <programlisting>Local0.* /var/log/ipfilter.log</programlisting>
587
588
588
       <para>The <literal>Local0.*</literal> means to write all the logged messages to the
589
       <para>The <literal>Local0.*</literal> means to write all the
589
         coded file location.</para>
590
         logged messages to the coded file location.</para>
590
591
591
       <para>To activate the changes to <filename>/etc/syslog.conf
592
       <para>To activate the changes made to
592
         </filename> you can reboot or bump the syslog task into
593
         <filename>/etc/syslog.conf </filename> you can reboot or bump
593
         re-reading <filename>/etc/syslog.conf</filename> by <command>
594
         the syslog task into re-reading
594
         kill -HUP &lt;pid&gt;</command>. You get the pid (i.e. process
595
         <filename>/etc/syslog.conf</filename> by
595
         number) by listing the tasks with the <command>ps -ax</command>
596
         <command>/etc/rc.d/syslogd restart</command> or <command>kill
596
         command. Find syslog in the display and the pid is the number
597
         -HUP <literal>pid</literal></command> on &os; 4.X systems. You
597
         in the left column.</para>
598
         get the pid (i.e. process number) by listing the tasks with
599
         the <command>ps -ax</command> command. Find syslog in the
600
         display and the pid is the number in the left column.</para>
598
601
599
       <para>Do not forget to change <filename>/etc/newsyslog.conf
602
       <para>Do not forget to change <filename>/etc/newsyslog.conf
600
         </filename> to rotate the new log you just created above.
603
         </filename> to rotate the new log you just created above.
Lines 643-649 Link Here
643
         </listitem>
646
         </listitem>
644
647
645
         <listitem>
648
         <listitem>
646
           <para>The addresses. This is actually three fields: the
649
           <para>The addresses. This is actuactually three fields: the
647
             source address and port (separated by a comma), the ->
650
             source address and port (separated by a comma), the ->
648
             symbol, and the destination address and port.
651
             symbol, and the destination address and port.
649
             209.53.17.22,80 -> 198.73.220.17,1722.</para>
652
             209.53.17.22,80 -> 198.73.220.17,1722.</para>
Lines 703-709 Link Here
703
<programlisting>############# Start of IPF rules script ########################
706
<programlisting>############# Start of IPF rules script ########################
704
707
705
oif="dc0"            # name of the outbound interface
708
oif="dc0"            # name of the outbound interface
706
odns="192.0.2.11"    # ISP's dns server IP address Symbolic&gt;
709
odns="192.0.2.11"    # ISP's DNS server IP address
707
myip="192.0.2.7"     # My Static IP address from ISP
710
myip="192.0.2.7"     # My Static IP address from ISP
708
ks="keep state"
711
ks="keep state"
709
fks="flags S keep state"
712
fks="flags S keep state"
Lines 716-722 Link Here
716
# after the EOF line to work correctly.
719
# after the EOF line to work correctly.
717
/sbin/ipf -Fa -f - &lt;&lt; EOF
720
/sbin/ipf -Fa -f - &lt;&lt; EOF
718
721
719
# Allow out access to my ISP's Domain name server.
722
# Allow out access to my ISP's Domain Name server.
720
pass out quick on &dollar;oif proto tcp from any to &dollar;odns port = 53 &dollar;fks
723
pass out quick on &dollar;oif proto tcp from any to &dollar;odns port = 53 &dollar;fks
721
pass out quick on &dollar;oif proto udp from any to &dollar;odns port = 53 &dollar;ks
724
pass out quick on &dollar;oif proto udp from any to &dollar;odns port = 53 &dollar;ks
722
725
Lines 728-737 Link Here
728
EOF
731
EOF
729
################## End of IPF rules script ########################</programlisting>
732
################## End of IPF rules script ########################</programlisting>
730
733
731
       <para>That is all there is to it. The rules are not important in
734
       <para>That is all there is to it. The rules are not important
732
         this example, how the Symbolic substitution field are populated
735
         in this example, how the Symbolic substitution field are
733
         and used are. If the above example was in <filename>/etc/ipf.rules.script</filename>
736
         populated and used are. If the above example was in
734
         file, you could reload these rules by entering this on the command
737
         <filename>/etc/ipf.rules.script</filename> file, you could
738
         reload these rules by entering the following on the command
735
         line:</para>
739
         line:</para>
736
740
737
       <programlisting><command>sh /etc/ipf.rules.script</command>
741
       <programlisting><command>sh /etc/ipf.rules.script</command>
Lines 761-767 Link Here
761
765
762
       <programlisting><command>chmod 700 /usr/local/etc/rc.d/ipf.loadrules.sh</command></programlisting>
766
       <programlisting><command>chmod 700 /usr/local/etc/rc.d/ipf.loadrules.sh</command></programlisting>
763
767
764
       <para>Now when you system boots your IPF rules will be loaded
768
       <para>Now when your system boots, your IPF rules will be loaded
765
         using the script.</para>
769
         using the script.</para>
766
770
767
     </sect2>
771
     </sect2>
Lines 774-780 Link Here
774
         session conversation. The firewall rule set processes the
778
         session conversation. The firewall rule set processes the
775
         packet 2 times, once on its arrival from the public Internet
779
         packet 2 times, once on its arrival from the public Internet
776
         host and again as it leaves for its return trip back to the
780
         host and again as it leaves for its return trip back to the
777
         public Internet host. Each tcp/ip service (i.e. telnet, www,
781
         public Internet host. Each TCP/IP service (i.e. telnet, www,
778
         mail, etc.) is predefined by its protocol, source and
782
         mail, etc.) is predefined by its protocol, source and
779
         destination IP address, or the source and destination port
783
         destination IP address, or the source and destination port
780
         number. This is the basic selection criteria used to create
784
         number. This is the basic selection criteria used to create
Lines 814-822 Link Here
814
         rule wins</quote> logic. For the complete legacy rule syntax
818
         rule wins</quote> logic. For the complete legacy rule syntax
815
         description see the &man.ipf.8; manual page.</para>
819
         description see the &man.ipf.8; manual page.</para>
816
820
817
       <para><literal>#</literal> is used to mark the start of a comment and may appear at
821
       <para><literal>#</literal> is used to mark the start of a
818
         the end of a rule line or on its own lines. Blank lines are
822
         comment and may appear at the end of a rule line or on its
819
         ignored.</para>
823
         own lines. Blank lines are ignored.</para>
820
824
821
       <para>Rules contain keywords, These keywords have to be coded in
825
       <para>Rules contain keywords, These keywords have to be coded in
822
         a specific order from left to right on the line. Keywords are
826
         a specific order from left to right on the line. Keywords are
Lines 859-866 Link Here
859
           <title>ACTION</title>
863
           <title>ACTION</title>
860
864
861
           <para>The action indicates what to do with the packet if it
865
           <para>The action indicates what to do with the packet if it
862
             matches the rest of the filter rule. Each rule <emphasis>must</emphasis> have a
866
             matches the rest of the filter rule. Each rule
863
             action. The following actions are recognized:</para>
867
             <emphasis>must</emphasis> have a action. The following
868
             actions are recognized:</para>
864
869
865
           <para>block indicates that the packet should be dropped if
870
           <para>block indicates that the packet should be dropped if
866
             the selection parameters match the packet.</para>
871
             the selection parameters match the packet.</para>
Lines 877-887 Link Here
877
             other has to be coded or the rule will not pass syntax
882
             other has to be coded or the rule will not pass syntax
878
             check.</para>
883
             check.</para>
879
884
880
           <para>in means this rule is being applied against an inbound
885
           <para>"in" means this rule is being applied against an inbound
881
             packet which has just been received on the interface
886
             packet which has just been received on the interface
882
             facing the public Internet.</para>
887
             facing the public Internet.</para>
883
888
884
           <para>out means this rule is being applied against an
889
           <para>"out" means this rule is being applied against an
885
             outbound packet destined for the interface facing the public
890
             outbound packet destined for the interface facing the public
886
             Internet.</para>
891
             Internet.</para>
887
         </sect3>
892
         </sect3>
Lines 893-910 Link Here
893
               </para>
898
               </para>
894
           </note>
899
           </note>
895
900
896
           <para>log indicates that the packet header will be written to
901
           <para>"log" indicates that the packet header will be written to
897
             the ipl log (as described in the LOGGING section below) if
902
             the ipl log (as described in the LOGGING section below) if
898
             the selection parameters match the packet.</para>
903
             the selection parameters match the packet.</para>
899
904
900
           <para>quick indicates that if the selection parameters match
905
           <para>"quick" indicates that if the selection parameters match
901
             the packet, this rule will be the last rule checked,
906
             the packet, this rule will be the last rule checked,
902
             allowing a "short-circuit" path to avoid processing any
907
             allowing a "short-circuit" path to avoid processing any
903
             following rules for this packet. This option is a mandatory
908
             following rules for this packet. This option is a mandatory
904
             requirement for the modernized rules processing logic.
909
             requirement for the modernized rules processing logic.
905
             </para>
910
             </para>
906
911
907
           <para>on indicates the interface name to be incorporated into
912
           <para>"on" indicates the interface name to be incorporated into
908
             the selection parameters. Interface names are as displayed
913
             the selection parameters. Interface names are as displayed
909
             by ifconfig. Using this option, the rule will only match if
914
             by ifconfig. Using this option, the rule will only match if
910
             the packet is going through that interface in the specified
915
             the packet is going through that interface in the specified
Lines 916-925 Link Here
916
             Immediately following the log keyword, the following
921
             Immediately following the log keyword, the following
917
             qualifiers may be used (in this order):</para>
922
             qualifiers may be used (in this order):</para>
918
923
919
           <para>body indicates that the first 128 bytes of the packet
924
           <para>"body" indicates that the first 128 bytes of the packet
920
             contents will be logged after the headers.</para>
925
             contents will be logged after the headers.</para>
921
926
922
           <para>first If the 'log' keyword is being used in conjunction
927
           <para>"first" If the 'log' keyword is being used in conjunction
923
             with a "keep state" option, it is recommended that this
928
             with a "keep state" option, it is recommended that this
924
             option is also applied so that only the triggering packet
929
             option is also applied so that only the triggering packet
925
             is logged and not every packet which there after matches
930
             is logged and not every packet which there after matches
Lines 958-964 Link Here
958
           <para>The 'all' keyword is essentially a synonym for "from
963
           <para>The 'all' keyword is essentially a synonym for "from
959
             any to any" with no other match parameters.</para>
964
             any to any" with no other match parameters.</para>
960
965
961
           <para>from src to dst The from and to keywords are used to
966
           <para>"from src to dst" The from and to keywords are used to
962
             match against IP addresses. Rules must specify BOTH source
967
             match against IP addresses. Rules must specify BOTH source
963
             and destination parameters. .any. is a special keyword that
968
             and destination parameters. .any. is a special keyword that
964
             matches any IP address. As in 'from any to any' or 'from
969
             matches any IP address. As in 'from any to any' or 'from
Lines 1042-1053 Link Here
1042
          do not properly fit the session conversation template are
1047
          do not properly fit the session conversation template are
1043
          automatically rejected as impostors.</para>
1048
          automatically rejected as impostors.</para>
1044
1049
1045
        <para>Keep state will also allow ICMP packets related to a <acronym>TCP</acronym>
1050
        <para>Keep state will also allow ICMP packets related to a
1046
          or UDP session through. So if you get ICMP type 3 code 4 in
1051
          <acronym>TCP</acronym> or UDP session through. So if you get
1047
          response to some web surfing allowed out by a keep state rule,
1052
          ICMP type 3 code 4 in response to some web surfing allowed
1048
          they will be automatically allowed in. Any packet that IPF can
1053
          out by a keep state rule, they will be automatically allowed
1049
          be certain is part of a active session, even if it is a
1054
          in. Any packet that IPF can be certain is part of a active
1050
          different protocol, will be let in.</para>
1055
          session, even if it is a different protocol, will be let
1056
          in.</para>
1051
1057
1052
        <para>What happens is:</para>
1058
        <para>What happens is:</para>
1053
1059
Lines 1090-1105 Link Here
1090
        interfaces which have to have rules to allow the firewall to
1096
        interfaces which have to have rules to allow the firewall to
1091
        function.</para>
1097
        function.</para>
1092
1098
1093
      <para>All Unix flavored systems including &os; are designed to
1099
      <para>All &unix; flavored systems including &os; are designed to
1094
        use interface l0 and IP address 127.0.0.1 for internal
1100
        use interface lo0 and IP address 127.0.0.1 for internal
1095
        communication with in the &os; operating system. The firewall
1101
        communication with in the operating system. The firewall
1096
        rules must contain rules to allow free unmolested movement of
1102
        rules must contain rules to allow free unmolested movement of
1097
        these special internally used packets.</para>
1103
        these special internally used packets.</para>
1098
1104
1099
      <para>The interface which faces the public Internet, is the one
1105
      <para>The interface which faces the public Internet, is the one
1100
        which you code your rules to authorize and control access out
1106
        which you code your rules to authorize and control access out
1101
        to the public Internet and access requests arriving from the
1107
        to the public Internet and access requests arriving from the
1102
        public Internet. This can be your .user ppp. tun0 interface or
1108
        public Internet. This can be your 'user ppp' tun0 interface or
1103
        your NIC card that is cabled to your DSL or cable modem.</para>
1109
        your NIC card that is cabled to your DSL or cable modem.</para>
1104
1110
1105
      <para>In cases where one or more than one NICs are cabled to
1111
      <para>In cases where one or more than one NICs are cabled to
Lines 1107-1113 Link Here
1107
        interfaces must have a rule coded to allow free unmolested
1113
        interfaces must have a rule coded to allow free unmolested
1108
        movement of packets originating from those LAN interfaces.</para>
1114
        movement of packets originating from those LAN interfaces.</para>
1109
1115
1110
      <para>The rules should be first organized into three major
1116
      <para>The rule set should be first organized into three major
1111
        sections, all the free unmolested interfaces, public interface
1117
        sections, all the free unmolested interfaces, public interface
1112
        outbound, and the public interface inbound.</para>
1118
        outbound, and the public interface inbound.</para>
1113
1119
Lines 1139-1151 Link Here
1139
        create the legal evidence needed to prosecute the people who
1145
        create the legal evidence needed to prosecute the people who
1140
        are attacking your system.</para>
1146
        are attacking your system.</para>
1141
1147
1142
      <para>Another thing you should take note of, is there is no
1148
      <para>There is another thing you should take note of: there is no
1143
        response returned for any of the undesirable stuff, their
1149
        response returned for any of the undesirable stuff, their
1144
        packets just get dropped and vanish. This way the attackers
1150
        packets just get dropped and vanish. This way the attackers
1145
        has no knowledge if his packets have reached your system.  The
1151
        has no knowledge if his packets have reached your system.  The
1146
        less the attackers can learn about your system the more secure
1152
        less the attackers can learn about your system the more secure
1147
        it is. The inbound 'nmap OS fingerprint' attempts rule I log
1153
        it is. The inbound 'nmap OS fingerprint' attempts rule I log
1148
        the first occurrence because this is something a attacker
1154
        the first occurrence because this is something an attacker
1149
        would do.</para>
1155
        would do.</para>
1150
1156
1151
      <para>Any time you see log messages on a rule with .log first.
1157
      <para>Any time you see log messages on a rule with .log first.
Lines 1182-1189 Link Here
1182
        <filename>/etc/ipf.rules</filename>:</para>
1188
        <filename>/etc/ipf.rules</filename>:</para>
1183
1189
1184
      <programlisting>#################################################################
1190
      <programlisting>#################################################################
1185
# No restrictions on Inside Lan Interface for private network
1191
# No restrictions on Inside LAN Interface for private network
1186
# Not needed unless you have Lan
1192
# Not needed unless you have LAN
1187
#################################################################
1193
#################################################################
1188
1194
1189
#pass out quick on xl0 all
1195
#pass out quick on xl0 all
Lines 1203-1209 Link Here
1203
#################################################################
1209
#################################################################
1204
1210
1205
# Allow out access to my ISP's Domain name server.
1211
# Allow out access to my ISP's Domain name server.
1206
# xxx must be the IP address of your ISP.s DNS.
1212
# xxx must be the IP address of your ISP's DNS.
1207
# Dup these lines if your ISP has more than one DNS server
1213
# Dup these lines if your ISP has more than one DNS server
1208
# Get the IP addresses from /etc/resolv.conf file
1214
# Get the IP addresses from /etc/resolv.conf file
1209
pass out quick on dc0 proto tcp from any to xxx port = 53 flags S keep state
1215
pass out quick on dc0 proto tcp from any to xxx port = 53 flags S keep state
Lines 1322-1328 Link Here
1322
# used in the outbound section.
1328
# used in the outbound section.
1323
pass in quick on dc0 proto udp from z.z.z.z to any port = 68 keep state
1329
pass in quick on dc0 proto udp from z.z.z.z to any port = 68 keep state
1324
1330
1325
# Allow in standard www function because I have apache server
1331
# Allow in standard www function because I have Apache server
1326
pass in quick on dc0 proto tcp from any to any port = 80 flags S keep state
1332
pass in quick on dc0 proto tcp from any to any port = 80 flags S keep state
1327
1333
1328
# Allow in non-secure Telnet session from public Internet
1334
# Allow in non-secure Telnet session from public Internet
Lines 1336-1342 Link Here
1336
1342
1337
# Block and log only first occurrence of all remaining traffic
1343
# Block and log only first occurrence of all remaining traffic
1338
# coming into the firewall. The logging of only the first
1344
# coming into the firewall. The logging of only the first
1339
# occurrence stops a .denial of service. attack targeted
1345
# occurrence stops a 'Denial of Service' attack targeted
1340
# at filling up your log file space.
1346
# at filling up your log file space.
1341
# This rule enforces the block all by default logic.
1347
# This rule enforces the block all by default logic.
1342
block in log first quick on dc0 all
1348
block in log first quick on dc0 all
Lines 1370-1376 Link Here
1370
        lines.</para>
1376
        lines.</para>
1371
1377
1372
      <para>With <acronym>NAT</acronym> you only need a single account
1378
      <para>With <acronym>NAT</acronym> you only need a single account
1373
        with your ISP, then cable your other 4 PC.s to a switch and
1379
        with your ISP, then cable your other 4 PC's to a switch and
1374
        the switch to the NIC in your &os; system which is going to
1380
        the switch to the NIC in your &os; system which is going to
1375
        service your LAN as a gateway. <acronym>NAT</acronym> will
1381
        service your LAN as a gateway. <acronym>NAT</acronym> will
1376
        automatically translate the private LAN IP address for each
1382
        automatically translate the private LAN IP address for each
Lines 1436-1448 Link Here
1436
        for details.</para>
1442
        for details.</para>
1437
1443
1438
      <para>When changing the <acronym>NAT</acronym> rules after
1444
      <para>When changing the <acronym>NAT</acronym> rules after
1439
        <acronym>NAT</acronym> has been started, Make your changes to
1445
        <acronym>NAT</acronym> has been started, make your changes to
1440
        the file containing the nat rules, then run ipnat command with
1446
        the file containing the nat rules, then run ipnat command with
1441
        the <option>-CF</option> flags to delete the internal in use
1447
        the <option>-CF</option> flags to delete the internal in use
1442
        <acronym>NAT</acronym> rules and flush the contents of the
1448
        <acronym>NAT</acronym> rules and flush the contents of the
1443
        translation table of all active entries.</para>
1449
        translation table of all active entries.</para>
1444
1450
1445
      <para>To reload the <acronym>NAT</acronym> rules issue a command
1451
      <para>To reload the <acronym>NAT</acronym> rules, issue a command
1446
        like this:</para>
1452
        like this:</para>
1447
1453
1448
      <programlisting>ipnat -CF -f /etc/ipnat.rules</programlisting>
1454
      <programlisting>ipnat -CF -f /etc/ipnat.rules</programlisting>
Lines 1554-1560 Link Here
1554
      <sect3>
1560
      <sect3>
1555
        <title>Assigning Ports to Use</title>
1561
        <title>Assigning Ports to Use</title>
1556
1562
1557
        <para>XXXBLAH</para>
1563
        <para></para>
1558
1564
1559
        <programlisting>map dc0 192.168.1.0/24 -> 0.32</programlisting>
1565
        <programlisting>map dc0 192.168.1.0/24 -> 0.32</programlisting>
1560
1566
Lines 1731-1737 Link Here
1731
1737
1732
    <para>The IPFIREWALL (IPFW) is a &os; sponsored firewall software
1738
    <para>The IPFIREWALL (IPFW) is a &os; sponsored firewall software
1733
      application authored and maintained by &os; volunteer staff
1739
      application authored and maintained by &os; volunteer staff
1734
      members. It uses the legacy Stateless rules and a legacy rule
1740
      members. It uses the legacy stateless rules and a legacy rule
1735
      coding technique to achieve what is referred to as Simple
1741
      coding technique to achieve what is referred to as Simple
1736
      Stateful logic.</para>
1742
      Stateful logic.</para>
1737
1743
Lines 1748-1768 Link Here
1748
1754
1749
    <para>IPFW is composed of 7 components, the primary component is
1755
    <para>IPFW is composed of 7 components, the primary component is
1750
      the kernel firewall filter rule processor and its integrated
1756
      the kernel firewall filter rule processor and its integrated
1751
      packet accounting facility, the logging facility, the 'divert'
1757
      packet accounting facility, then come the logging facility, the
1752
      rule which triggers the <acronym>NAT</acronym> facility, and the
1758
      'divert' rule which triggers the <acronym>NAT</acronym>
1753
      advanced special purpose facilities, the dummynet traffic shaper
1759
      facility, and the advanced special purpose facilities, the
1754
      facilities, the 'fwd rule' forward facility, the bridge
1760
      dummynet traffic shaper facilities, the 'fwd rule' forward
1755
      facility, and the ipstealth facility.</para>
1761
      facility, the bridge facility, and the ipstealth
1762
      facility.</para>
1756
1763
1757
    <sect2 id="firewalls-ipfw-enable">
1764
    <sect2 id="firewalls-ipfw-enable">
1758
      <title>Enabling IPFW</title>
1765
      <title>Enabling IPFW</title>
1759
1766
1760
      <para>IPFW is included in the basic &os; install as a separate
1767
      <para>IPFW is included in the basic &os; install as a separate
1761
        run time loadable module. IPFW will dynamically load the
1768
        run time loadable module. The system will dynamically load
1762
        kernel module when the <filename>rc.conf</filename> statement
1769
        IPFW kernel module when the <filename>rc.conf</filename>
1763
        <literal>firewall_enable="YES"</literal> is used. You do not
1770
        statement <literal>firewall_enable="YES"</literal> is
1764
        need to compile IPFW into the &os; kernel unless you want
1771
        used. You do not need to compile IPFW into the &os; kernel
1765
        <acronym>NAT</acronym> function enabled.</para>
1772
        unless you want <acronym>NAT</acronym> function
1773
        enabled.</para>
1766
1774
1767
      <para>After rebooting your system with
1775
      <para>After rebooting your system with
1768
        <literal>firewall_enable="YES"</literal> in
1776
        <literal>firewall_enable="YES"</literal> in
Lines 1870-1876 Link Here
1870
        firewall rules with changes you made to the files content is
1878
        firewall rules with changes you made to the files content is
1871
        the recommended method used here.</para>
1879
        the recommended method used here.</para>
1872
1880
1873
      <para>The IPFW command is still a very useful to display the
1881
      <para>The ipfw command is still very useful to display the
1874
        running firewall rules to the console screen. The IPFW
1882
        running firewall rules to the console screen. The IPFW
1875
        accounting facility dynamically creates a counter for each
1883
        accounting facility dynamically creates a counter for each
1876
        rule that counts each packet that matches the rule. During the
1884
        rule that counts each packet that matches the rule. During the
Lines 2063-2073 Link Here
2063
2071
2064
          <para>The from and to keywords are used to match against IP
2072
          <para>The from and to keywords are used to match against IP
2065
            addresses. Rules must specify BOTH source and destination
2073
            addresses. Rules must specify BOTH source and destination
2066
            parameters. any is a special keyword that matches any IP
2074
            parameters. 'any' is a special keyword that matches any IP
2067
            address. me is a special keyword that matches any IP
2075
            address. 'me' is a special keyword that matches any IP
2068
            address configured on an interface in your &os; system to
2076
            address configured on an interface in your &os; system to
2069
            represent the PC the firewall is running on. (i.e. this
2077
            represent the PC the firewall is running on (i.e. this
2070
            box) As in from me to any or from any to me or from
2078
            box). As in from me to any or from any to me or from
2071
            0.0.0.0/0 to any or from any to 0.0.0.0/0 or from 0.0.0.0
2079
            0.0.0.0/0 to any or from any to 0.0.0.0/0 or from 0.0.0.0
2072
            to any or from any to 0.0.0.0 or from me to 0.0.0.0. IP
2080
            to any or from any to 0.0.0.0 or from me to 0.0.0.0. IP
2073
            addresses are specified as a dotted IP address numeric
2081
            addresses are specified as a dotted IP address numeric
Lines 2225-2231 Link Here
2225
          <para>The script syntax used here is compatible with the 'sh',
2233
          <para>The script syntax used here is compatible with the 'sh',
2226
            'csh', 'tcsh' shells. Symbolic substitution fields are
2234
            'csh', 'tcsh' shells. Symbolic substitution fields are
2227
            prefixed with a dollar sign &dollar;. Symbolic fields do not have
2235
            prefixed with a dollar sign &dollar;. Symbolic fields do not have
2228
            the &dollar; prefix. The value to populate the Symbolic field must
2236
            the &dollar; prefix. The value to populate the symbolic field must
2229
            be enclosed to "double quotes".</para>
2237
            be enclosed to "double quotes".</para>
2230
2238
2231
          <para>Start your rules file like this:</para>
2239
          <para>Start your rules file like this:</para>
Lines 2235-2241 Link Here
2235
ipfw -q -f flush       # Delete all rules
2243
ipfw -q -f flush       # Delete all rules
2236
# Set defaults
2244
# Set defaults
2237
oif="tun0"             # out interface
2245
oif="tun0"             # out interface
2238
odns="192.0.2.11"      # ISP's dns server IP address
2246
odns="192.0.2.11"      # ISP's DNS server IP address
2239
cmd="ipfw -q add "     # build rule prefix
2247
cmd="ipfw -q add "     # build rule prefix
2240
ks="keep-state"        # just too lazy to key this each time
2248
ks="keep-state"        # just too lazy to key this each time
2241
&dollar;cmd 00500 check-state
2249
&dollar;cmd 00500 check-state
Lines 2247-2253 Link Here
2247
################### End of example ipfw rules script ############</programlisting>
2255
################### End of example ipfw rules script ############</programlisting>
2248
2256
2249
          <para>That is all there is to it. The rules are not important
2257
          <para>That is all there is to it. The rules are not important
2250
            in this example, how the Symbolic substitution field are
2258
            in this example, how the symbolic substitution field are
2251
            populated and used are.</para>
2259
            populated and used are.</para>
2252
2260
2253
          <para>If the above example was in
2261
          <para>If the above example was in
Lines 2274-2280 Link Here
2274
2282
2275
        </sect3>
2283
        </sect3>
2276
        <sect3>
2284
        <sect3>
2277
          <title>Stateful Ruleset</title>
2285
          <title>Stateful Rule Set</title>
2278
          <para>The following non-<acronym>NAT</acronym>ed rule set is a example of how to
2286
          <para>The following non-<acronym>NAT</acronym>ed rule set is a example of how to
2279
            code a very secure 'inclusive' type of firewall. An
2287
            code a very secure 'inclusive' type of firewall. An
2280
            inclusive firewall only allows services matching pass rules
2288
            inclusive firewall only allows services matching pass rules
Lines 2283-2289 Link Here
2283
            allow the firewall to function.</para>
2291
            allow the firewall to function.</para>
2284
2292
2285
          <para>All &unix; flavored operating systems, &os; included, are designed to
2293
          <para>All &unix; flavored operating systems, &os; included, are designed to
2286
            use interface lo and IP address
2294
            use interface lo0 and IP address
2287
            <hostid role="ipaddr">127.0.0.1</hostid> for internal
2295
            <hostid role="ipaddr">127.0.0.1</hostid> for internal
2288
            communication with in &os;. The firewall rules must contain
2296
            communication with in &os;. The firewall rules must contain
2289
            rules to allow free unmolested movement of these special
2297
            rules to allow free unmolested movement of these special
Lines 2292-2300 Link Here
2292
          <para>The interface which faces the public Internet, is the
2300
          <para>The interface which faces the public Internet, is the
2293
            one which you code your rules to authorize and control
2301
            one which you code your rules to authorize and control
2294
            access out to the public Internet and access requests
2302
            access out to the public Internet and access requests
2295
            arriving from the public Internet. This can be your ppp tun0
2303
            arriving from the public Internet. This can be your 'user
2296
            interface or your NIC that is connected to your DSL or cable
2304
            ppp' tun0 interface or your NIC that is connected to your
2297
            modem.</para>
2305
            DSL or cable modem.</para>
2298
2306
2299
          <para>In cases where one or more than one NIC are connected to
2307
          <para>In cases where one or more than one NIC are connected to
2300
            a private LANs behind the firewall, those interfaces must
2308
            a private LANs behind the firewall, those interfaces must
Lines 2349-2357 Link Here
2349
            .</para>
2357
            .</para>
2350
        </sect3>
2358
        </sect3>
2351
        <sect3>
2359
        <sect3>
2352
          <title>An Example Inclusive Ruleset</title>
2360
          <title>An Example Inclusive Rule Set</title>
2353
          <para>The following non-<acronym>NAT</acronym>ed rule set is a complete inclusive
2361
          <para>The following non-<acronym>NAT</acronym>ed rule set is a complete inclusive
2354
            type ruleset. You can not go wrong using this rule set for
2362
            type rule set. You can not go wrong using this rule set for
2355
            you own.  Just comment out any pass rules for services you
2363
            you own.  Just comment out any pass rules for services you
2356
            do not want.  If you see messages in your log that you want to
2364
            do not want.  If you see messages in your log that you want to
2357
            stop seeing just add a deny rule in the inbound section. You
2365
            stop seeing just add a deny rule in the inbound section. You
Lines 2398-2404 Link Here
2398
                        # facing the public Internet
2406
                        # facing the public Internet
2399
2407
2400
#################################################################
2408
#################################################################
2401
# No restrictions on Inside Lan Interface for private network
2409
# No restrictions on Inside LAN Interface for private network
2402
# Not needed unless you have Lan.
2410
# Not needed unless you have Lan.
2403
# Change xl0 to your Lan Nic card interface name
2411
# Change xl0 to your Lan Nic card interface name
2404
#################################################################
2412
#################################################################
Lines 2540-2554 Link Here
2540
        </sect3>
2548
        </sect3>
2541
2549
2542
        <sect3>
2550
        <sect3>
2543
          <title>An Example <acronym>NAT</acronym> and Stateful Ruleset</title>
2551
          <title>An Example <acronym>NAT</acronym> and Stateful Rule
2544
          <para>There are some additional configuration statements that
2552
          Set</title> 
2545
            need to be enabled to activate the <acronym>NAT</acronym> function of IPFW. The
2553
2546
            kernel source needs 'option divert' statement added to the
2554
          <para>There are some additional configuration statements
2547
            other IPFIREWALL statements compiled into a custom kernel.
2555
            that need to be enabled to activate the
2556
            <acronym>NAT</acronym> function of IPFW. The kernel
2557
            needs 'option divert' statement added to the other
2558
            IPFIREWALL statements compiled into a custom kernel.
2548
            </para>
2559
            </para>
2549
2560
2550
          <para>In addition to the normal IPFW options in
2561
          <para>In addition to the normal IPFW options in
2551
            <filename>/etc/rc.conf</filename>, the following are needed.
2562
            <filename>/etc/rc.conf</filename>, the following are needed:
2552
            </para>
2563
            </para>
2553
2564
2554
          <programlisting>natd_enable="YES"                   # Enable <acronym>NAT</acronym>D function
2565
          <programlisting>natd_enable="YES"                   # Enable <acronym>NAT</acronym>D function
Lines 2571-2640 Link Here
2571
2582
2572
          <para>The processing flow starts with the first rule from the
2583
          <para>The processing flow starts with the first rule from the
2573
            top of the rule file and progress one rule at a time deeper
2584
            top of the rule file and progress one rule at a time deeper
2574
            into the file until the end is reach or the packet being
2585
            into the file until the end is reached or the packet being
2575
            tested to the selection criteria matches and the packet is
2586
            tested to the selection criteria matches and the packet is
2576
            released out of the firewall.  It is important to take notice
2587
            released out of the firewall.  It is important to take notice
2577
            of the location of rule numbers 100 101, 450, 500, and 510.
2588
            of the location of rule numbers 100 101, 450, 500, and 510.
2578
            These rules control the translation of the outbound and
2589
            These rules control the translation of the outbound and
2579
            inbound packets so their entries in the keep-state dynamic
2590
            inbound packets so their entries in the keep-state dynamic
2580
            table always register the private Lan IP address. Next
2591
            table always register the private LAN IP address. Next
2581
            notice that all the allow and deny rules specified the
2592
            notice that all the allow and deny rules specified the
2582
            direction the packet is going (IE outbound or inbound) and
2593
            direction the packet is going (IE outbound or inbound) and
2583
            the interface. Also notice that all the start outbound
2594
            the interface. Also notice that all the start outbound
2584
            session requests all skipto rule 500 for the network address
2595
            session requests all skipto rule 500 for the network address
2585
            translation.</para>
2596
            translation.</para>
2586
2597
2587
          <para>Lets say a LAN user uses their web browser to get a web
2598
          <para>Lets say a LAN user uses their web browser to get a
2588
            page. Web pages use port 80 to communicate over. So the
2599
            web page. Web pages use port 80 to communicate over. So
2589
            packet enters the firewall, It does not match 100 because
2600
            the packet enters the firewall. It does not match 100
2590
            it is headed out not in. It passes rule 101 because this is
2601
            because it is headed out not in. It passes rule 101
2591
            the first packet so it has not been posted to the keep-state
2602
            because this is the first packet so it has not been posted
2592
            dynamic table yet. The packet finally comes to rule 125 a
2603
            to the keep-state dynamic table yet. The packet finally
2593
            matches.  It is outbound through the NIC facing the public
2604
            comes to rule 125 a matches. It is outbound through the
2594
            Internet. The packet still has it's source IP address as a
2605
            NIC facing the public Internet. The packet source IP
2595
            private Lan IP address. On the match to this rule, two
2606
            address is still a private LAN IP address. On the match to
2596
            actions take place.  The keep-state option will post this rule
2607
            this rule, two actions take place. The keep-state option
2597
            into the keep-state dynamic rules table and the specified
2608
            will post this rule into the keep-state dynamic rules
2598
            action is executed. The action is part of the info posted to
2609
            table and the specified action is executed. The action is
2599
            the dynamic table.  In this case it is "skipto rule 500".  Rule
2610
            part of the info posted to the dynamic table.  In this
2600
            500 <acronym>NAT</acronym>s the packet IP address and out it goes. Remember
2611
            case it is "skipto rule 500".  Rule 500
2601
            this, this is very important. This packet makes it's way to
2612
            <acronym>NAT</acronym>s the packet IP address and out it
2602
            the destination and returns and enters the top of the rule
2613
            goes. Remember this, this is very important. This packet
2603
            set. This time it does match rule 100 and has it destination
2614
            makes its way to the destination and returns and enters
2604
            IP address mapped back to it's corresponding Lan IP address.
2615
            the top of the rule set. This time it does match rule 100
2605
            It then is processed by the check-state rule, it's found in
2616
            and has it destination IP address mapped back to it's
2606
            the table as an existing session conversation and released
2617
            corresponding Lan IP address.  Then it is processed by the
2607
            to the LAN. It goes to the LAN PC that sent it and a new
2618
            check-state rule, it's found in the table as belonging to
2608
            packet is sent requesting another segment of the data from
2619
            an existing session conversation and released to the
2609
            the remote server. This time it gets checked by the
2620
            LAN. It goes to the LAN PC that sent it and a new packet
2610
            check-state rule and it's outbound entry is found,  the
2621
            is sent requesting another segment of the data from the
2622
            remote server. This time it gets checked by the
2623
            check-state rule and, as its outbound entry is found, the
2611
            associated action, 'skipto 500', is executed.  The packet
2624
            associated action, 'skipto 500', is executed.  The packet
2612
            jumps to rule 500 gets <acronym>NAT</acronym>ed and released on it's way out.
2625
            jumps to rule 500 gets <acronym>NAT</acronym>ed and
2613
            </para>
2626
            released on it's way out.  </para>
2614
2627
2615
          <para>On the inbound side, everything coming in that is part
2628
          <para>On the inbound side, everything coming in that is part
2616
            of an existing session conversation is being automatically
2629
            of an existing session conversation is being automatically
2617
            handled by the check-state rule and the properly placed
2630
            handled by the check-state rule and the properly placed
2618
            divert natd rules. All we have to address is denying all the
2631
            divert natd rules. All we have to address is denying all
2619
            bad packets and only allowing in the authorized services.
2632
            the bad packets and only allowing in the authorized
2620
            Lets say there is a apache server running on the firewall
2633
            services.  Lets say there is a apache server running on
2621
            box and we want people on the public Internet to be able to
2634
            the firewall box and we want people on the public Internet
2622
            access the local web site. The new inbound start request
2635
            to be able to access the local web site. The new inbound
2623
            packet matches rule 100 and its IP address is mapped to LAN
2636
            start request packet matches rule 100 and its IP address
2624
            IP for the firewall box. The packet is them matched against
2637
            is mapped to LAN IP for the firewall box. The packet is
2625
            all the nasty things we want to check for and finally
2638
            them matched against all the nasty things we want to check
2626
            matches against rule 425. On a match two things occur, the
2639
            for and finally matches against rule 425. On a match two
2627
            limit option is an extension to keep-state. The packet rule
2640
            things occur. The packet rule is posted to the keep-state
2628
            is posted to the keep-state dynamic table but this time any
2641
            dynamic table but this time the number of new session
2629
            new session requests originating from that source IP address
2642
            requests originating from that source IP address is
2630
            is limited to 2. This defends against DoS attacks of service
2643
            limited to 2. This defends against DoS attacks of service
2631
            IP for the firewall box. The packet is them matched against
2644
            running on the specified port number. The action is allow
2632
            all the nasty things we want to check for and finally
2645
            so the packet is released to the LAN. On return the
2633
            matches against rule 425. On a match two things occur, the
2646
            check-state rule recognizes the packet as belonging to an
2634
            limit option is an extension to keep-state. The packet rule
2647
            existing session conversation sends it to rule 500 for
2635
            is posted to the keep-state dynamic table but this time any
2648
            <acronym>NAT</acronym>ing and released to outbound
2636
            new session requests originating from that source IP address
2649
            interface.</para>
2637
            is limited to 2. This defends against DoS attacks of service
2638
            running on the specified port number. The action is allow so
2639
            the packet is released to the LAN. On return the check-state
2640
            rule recognizes the packet as belonging to an existing
2641
            session conversation sends it to rule 500 for <acronym>NAT</acronym>ing and
2642
            released to outbound interface.</para>
2643
2650
2644
          <para>Example Ruleset #1:</para>
2651
          <para>Example Rule Set #1:</para>
2645
2652
2646
          <programlisting>#!/bin/sh
2653
          <programlisting>#!/bin/sh
2647
cmd="ipfw -q add"
2654
cmd="ipfw -q add"
Lines 2645-2651 Link Here
2645
2659
2646
ipfw -q -f flush
2660
ipfw -q -f flush
2647
2661
2648
&dollar;cmd 002 allow all from any to any via xl0  # exclude Lan traffic
2662
&dollar;cmd 002 allow all from any to any via xl0  # exclude LAN traffic
2649
&dollar;cmd 003 allow all from any to any via lo0  # exclude loopback traffic
2663
&dollar;cmd 003 allow all from any to any via lo0  # exclude loopback traffic
2650
2664
2651
&dollar;cmd 100 divert natd ip from any to any in via &dollar;pif
2665
&dollar;cmd 100 divert natd ip from any to any in via &dollar;pif
Lines 2688-2694 Link Here
2688
            to help the inexperienced IPFW rule writer to better
2702
            to help the inexperienced IPFW rule writer to better
2689
            understand what the rules are doing.</para>
2703
            understand what the rules are doing.</para>
2690
2704
2691
          <para>Example Ruleset #2:</para>
2705
          <para>Example Rule Set #2:</para>
2692
2706
2693
          <programlisting>
2707
          <programlisting>
2694
#!/bin/sh
2708
#!/bin/sh

Return to bug 75422