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

(-)en_US.ISO8859-1/articles/filtering-bridges/article.sgml (-70 / +72 lines)
Lines 22-28 Link Here
22
    <abstract>
22
    <abstract>
23
      <para>Often it is useful to divide one physical network (like an
23
      <para>Often it is useful to divide one physical network (like an
24
	Ethernet) into two separate segments without having to create subnets,
24
	Ethernet) into two separate segments without having to create subnets,
25
	and use a router to link them together. The device that connects the
25
	and use a router to link them together.  The device that connects the
26
	two networks in this way is called a bridge.  A FreeBSD system with
26
	two networks in this way is called a bridge.  A FreeBSD system with
27
	two network interfaces is enough in order to act as a bridge.</para>
27
	two network interfaces is enough in order to act as a bridge.</para>
28
28
Lines 30-36 Link Here
30
	level (Ethernet addresses) of the devices connected to each of its
30
	level (Ethernet addresses) of the devices connected to each of its
31
	network interfaces and then forwarding the traffic between the two
31
	network interfaces and then forwarding the traffic between the two
32
	networks only if the source and the destination are on different
32
	networks only if the source and the destination are on different
33
	segments. Under many points of view a brigde is similar to an Ethernet
33
	segments.  Under many points of view a brigde is similar to an Ethernet
34
	switch with only two ports.</para>
34
	switch with only two ports.</para>
35
    </abstract>
35
    </abstract>
36
  </articleinfo>
36
  </articleinfo>
Lines 42-53 Link Here
42
      Internet connections (xDSL) and also because of the reduction of
42
      Internet connections (xDSL) and also because of the reduction of
43
      available IPv4 addresses, many companies are connected to the Internet
43
      available IPv4 addresses, many companies are connected to the Internet
44
      24 hours on 24 and with few (sometimes not even a power of 2) IP
44
      24 hours on 24 and with few (sometimes not even a power of 2) IP
45
      addresses. In these situations it is often desirable to have a firewall
45
      addresses.  In these situations it is often desirable to have a firewall
46
      that filters incoming and outgoing traffic from and towards Internet,
46
      that filters incoming and outgoing traffic from and towards Internet,
47
      but a packet filtering solution based on router may not be applicable,
47
      but a packet filtering solution based on router may not be applicable,
48
      either due to subnetting issues, the router is owned by the connectivity
48
      either due to subnetting issues, the router is owned by the connectivity
49
      supplier (<acronym>ISP</acronym>), or because it doesn't support such
49
      supplier (<acronym>ISP</acronym>), or because it doesn't support such
50
      functionalities. In these scenarios the use of a filtering bridge is
50
      functionalities.  In these scenarios the use of a filtering bridge is
51
      highly advised.</para>
51
      highly advised.</para>
52
52
53
    <para>A bridge-based firewall can be configured and inserted between the
53
    <para>A bridge-based firewall can be configured and inserted between the
Lines 61-67 Link Here
61
    <para>Adding bridge functionalities to a FreeBSD system is not difficult.
61
    <para>Adding bridge functionalities to a FreeBSD system is not difficult.
62
      Since 4.5 release it is possible to load such functionalities as modules
62
      Since 4.5 release it is possible to load such functionalities as modules
63
      instead of having to rebuild the kernel, simplifying the procedure a
63
      instead of having to rebuild the kernel, simplifying the procedure a
64
      great deal. In the following subsections I will explain both
64
      great deal.  In the following subsections I will explain both
65
      installation ways.</para>
65
      installation ways.</para>
66
66
67
    <important>
67
    <important>
Lines 73-81 Link Here
73
    <para>Before going on, be sure to have at least two Ethernet cards that
73
    <para>Before going on, be sure to have at least two Ethernet cards that
74
      support the promiscuous mode for both reception and transmission, since
74
      support the promiscuous mode for both reception and transmission, since
75
      they must be able to send Ethernet packets with any address, not just
75
      they must be able to send Ethernet packets with any address, not just
76
      their own. Moreover, to have a good throughput, the cards should be PCI
76
      their own.  Moreover, to have a good throughput, the cards should be PCI
77
      bus mastering cards. The best choices are still the Intel EtherExpress
77
      bus mastering cards.  The best choices are still the Intel EtherExpress
78
      Pro, followed by the 3Com 3c9xx series. To simplify the firewall
78
      Pro, followed by the 3Com 3c9xx series.  To simplify the firewall
79
      configuration it may be useful to have two cards of different
79
      configuration it may be useful to have two cards of different
80
      manufacturers (using different drivers) in order to distinguish clearly
80
      manufacturers (using different drivers) in order to distinguish clearly
81
      which interface is connected to the router and which to the inner
81
      which interface is connected to the router and which to the inner
Lines 85-91 Link Here
85
      <title>Kernel Configuration</title>
85
      <title>Kernel Configuration</title>
86
86
87
      <para>So you have decided to use the older but well tested installation
87
      <para>So you have decided to use the older but well tested installation
88
	method. To begin, you have to add the following rows to your kernel
88
	method.  To begin, you have to add the following rows to your kernel
89
	configuration file:</para>
89
	configuration file:</para>
90
90
91
      <programlisting>options BRIDGE
91
      <programlisting>options BRIDGE
Lines 114-120 Link Here
114
114
115
      <para>In this way, during the system startup, the
115
      <para>In this way, during the system startup, the
116
	<filename>bridge.ko</filename> module will be loaded together with the
116
	<filename>bridge.ko</filename> module will be loaded together with the
117
	kernel. It is not required to add a similar row for the
117
	kernel.  It is not required to add a similar row for the
118
	<filename>ipfw.ko</filename> module, since it will be loaded
118
	<filename>ipfw.ko</filename> module, since it will be loaded
119
	automatically after the execution of the steps in the following
119
	automatically after the execution of the steps in the following
120
	section.</para>
120
	section.</para>
Lines 127-138 Link Here
127
    <para>Before rebooting in order to load the new kernel or the required
127
    <para>Before rebooting in order to load the new kernel or the required
128
      modules (according to the previously choosen installation method), you
128
      modules (according to the previously choosen installation method), you
129
      have to make some changes to the <filename>/etc/rc.conf</filename>
129
      have to make some changes to the <filename>/etc/rc.conf</filename>
130
      configuration file. The default rule of the firewall is to reject all IP
130
      configuration file.  The default rule of the firewall is to reject all IP
131
      packets.  Initially we will set up an <option>open</option> firewall, in order to verify
131
      packets.  Initially we will set up an <option>open</option> firewall, in
132
      its operation without any issue related to packet filtering (in case you
132
      order to verify its operation without any issue related to packet
133
      are going to execute this procedure remotely, such configuration will
133
      filtering (in case you are going to execute this procedure remotely, such
134
      avoid you to remain isolated from the network). Put these lines in
134
      configuration will avoid you to remain isolated from the network).  Put
135
      <filename>/etc/rc.conf</filename>:</para>
135
      these lines in <filename>/etc/rc.conf</filename>:</para>
136
136
137
    <programlisting>firewall_enable="YES"
137
    <programlisting>firewall_enable="YES"
138
firewall_type="open"
138
firewall_type="open"
Lines 147-153 Link Here
147
147
148
    <para>About the configuration of the network interfaces, the most used way
148
    <para>About the configuration of the network interfaces, the most used way
149
      is to assign an IP to only one of the network cards, but the bridge will
149
      is to assign an IP to only one of the network cards, but the bridge will
150
      work equally even if both interfaces or none has a configured IP. In the
150
      work equally even if both interfaces or none has a configured IP.  In the
151
      last case (IP-less) the bridge machine will be still more hidden, as
151
      last case (IP-less) the bridge machine will be still more hidden, as
152
      inaccessible from the network: to configure it, you have to login from
152
      inaccessible from the network: to configure it, you have to login from
153
      console or through a third network interface separated from the bridge.
153
      console or through a third network interface separated from the bridge.
Lines 155-175 Link Here
155
      access, say for domain resolution: in this case it is necessary to
155
      access, say for domain resolution: in this case it is necessary to
156
      assign an IP to the external interface (the one connected to Internet,
156
      assign an IP to the external interface (the one connected to Internet,
157
      where <acronym>DNS</acronym> server resides), since the bridge will be
157
      where <acronym>DNS</acronym> server resides), since the bridge will be
158
      activated at the end of the startup procedure. It means that the
158
      activated at the end of the startup procedure.  It means that the
159
      <devicename>fxp0</devicename> interface (in our case) must be mentioned
159
      <devicename>fxp0</devicename> interface (in our case) must be mentioned
160
      in the ifconfig section of the <filename>/etc/rc.conf</filename> file,
160
      in the ifconfig section of the <filename>/etc/rc.conf</filename> file,
161
      while the <devicename>xl0</devicename> is not. Assigning an IP to both
161
      while the <devicename>xl0</devicename> is not.  Assigning an IP to both
162
      the network cards does not make much sense, unless, during the start
162
      the network cards does not make much sense, unless, during the start
163
      procedure, applications should access to services on both Ethernet
163
      procedure, applications should access to services on both Ethernet
164
      segments.</para>
164
      segments.</para>
165
165
166
    <para>There is another important thing to know. When running IP over
166
    <para>There is another important thing to know.  When running IP over
167
      Ethernet, there are actually two Ethernet protocols in use: one is IP,
167
      Ethernet, there are actually two Ethernet protocols in use: one is IP,
168
      the other is <acronym>ARP</acronym>.  <acronym>ARP</acronym> does the
168
      the other is <acronym>ARP</acronym>.  <acronym>ARP</acronym> does the
169
      conversion of the IP address of a host into its Ethernet address
169
      conversion of the IP address of a host into its Ethernet address
170
      (<acronym>MAC</acronym> layer).  In order to allow the communication
170
      (<acronym>MAC</acronym> layer).  In order to allow the communication
171
      between two hosts separated by the bridge, it is necessary that the
171
      between two hosts separated by the bridge, it is necessary that the
172
      bridge will forward <acronym>ARP</acronym> packets. Such protocol is not
172
      bridge will forward <acronym>ARP</acronym> packets.  Such protocol is not
173
      included in the IP layer, since it exists only with IP over Ethernet.
173
      included in the IP layer, since it exists only with IP over Ethernet.
174
      The FreeBSD firewall filters exclusively on the IP layer and therefore
174
      The FreeBSD firewall filters exclusively on the IP layer and therefore
175
      all non-IP packets (<acronym>ARP</acronym> included) will be forwarded
175
      all non-IP packets (<acronym>ARP</acronym> included) will be forwarded
Lines 178-185 Link Here
178
178
179
    <para>Now it's time to reboot the system and use it as before: there will
179
    <para>Now it's time to reboot the system and use it as before: there will
180
      be some new messages about the bridge and the firewall, but the bridge
180
      be some new messages about the bridge and the firewall, but the bridge
181
      will not be activated and the firewall, being in <option>open</option> mode, will not
181
      will not be activated and the firewall, being in <option>open</option>
182
      avoid any operations.</para>
182
      mode, will not avoid any operations.</para>
183
183
184
    <para>If there are any problems, you should sort them out now
184
    <para>If there are any problems, you should sort them out now
185
      before proceeding.</para>
185
      before proceeding.</para>
Lines 203-209 Link Here
203
203
204
    <para>At this point you should be able to insert the machine between two
204
    <para>At this point you should be able to insert the machine between two
205
      sets of hosts without compromising any communication abilities between
205
      sets of hosts without compromising any communication abilities between
206
      them. If so, the next step is to add the
206
      them.  If so, the next step is to add the
207
      <literal>net.link.ether.<replaceable>[blah]</replaceable>=<replaceable>[blah]</replaceable></literal>
207
      <literal>net.link.ether.<replaceable>[blah]</replaceable>=<replaceable>[blah]</replaceable></literal>
208
      portions of these rows to the <filename>/etc/sysctl.conf</filename>
208
      portions of these rows to the <filename>/etc/sysctl.conf</filename>
209
      file, in order to have them execute at startup.</para>
209
      file, in order to have them execute at startup.</para>
Lines 213-255 Link Here
213
    <title>Configuring The Firewall</title>
213
    <title>Configuring The Firewall</title>
214
214
215
    <para>Now it is time to create your own file with custom firewall rules,
215
    <para>Now it is time to create your own file with custom firewall rules,
216
      in order to secure the inside network. There will be some complication
216
      in order to secure the inside network.  There will be some complication
217
      in doing this because not all of the firewall functionalities are
217
      in doing this because not all of the firewall functionalities are
218
      available on bridged packets. Furthermore, there is a difference between
218
      available on bridged packets.  Furthermore, there is a difference between
219
      the packets that are in the process of being forwarded and packets that
219
      the packets that are in the process of being forwarded and packets that
220
      are being received by the local machine. In general, incoming packets
220
      are being received by the local machine.  In general, incoming packets
221
      are run through the firewall only once, not twice as is normally the
221
      are run through the firewall only once, not twice as is normally the
222
      case; in fact they are filtered only upon receipt, so rules that use
222
      case; in fact they are filtered only upon receipt, so rules that use
223
      <option>out</option> or <option>xmit</option> will never match. Personally, I use <option>in via</option> which is an
223
      <option>out</option> or <option>xmit</option> will never match.
224
      older syntax, but one that has a sense when you read it. Another
224
      Personally, I use <option>in via</option> which is an older syntax, but
225
      limitation is that you are restricted to use only <option>pass</option> or <option>drop</option>
225
      one that has a sense when you read it.  Another limitation is that you are
226
      restricted to use only <option>pass</option> or <option>drop</option>
226
      commands for packets filtered by a bridge.  Sophisticated things like
227
      commands for packets filtered by a bridge.  Sophisticated things like
227
      <option>divert</option>, <option>forward</option> or <option>reject</option> are not available. Such options can
228
      <option>divert</option>, <option>forward</option> or
228
      still be used, but only on traffic to or from the bridge machine itself
229
      <option>reject</option> are not available.  Such options can still be
229
      (if it has an IP address).</para>
230
      used, but only on traffic to or from the bridge machine itself (if it has
231
      an IP address).</para>
230
232
231
    <para>New in FreeBSD 4.0, is the concept of stateful filtering.  This is a
233
    <para>New in FreeBSD 4.0, is the concept of stateful filtering.  This is a
232
      big improvement for <acronym>UDP</acronym> traffic, which typically is a
234
      big improvement for <acronym>UDP</acronym> traffic, which typically is a
233
      request going out, followed shortly thereafter by a response with the
235
      request going out, followed shortly thereafter by a response with the
234
      exact same set of IP addresses and port numbers (but with source and
236
      exact same set of IP addresses and port numbers (but with source and
235
      destination reversed, of course). For firewalls that have no
237
      destination reversed, of course).  For firewalls that have no
236
      statekeeping, there is almost no way to deal with this sort of traffic
238
      statekeeping, there is almost no way to deal with this sort of traffic
237
      as a single session. But with a firewall that can <quote>remember</quote> an outgoing
239
      as a single session.  But with a firewall that can <quote>remember</quote>
238
      <acronym>UDP</acronym> packet and, for the next few minutes, allow a
240
      an outgoing <acronym>UDP</acronym> packet and, for the next few minutes,
239
      response, handling <acronym>UDP</acronym> services is trivial. The
241
      allow a response, handling <acronym>UDP</acronym> services is trivial.
240
      following example shows how to do it. It's possible to do the same thing
242
      The following example shows how to do it.  It's possible to do the same
241
      with <acronym>TCP</acronym> packets. This allows you to avoid some
243
      thing with <acronym>TCP</acronym> packets.  This allows you to avoid some
242
      denial of service attacks and other nasty tricks, but it also typically
244
      denial of service attacks and other nasty tricks, but it also typically
243
      makes your state table grow quickly in size.</para>
245
      makes your state table grow quickly in size.</para>
244
246
245
    <para>Let's look at an example setup. Note first that at the top of
247
    <para>Let's look at an example setup.  Note first that at the top of
246
      <filename>/etc/rc.firewall</filename> there are already standard rules
248
      <filename>/etc/rc.firewall</filename> there are already standard rules
247
      for the loopback interface <devicename>lo0</devicename>, so we shouldn't
249
      for the loopback interface <devicename>lo0</devicename>, so we shouldn't
248
      have to care for them anymore. Custom rules should be put in a separate
250
      have to care for them anymore.  Custom rules should be put in a separate
249
      file (say <filename>/etc/rc.firewall.local</filename>) and loaded at
251
      file (say <filename>/etc/rc.firewall.local</filename>) and loaded at
250
      system startup, by modifying the row of
252
      system startup, by modifying the row of
251
      <filename>/etc/rc.conf</filename> where we defined the <option>open</option>
253
      <filename>/etc/rc.conf</filename> where we defined the
252
      firewall:</para>
254
      <option>open</option> firewall:</para>
253
255
254
    <programlisting>firewall_type="/etc/rc.firewall.local"</programlisting>
256
    <programlisting>firewall_type="/etc/rc.firewall.local"</programlisting>
255
257
Lines 315-377 Link Here
315
add drop log all from any to any</programlisting>
317
add drop log all from any to any</programlisting>
316
318
317
    <para>Those of you who have set up firewalls before may notice some things
319
    <para>Those of you who have set up firewalls before may notice some things
318
      missing. In particular, there are no anti-spoofing rules, in fact we did
320
      missing.  In particular, there are no anti-spoofing rules, in fact we did
319
      <emphasis>not</emphasis> add:</para>
321
      <emphasis>not</emphasis> add:</para>
320
322
321
    <programlisting>add deny all from 1.2.3.4/8 to any in via fxp0</programlisting>
323
    <programlisting>add deny all from 1.2.3.4/8 to any in via fxp0</programlisting>
322
324
323
    <para>That is, drop packets that are coming in from the outside claiming
325
    <para>That is, drop packets that are coming in from the outside claiming
324
      to be from our network. This is something that you would commonly do to
326
      to be from our network.  This is something that you would commonly do to
325
      be sure that someone does not try to evade the packet filter, by
327
      be sure that someone does not try to evade the packet filter, by
326
      generating nefarious packets that look like they are from the inside.
328
      generating nefarious packets that look like they are from the inside.
327
      The problem with that is that there is <emphasis>at least</emphasis> one
329
      The problem with that is that there is <emphasis>at least</emphasis> one
328
      host on the outside interface that you do not want to ignore: the
330
      host on the outside interface that you do not want to ignore: the
329
      router. But usually, the <acronym>ISP</acronym> anti-spoofs at their
331
      router.  But usually, the <acronym>ISP</acronym> anti-spoofs at their
330
      router, so we do not need to bother that much.</para>
332
      router, so we do not need to bother that much.</para>
331
333
332
    <para>The last rule seems to be an exact duplicate of the default rule,
334
    <para>The last rule seems to be an exact duplicate of the default rule,
333
      that is, do not let anything pass that is not specifically allowed. But
335
      that is, do not let anything pass that is not specifically allowed.  But
334
      there is a difference: all suspected traffic will be logged.</para>
336
      there is a difference: all suspected traffic will be logged.</para>
335
337
336
    <para>There are two rules for passing <acronym>SMTP</acronym> and
338
    <para>There are two rules for passing <acronym>SMTP</acronym> and
337
      <acronym>DNS</acronym> traffic towards the mail server and the name
339
      <acronym>DNS</acronym> traffic towards the mail server and the name
338
      server, if you have them. Obviously the whole rule set should be
340
      server, if you have them.  Obviously the whole rule set should be
339
      flavored to personal taste, this is only a specific example (rule format
341
      flavored to personal taste, this is only a specific example (rule format
340
      is described accurately in the &man.ipfw.8; man page). Note that in
342
      is described accurately in the &man.ipfw.8; man page).  Note that in
341
      order for <quote>relay</quote> and <quote>ns</quote> to work, name service lookups must work
343
      order for <quote>relay</quote> and <quote>ns</quote> to work, name service
342
      <emphasis>before</emphasis> the bridge is enabled. This is an example of
344
      lookups must work <emphasis>before</emphasis> the bridge is enabled.  This
343
      making sure that you set the IP on the correct network card.
345
      is an example of making sure that you set the IP on the correct network
344
      Alternatively it is possible to specify the IP address instead of the
346
      card.  Alternatively it is possible to specify the IP address instead of
345
      host name (required if the machine is IP-less).</para>
347
      the host name (required if the machine is IP-less).</para>
346
348
347
    <para>People that are used to setting up firewalls are probably also used
349
    <para>People that are used to setting up firewalls are probably also used
348
      to either having a <option>reset</option> or a <option>forward</option> rule for ident packets
350
      to either having a <option>reset</option> or a <option>forward</option>
349
      (<acronym>TCP</acronym> port 113). Unfortunately, this is not an
351
      rule for ident packets (<acronym>TCP</acronym> port 113).  Unfortunately,
350
      applicable option with the bridge, so the best thing is to simply pass
352
      this is not an applicable option with the bridge, so the best thing is to
351
      them to their destination. As long as that destination machine is not
353
      simply pass them to their destination.  As long as that destination
352
      running an ident daemon, this is relatively harmless. The alternative is
354
      machine is not running an ident daemon, this is relatively harmless.  The
353
      dropping connections on port 113, which creates some problems with
355
      alternative is dropping connections on port 113, which creates some
354
      services like <acronym>IRC</acronym> (the ident probe must
356
      problems with services like <acronym>IRC</acronym> (the ident probe must
355
      timeout).</para>
357
      timeout).</para>
356
358
357
    <para>The only other thing that is a little weird that you may have
359
    <para>The only other thing that is a little weird that you may have
358
      noticed is that there is a rule to let the bridge machine speak, and
360
      noticed is that there is a rule to let the bridge machine speak, and
359
      another for internal hosts. Remember that this is because the two sets
361
      another for internal hosts.  Remember that this is because the two sets
360
      of traffic will take different paths through the kernel and into the
362
      of traffic will take different paths through the kernel and into the
361
      packet filter. The inside net will go through the bridge, while the
363
      packet filter.  The inside net will go through the bridge, while the
362
      local machine will use the normal IP stack to speak. Thus the two rules
364
      local machine will use the normal IP stack to speak.  Thus the two rules
363
      to handle the different cases. The <literal>in via
365
      to handle the different cases.  The <literal>in via
364
      <devicename>fxp0</devicename></literal> rules work for both paths. In general, if
366
      <devicename>fxp0</devicename></literal> rules work for both paths.  In
365
      you use <option>in via</option> rules throughout the filter, you will need to make an
367
      general, if you use <option>in via</option> rules throughout the filter,
366
      exception for locally generated packets, because they did not come in
368
      you will need to make an exception for locally generated packets, because
367
      via any of our interfaces.</para>
369
      they did not come in via any of our interfaces.</para>
368
  </sect1>
370
  </sect1>
369
371
370
  <sect1 id="filtering-bridges-contributors">
372
  <sect1 id="filtering-bridges-contributors">
371
    <title>Contributors</title>
373
    <title>Contributors</title>
372
374
373
    <para>Many parts of this article have been taken, updated and adapted from
375
    <para>Many parts of this article have been taken, updated and adapted from
374
      an old text about bridging, edited by Nick Sayer. A pair of inspirations
376
      an old text about bridging, edited by Nick Sayer.  A pair of inspirations
375
      are due to an introduction on bridging by Steve Peterson.</para>
377
      are due to an introduction on bridging by Steve Peterson.</para>
376
378
377
    <para>A big thanks to Luigi Rizzo for the implementation of the bridge
379
    <para>A big thanks to Luigi Rizzo for the implementation of the bridge

Return to bug 39509