xref: /freebsd/share/man/man7/firewall.7 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
15ecb12e3SWarner Losh.\" Copyright (C) 2001 Matthew Dillon. All rights reserved.
25ecb12e3SWarner Losh.\"
35ecb12e3SWarner Losh.\" Redistribution and use in source and binary forms, with or without
45ecb12e3SWarner Losh.\" modification, are permitted provided that the following conditions
55ecb12e3SWarner Losh.\" are met:
65ecb12e3SWarner Losh.\" 1. Redistributions of source code must retain the above copyright
75ecb12e3SWarner Losh.\"    notice, this list of conditions and the following disclaimer.
85ecb12e3SWarner Losh.\" 2. Redistributions in binary form must reproduce the above copyright
95ecb12e3SWarner Losh.\"    notice, this list of conditions and the following disclaimer in the
105ecb12e3SWarner Losh.\"    documentation and/or other materials provided with the distribution.
115ecb12e3SWarner Losh.\"
125ecb12e3SWarner Losh.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
135ecb12e3SWarner Losh.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
145ecb12e3SWarner Losh.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
155ecb12e3SWarner Losh.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
165ecb12e3SWarner Losh.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
175ecb12e3SWarner Losh.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
185ecb12e3SWarner Losh.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
195ecb12e3SWarner Losh.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
205ecb12e3SWarner Losh.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
215ecb12e3SWarner Losh.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
225ecb12e3SWarner Losh.\" SUCH DAMAGE.
23fc32c802SMatthew Dillon.\"
24fc32c802SMatthew Dillon.Dd May 26, 2001
25fc32c802SMatthew Dillon.Dt FIREWALL 7
263d45e180SRuslan Ermilov.Os
27fc32c802SMatthew Dillon.Sh NAME
28fc32c802SMatthew Dillon.Nm firewall
29fc32c802SMatthew Dillon.Nd simple firewalls under FreeBSD
30fc32c802SMatthew Dillon.Sh FIREWALL BASICS
31fc32c802SMatthew DillonA Firewall is most commonly used to protect an internal network
32fc32c802SMatthew Dillonfrom an outside network by preventing the outside network from
335203edcdSRuslan Ermilovmaking arbitrary connections into the internal network.
345203edcdSRuslan ErmilovFirewalls
35fc32c802SMatthew Dillonare also used to prevent outside entities from spoofing internal
36fc32c802SMatthew DillonIP addresses and to isolate services such as NFS or SMBFS (Windows
37fc32c802SMatthew Dillonfile sharing) within LAN segments.
38fc32c802SMatthew Dillon.Pp
39fc32c802SMatthew DillonThe
40fc32c802SMatthew Dillon.Fx
41fc32c802SMatthew Dillonfirewalling system also has the capability to limit bandwidth using
42fc32c802SMatthew Dillon.Xr dummynet 4 .
437c86a74bSMike PritchardThis feature can be useful when you need to guarantee a certain
445203edcdSRuslan Ermilovamount of bandwidth for a critical purpose.
455203edcdSRuslan ErmilovFor example, if you
467c86a74bSMike Pritchardare doing video conferencing over the Internet via your
47c70d56a5SChristian Bruefferoffice T1 (1.5 MBits/s), you may wish to bandwidth-limit all other
48c70d56a5SChristian BruefferT1 traffic to 1 MBit/s in order to reserve at least 0.5 MBits
495203edcdSRuslan Ermilovfor your video conferencing connections.
505203edcdSRuslan ErmilovSimilarly if you are
51fc32c802SMatthew Dillonrunning a popular web or ftp site from a colocation facility
52c70d56a5SChristian Bruefferyou might want to limit bandwidth to prevent excessive bandwidth
53c70d56a5SChristian Brueffercharges from your provider.
54fc32c802SMatthew Dillon.Pp
55fc32c802SMatthew DillonFinally,
56fc32c802SMatthew Dillon.Fx
57fc32c802SMatthew Dillonfirewalls may be used to divert packets or change the next-hop
58fc32c802SMatthew Dillonaddress for packets to help route them to the correct destination.
59fc32c802SMatthew DillonPacket diversion is most often used to support NAT (network
60fc32c802SMatthew Dillonaddress translation), which allows an internal network using
61fc32c802SMatthew Dillona private IP space to make connections to the outside for browsing
62fc32c802SMatthew Dillonor other purposes.
63fc32c802SMatthew Dillon.Pp
64fc32c802SMatthew DillonConstructing a firewall may appear to be trivial, but most people
655203edcdSRuslan Ermilovget them wrong.
665203edcdSRuslan ErmilovThe most common mistake is to create an exclusive
675203edcdSRuslan Ermilovfirewall rather than an inclusive firewall.
685203edcdSRuslan ErmilovAn exclusive firewall
69fc32c802SMatthew Dillonallows all packets through except for those matching a set of rules.
700b6579f2SGiorgos KeramidasAn inclusive firewall allows only packets matching the ruleset
715203edcdSRuslan Ermilovthrough.
725203edcdSRuslan ErmilovInclusive firewalls are much, much safer than exclusive
735203edcdSRuslan Ermilovfirewalls but a tad more difficult to build properly.
745203edcdSRuslan ErmilovThe
75fc32c802SMatthew Dillonsecond most common mistake is to blackhole everything except the
765203edcdSRuslan Ermilovparticular port you want to let through.
775203edcdSRuslan ErmilovTCP/IP needs to be able
78fc32c802SMatthew Dillonto get certain types of ICMP errors to function properly - for
795203edcdSRuslan Ermilovexample, to implement MTU discovery.
805203edcdSRuslan ErmilovAlso, a number of common
81fc32c802SMatthew Dillonsystem daemons make reverse connections to the
82fc32c802SMatthew Dillon.Sy auth
83fc32c802SMatthew Dillonservice in an attempt to authenticate the user making a connection.
84fc32c802SMatthew DillonAuth is rather dangerous but the proper implementation is to return
857361df21SGiorgos Keramidasa TCP reset for the connection attempt rather than simply blackholing
865203edcdSRuslan Ermilovthe packet.
875203edcdSRuslan ErmilovWe cover these and other quirks involved with constructing
88fc32c802SMatthew Dillona firewall in the sample firewall section below.
89fc32c802SMatthew Dillon.Sh IPFW KERNEL CONFIGURATION
90aa2ada4eSMurray StokelyYou do not need to create a custom kernel to use the IP firewalling features.
91b895742dSMatthew DillonIf you enable firewalling in your
92*37b983c0SJoel Dahl.Pa /etc/rc.conf
9360eefdafSGiorgos Keramidas(see below), the ipfw kernel module will be loaded automatically
9460eefdafSGiorgos Keramidaswhen necessary.
9560eefdafSGiorgos KeramidasHowever,
96b895742dSMatthew Dillonif you are paranoid you can compile IPFW directly into the
97fc32c802SMatthew Dillon.Fx
98b895742dSMatthew Dillonkernel by using the
99fc32c802SMatthew Dillon.Sy IPFIREWALL
1005203edcdSRuslan Ermilovoption set.
1015203edcdSRuslan ErmilovIf compiled in the kernel, ipfw denies all
1026b3e3c6fSGiorgos Keramidaspackets by default, which means that, if you do not load in
103fc32c802SMatthew Dillona permissive ruleset via
104*37b983c0SJoel Dahl.Pa /etc/rc.conf ,
1056b3e3c6fSGiorgos Keramidasrebooting into your new kernel will take the network offline.
1066b3e3c6fSGiorgos KeramidasThis can prevent you from being able to access your system if you
1075203edcdSRuslan Ermilovare not sitting at the console.
1085203edcdSRuslan ErmilovIt is also quite common to
109fc32c802SMatthew Dillonupdate a kernel to a new release and reboot before updating
1105203edcdSRuslan Ermilovthe binaries.
1115203edcdSRuslan ErmilovThis can result in an incompatibility between
112fc32c802SMatthew Dillonthe
113fc32c802SMatthew Dillon.Xr ipfw 8
114fc32c802SMatthew Dillonprogram and the kernel which prevents it from running in the
115fc32c802SMatthew Dillonboot sequence, also resulting in an inaccessible machine.
116fc32c802SMatthew DillonBecause of these problems the
117fc32c802SMatthew Dillon.Sy IPFIREWALL_DEFAULT_TO_ACCEPT
118fc32c802SMatthew Dillonkernel option is also available which changes the default firewall
1195203edcdSRuslan Ermilovto pass through all packets.
1205203edcdSRuslan ErmilovNote, however, that using this option
121b895742dSMatthew Dillonmay open a small window of opportunity during booting where your
1225203edcdSRuslan Ermilovfirewall passes all packets.
12336a142c4SRuslan ErmilovStill, it is a good option to use
124b895742dSMatthew Dillonwhile getting up to speed with
125fc32c802SMatthew Dillon.Fx
1265203edcdSRuslan Ermilovfirewalling.
1275203edcdSRuslan ErmilovGet rid of it once you understand how it all works
1285203edcdSRuslan Ermilovto close the loophole, though.
1295203edcdSRuslan ErmilovThere is a third option called
130fc32c802SMatthew Dillon.Sy IPDIVERT
131fc32c802SMatthew Dillonwhich allows you to use the firewall to divert packets to a user program
132fc32c802SMatthew Dillonand is necessary if you wish to use
133fc32c802SMatthew Dillon.Xr natd 8
134fc32c802SMatthew Dillonto give private internal networks access to the outside world.
135fc32c802SMatthew DillonIf you want to be able to limit the bandwidth used by certain types of
136fc32c802SMatthew Dillontraffic, the
137fc32c802SMatthew Dillon.Sy DUMMYNET
138fc32c802SMatthew Dillonoption must be used to enable
139fc32c802SMatthew Dillon.Em ipfw pipe
140fc32c802SMatthew Dillonrules.
141fc32c802SMatthew Dillon.Sh SAMPLE IPFW-BASED FIREWALL
142fc32c802SMatthew DillonHere is an example ipfw-based firewall taken from a machine with three
1435203edcdSRuslan Ermilovinterface cards.
1445203edcdSRuslan Ermilovfxp0 is connected to the 'exposed' LAN.
1455203edcdSRuslan ErmilovMachines
1465203edcdSRuslan Ermilovon this LAN are dual-homed with both internal 10.\& IP addresses and
1475203edcdSRuslan ErmilovInternet-routed IP addresses.
1485203edcdSRuslan ErmilovIn our example, 192.100.5.x represents
1497c86a74bSMike Pritchardthe Internet-routed IP block while 10.x.x.x represents the internal
1505203edcdSRuslan Ermilovnetworks.
1510227791bSRuslan ErmilovWhile it is not relevant to the example, 10.0.1.x is
152fc32c802SMatthew Dillonassigned as the internal address block for the LAN on fxp0, 10.0.2.x
153fc32c802SMatthew Dillonfor the LAN on fxp1, and 10.0.3.x for the LAN on fxp2.
154fc32c802SMatthew Dillon.Pp
1557c86a74bSMike PritchardIn this example we want to isolate all three LANs from the Internet
156fc32c802SMatthew Dillonas well as isolate them from each other, and we want to give all
1577c86a74bSMike Pritchardinternal addresses access to the Internet through a NAT gateway running
1585203edcdSRuslan Ermilovon this machine.
1595203edcdSRuslan ErmilovTo make the NAT gateway work, the firewall machine
1607c86a74bSMike Pritchardis given two Internet-exposed addresses on fxp0 in addition to an
1615203edcdSRuslan Ermilovinternal 10.\& address on fxp0: one exposed address (not shown)
162fc32c802SMatthew Dillonrepresents the machine's official address, and the second exposed
163fc32c802SMatthew Dillonaddress (192.100.5.5 in our example) represents the NAT gateway
1645203edcdSRuslan Ermilovrendezvous IP.
1655203edcdSRuslan ErmilovWe make the example more complex by giving the machines
166fc32c802SMatthew Dillonon the exposed LAN internal 10.0.0.x addresses as well as exposed
1675203edcdSRuslan Ermilovaddresses.
1685203edcdSRuslan ErmilovThe idea here is that you can bind internal services
169fc32c802SMatthew Dillonto internal addresses even on exposed machines and still protect
1705203edcdSRuslan Ermilovthose services from the Internet.
1715203edcdSRuslan ErmilovThe only services you run on
172fc32c802SMatthew Dillonexposed IP addresses would be the ones you wish to expose to the
1737c86a74bSMike PritchardInternet.
174fc32c802SMatthew Dillon.Pp
175fc32c802SMatthew DillonIt is important to note that the 10.0.0.x network in our example
1765203edcdSRuslan Ermilovis not protected by our firewall.
1775203edcdSRuslan ErmilovYou must make sure that your
1787c86a74bSMike PritchardInternet router protects this network from outside spoofing.
179fc32c802SMatthew DillonAlso, in our example, we pretty much give the exposed hosts free
180fc32c802SMatthew Dillonreign on our internal network when operating services through
1815203edcdSRuslan Ermilovinternal IP addresses (10.0.0.x).
1825203edcdSRuslan ErmilovThis is somewhat of security
1835203edcdSRuslan Ermilovrisk: what if an exposed host is compromised?
1845203edcdSRuslan ErmilovTo remove the
185fc32c802SMatthew Dillonrisk and force everything coming in via LAN0 to go through
186fc32c802SMatthew Dillonthe firewall, remove rules 01010 and 01011.
187fc32c802SMatthew Dillon.Pp
188fc32c802SMatthew DillonFinally, note that the use of internal addresses represents a
1895203edcdSRuslan Ermilovbig piece of our firewall protection mechanism.
1905203edcdSRuslan ErmilovWith proper
191fc32c802SMatthew Dillonspoofing safeguards in place, nothing outside can directly
192fc32c802SMatthew Dillonaccess an internal (LAN1 or LAN2) host.
193fc32c802SMatthew Dillon.Bd -literal
194fc32c802SMatthew Dillon# /etc/rc.conf
195fc32c802SMatthew Dillon#
196fc32c802SMatthew Dillonfirewall_enable="YES"
197fc32c802SMatthew Dillonfirewall_type="/etc/ipfw.conf"
198fc32c802SMatthew Dillon
199fc32c802SMatthew Dillon# temporary port binding range let
200fc32c802SMatthew Dillon# through the firewall.
201fc32c802SMatthew Dillon#
202fc32c802SMatthew Dillon# NOTE: heavily loaded services running through the firewall may require
203fc32c802SMatthew Dillon# a larger port range for local-size binding.  4000-10000 or 4000-30000
204fc32c802SMatthew Dillon# might be a better choice.
205fc32c802SMatthew Dillonip_portrange_first=4000
206fc32c802SMatthew Dillonip_portrange_last=5000
20763b2f772SRuslan Ermilov\&...
208fc32c802SMatthew Dillon.Ed
209fc32c802SMatthew Dillon.Bd -literal
210fc32c802SMatthew Dillon# /etc/ipfw.conf
211fc32c802SMatthew Dillon#
212fc32c802SMatthew Dillon# FIREWALL: the firewall machine / nat gateway
213fc32c802SMatthew Dillon# LAN0	    10.0.0.X and 192.100.5.X (dual homed)
214fc32c802SMatthew Dillon# LAN1	    10.0.1.X
215fc32c802SMatthew Dillon# LAN2	    10.0.2.X
216fc32c802SMatthew Dillon# sw:	    ethernet switch (unmanaged)
217fc32c802SMatthew Dillon#
2187c86a74bSMike Pritchard# 192.100.5.x represents IP addresses exposed to the Internet
2197c86a74bSMike Pritchard# (i.e. Internet routeable).  10.x.x.x represent internal IPs
220fc32c802SMatthew Dillon# (not exposed)
221fc32c802SMatthew Dillon#
222fc32c802SMatthew Dillon#   [LAN1]
223fc32c802SMatthew Dillon#      ^
224fc32c802SMatthew Dillon#      |
225fc32c802SMatthew Dillon#   FIREWALL -->[LAN2]
226fc32c802SMatthew Dillon#      |
227fc32c802SMatthew Dillon#   [LAN0]
228fc32c802SMatthew Dillon#      |
229fc32c802SMatthew Dillon#      +--> exposed host A
230fc32c802SMatthew Dillon#      +--> exposed host B
231fc32c802SMatthew Dillon#      +--> exposed host C
232fc32c802SMatthew Dillon#      |
233fc32c802SMatthew Dillon#   INTERNET (secondary firewall)
234fc32c802SMatthew Dillon#    ROUTER
235fc32c802SMatthew Dillon#      |
2367c86a74bSMike Pritchard#    [Internet]
237fc32c802SMatthew Dillon#
238fc32c802SMatthew Dillon# NOT SHOWN:  The INTERNET ROUTER must contain rules to disallow
239fc32c802SMatthew Dillon# all packets with source IP addresses in the 10. block in order
240fc32c802SMatthew Dillon# to protect the dual-homed 10.0.0.x block.  Exposed hosts are
241fc32c802SMatthew Dillon# not otherwise protected in this example - they should only bind
242fc32c802SMatthew Dillon# exposed services to exposed IPs but can safely bind internal
243fc32c802SMatthew Dillon# services to internal IPs.
244fc32c802SMatthew Dillon#
245fc32c802SMatthew Dillon# The NAT gateway works by taking packets sent from internal
246fc32c802SMatthew Dillon# IP addresses to external IP addresses and routing them to natd, which
247fc32c802SMatthew Dillon# is listening on port 8668.   This is handled by rule 00300.  Data coming
248fc32c802SMatthew Dillon# back to natd from the outside world must also be routed to natd using
249fc32c802SMatthew Dillon# rule 00301.  To make the example interesting, we note that we do
250fc32c802SMatthew Dillon# NOT have to run internal requests to exposed hosts through natd
251fc32c802SMatthew Dillon# (rule 00290) because those exposed hosts know about our
252fc32c802SMatthew Dillon# 10. network.  This can reduce the load on natd.  Also note that we
253fc32c802SMatthew Dillon# of course do not have to route internal<->internal traffic through
254fc32c802SMatthew Dillon# natd since those hosts know how to route our 10. internal network.
255fc32c802SMatthew Dillon# The natd command we run from /etc/rc.local is shown below.  See
256fc32c802SMatthew Dillon# also the in-kernel version of natd, ipnat.
257fc32c802SMatthew Dillon#
258fc32c802SMatthew Dillon#	natd -s -u -a 208.161.114.67
259fc32c802SMatthew Dillon#
260fc32c802SMatthew Dillon#
261fc32c802SMatthew Dillonadd 00290 skipto 1000 ip from 10.0.0.0/8 to 192.100.5.0/24
262fc32c802SMatthew Dillonadd 00300 divert 8668 ip from 10.0.0.0/8 to not 10.0.0.0/8
263fc32c802SMatthew Dillonadd 00301 divert 8668 ip from not 10.0.0.0/8 to 192.100.5.5
264fc32c802SMatthew Dillon
265fc32c802SMatthew Dillon# Short cut the rules to avoid running high bandwidths through
266fc32c802SMatthew Dillon# the entire rule set.  Allow established tcp connections through,
267fc32c802SMatthew Dillon# and shortcut all outgoing packets under the assumption that
268fc32c802SMatthew Dillon# we need only firewall incoming packets.
269fc32c802SMatthew Dillon#
270fc32c802SMatthew Dillon# Allowing established tcp connections through creates a small
271fc32c802SMatthew Dillon# hole but may be necessary to avoid overloading your firewall.
272fc32c802SMatthew Dillon# If you are worried, you can move the rule to after the spoof
273fc32c802SMatthew Dillon# checks.
274fc32c802SMatthew Dillon#
275fc32c802SMatthew Dillonadd 01000 allow tcp from any to any established
276fc32c802SMatthew Dillonadd 01001 allow all from any to any out via fxp0
277fc32c802SMatthew Dillonadd 01001 allow all from any to any out via fxp1
278fc32c802SMatthew Dillonadd 01001 allow all from any to any out via fxp2
279fc32c802SMatthew Dillon
280fc32c802SMatthew Dillon# Spoof protection.  This depends on how well you trust your
281fc32c802SMatthew Dillon# internal networks.  Packets received via fxp1 MUST come from
282fc32c802SMatthew Dillon# 10.0.1.x.  Packets received via fxp2 MUST come from 10.0.2.x.
283fc32c802SMatthew Dillon# Packets received via fxp0 cannot come from the LAN1 or LAN2
2840227791bSRuslan Ermilov# blocks.  We cannot protect 10.0.0.x here, the Internet router
285fc32c802SMatthew Dillon# must do that for us.
286fc32c802SMatthew Dillon#
287fc32c802SMatthew Dillonadd 01500 deny all from not 10.0.1.0/24 in via fxp1
288fc32c802SMatthew Dillonadd 01500 deny all from not 10.0.2.0/24 in via fxp2
289fc32c802SMatthew Dillonadd 01501 deny all from 10.0.1.0/24 in via fxp0
290fc32c802SMatthew Dillonadd 01501 deny all from 10.0.2.0/24 in via fxp0
291fc32c802SMatthew Dillon
292fc32c802SMatthew Dillon# In this example rule set there are no restrictions between
293fc32c802SMatthew Dillon# internal hosts, even those on the exposed LAN (as long as
294fc32c802SMatthew Dillon# they use an internal IP address).  This represents a
295fc32c802SMatthew Dillon# potential security hole (what if an exposed host is
296fc32c802SMatthew Dillon# compromised?).  If you want full restrictions to apply
297fc32c802SMatthew Dillon# between the three LANs, firewalling them off from each
298fc32c802SMatthew Dillon# other for added security, remove these two rules.
299fc32c802SMatthew Dillon#
300fc32c802SMatthew Dillon# If you want to isolate LAN1 and LAN2, but still want
301fc32c802SMatthew Dillon# to give exposed hosts free reign with each other, get
302fc32c802SMatthew Dillon# rid of rule 01010 and keep rule 01011.
303fc32c802SMatthew Dillon#
304fc32c802SMatthew Dillon# (commented out, uncomment for less restrictive firewall)
305fc32c802SMatthew Dillon#add 01010 allow all from 10.0.0.0/8 to 10.0.0.0/8
306fc32c802SMatthew Dillon#add 01011 allow all from 192.100.5.0/24 to 192.100.5.0/24
307fc32c802SMatthew Dillon#
308fc32c802SMatthew Dillon
309fc32c802SMatthew Dillon# SPECIFIC SERVICES ALLOWED FROM SPECIFIC LANS
310fc32c802SMatthew Dillon#
311fc32c802SMatthew Dillon# If using a more restrictive firewall, allow specific LANs
312fc32c802SMatthew Dillon# access to specific services running on the firewall itself.
313fc32c802SMatthew Dillon# In this case we assume LAN1 needs access to filesharing running
314fc32c802SMatthew Dillon# on the firewall.  If using a less restrictive firewall
3150227791bSRuslan Ermilov# (allowing rule 01010), you do not need these rules.
316fc32c802SMatthew Dillon#
317fc32c802SMatthew Dillonadd 01012 allow tcp from 10.0.1.0/8 to 10.0.1.1 139
318fc32c802SMatthew Dillonadd 01012 allow udp from 10.0.1.0/8 to 10.0.1.1 137,138
319fc32c802SMatthew Dillon
320fc32c802SMatthew Dillon# GENERAL SERVICES ALLOWED TO CROSS INTERNAL AND EXPOSED LANS
321fc32c802SMatthew Dillon#
322fc32c802SMatthew Dillon# We allow specific UDP services through: DNS lookups, ntalk, and ntp.
323fc32c802SMatthew Dillon# Note that internal services are protected by virtue of having
324fc32c802SMatthew Dillon# spoof-proof internal IP addresses (10. net), so these rules
325fc32c802SMatthew Dillon# really only apply to services bound to exposed IPs.  We have
326fc32c802SMatthew Dillon# to allow UDP fragments or larger fragmented UDP packets will
327fc32c802SMatthew Dillon# not survive the firewall.
328fc32c802SMatthew Dillon#
329fc32c802SMatthew Dillon# If we want to expose high-numbered temporary service ports
330fc32c802SMatthew Dillon# for things like DNS lookup responses we can use a port range,
331fc32c802SMatthew Dillon# in this example 4000-65535, and we set to /etc/rc.conf variables
332fc32c802SMatthew Dillon# on all exposed machines to make sure they bind temporary ports
333fc32c802SMatthew Dillon# to the exposed port range (see rc.conf example above)
334fc32c802SMatthew Dillon#
335fc32c802SMatthew Dillonadd 02000 allow udp from any to any 4000-65535,domain,ntalk,ntp
336fc32c802SMatthew Dillonadd 02500 allow udp from any to any frag
337fc32c802SMatthew Dillon
338fc32c802SMatthew Dillon# Allow similar services for TCP.  Again, these only apply to
339fc32c802SMatthew Dillon# services bound to exposed addresses.  NOTE: we allow 'auth'
340fc32c802SMatthew Dillon# through but do not actually run an identd server on any exposed
341fc32c802SMatthew Dillon# port.  This allows the machine being authed to respond with a
342fc32c802SMatthew Dillon# TCP RESET.  Throwing the packet away would result in delays
343fc32c802SMatthew Dillon# when connecting to remote services that do reverse ident lookups.
344fc32c802SMatthew Dillon#
345fc32c802SMatthew Dillon# Note that we do not allow tcp fragments through, and that we do
346fc32c802SMatthew Dillon# not allow fragments in general (except for UDP fragments).  We
347fc32c802SMatthew Dillon# expect the TCP mtu discovery protocol to work properly so there
348fc32c802SMatthew Dillon# should be no TCP fragments.
349fc32c802SMatthew Dillon#
350fc32c802SMatthew Dillonadd 03000 allow tcp from any to any http,https
351fc32c802SMatthew Dillonadd 03000 allow tcp from any to any 4000-65535,ssh,smtp,domain,ntalk
352fc32c802SMatthew Dillonadd 03000 allow tcp from any to any auth,pop3,ftp,ftp-data
353fc32c802SMatthew Dillon
354455c7374SMatthew Dillon# It is important to allow certain ICMP types through, here is a list
355455c7374SMatthew Dillon# of general ICMP types.  Note that it is important to let ICMP type 3
356455c7374SMatthew Dillon# through.
357fc32c802SMatthew Dillon#
358fc32c802SMatthew Dillon#	0	Echo Reply
359455c7374SMatthew Dillon#	3	Destination Unreachable (used by TCP MTU discovery, aka
360455c7374SMatthew Dillon#					packet-too-big)
361fc32c802SMatthew Dillon#	4	Source Quench (typically not allowed)
362fc32c802SMatthew Dillon#	5	Redirect (typically not allowed - can be dangerous!)
363fc32c802SMatthew Dillon#	8	Echo
364fc32c802SMatthew Dillon#	11	Time Exceeded
365fc32c802SMatthew Dillon#	12	Parameter Problem
366fc32c802SMatthew Dillon#	13	Timestamp
367fc32c802SMatthew Dillon#	14	Timestamp Reply
368fc32c802SMatthew Dillon#
369fc32c802SMatthew Dillon# Sometimes people need to allow ICMP REDIRECT packets, which is
3707c86a74bSMike Pritchard# type 5, but if you allow it make sure that your Internet router
371fc32c802SMatthew Dillon# disallows it.
372fc32c802SMatthew Dillon
373455c7374SMatthew Dillonadd 04000 allow icmp from any to any icmptypes 0,3,8,11,12,13,14
374fc32c802SMatthew Dillon
375fc32c802SMatthew Dillon# log any remaining fragments that get through.  Might be useful,
3760227791bSRuslan Ermilov# otherwise do not bother.  Have a final deny rule as a safety to
3777c86a74bSMike Pritchard# guarantee that your firewall is inclusive no matter how the kernel
378fc32c802SMatthew Dillon# is configured.
379fc32c802SMatthew Dillon#
380fc32c802SMatthew Dillonadd 05000 deny log ip from any to any frag
381fc32c802SMatthew Dillonadd 06000 deny all from any to any
382fc32c802SMatthew Dillon.Ed
383fc32c802SMatthew Dillon.Sh PORT BINDING INTERNAL AND EXTERNAL SERVICES
38436a142c4SRuslan ErmilovWe have mentioned multi-homing hosts and binding services to internal or
3850227791bSRuslan Ermilovexternal addresses but we have not really explained it.
3865203edcdSRuslan ErmilovWhen you have a
387fc32c802SMatthew Dillonhost with multiple IP addresses assigned to it, you can bind services run
3885203edcdSRuslan Ermilovon that host to specific IPs or interfaces rather than all IPs.
3895203edcdSRuslan ErmilovTake
3905203edcdSRuslan Ermilovthe firewall machine for example: with three interfaces
391fc32c802SMatthew Dillonand two exposed IP addresses
392fc32c802SMatthew Dillonon one of those interfaces, the firewall machine is known by 5 different
393fc32c802SMatthew DillonIP addresses (10.0.0.1, 10.0.1.1, 10.0.2.1, 192.100.5.5, and say
3945203edcdSRuslan Ermilov192.100.5.1).
3955203edcdSRuslan ErmilovIf the firewall is providing file sharing services to the
396fc32c802SMatthew Dillonwindows LAN segment (say it is LAN1), you can use samba's 'bind interfaces'
3975203edcdSRuslan Ermilovdirective to specifically bind it to just the LAN1 IP address.
3985203edcdSRuslan ErmilovThat
399fc32c802SMatthew Dillonway the file sharing services will not be made available to other LAN
4005203edcdSRuslan Ermilovsegments.
4015203edcdSRuslan ErmilovThe same goes for NFS.
4025203edcdSRuslan ErmilovIf LAN2 has your UNIX engineering
4035203edcdSRuslan Ermilovworkstations, you can tell nfsd to bind specifically to 10.0.2.1.
4045203edcdSRuslan ErmilovYou
405fc32c802SMatthew Dilloncan specify how to bind virtually every service on the machine and you
406fc32c802SMatthew Dilloncan use a light
407fc32c802SMatthew Dillon.Xr jail 8
408fc32c802SMatthew Dillonto indirectly bind services that do not otherwise give you the option.
409fc32c802SMatthew Dillon.Sh SEE ALSO
4105521ff5aSRuslan Ermilov.Xr dummynet 4 ,
411fc32c802SMatthew Dillon.Xr ipnat 5 ,
4125521ff5aSRuslan Ermilov.Xr rc.conf 5 ,
413bf7f20c2SRuslan Ermilov.Xr smb.conf 5 Pq Pa ports/net/samba ,
414bf7f20c2SRuslan Ermilov.Xr samba 7 Pq Pa ports/net/samba ,
4155521ff5aSRuslan Ermilov.Xr config 8 ,
4165521ff5aSRuslan Ermilov.Xr ipfw 8 ,
417f0ea72a0SChristian Brueffer.Xr ipnat 8 ,
418fc32c802SMatthew Dillon.Xr jail 8 ,
419fc32c802SMatthew Dillon.Xr natd 8 ,
4205521ff5aSRuslan Ermilov.Xr nfsd 8
421fc32c802SMatthew Dillon.Sh ADDITIONAL READING
422c0854fb7SRuslan Ermilov.Bl -tag -width indent
423faf58d14SMax Laier.It Nm Ipfilter
424fc32c802SMatthew Dillon.Xr ipf 5 ,
425fc32c802SMatthew Dillon.Xr ipf 8 ,
426fc32c802SMatthew Dillon.Xr ipfstat 8
427faf58d14SMax Laier.It Nm Packet Filter
428faf58d14SMax Laier.Xr pf.conf 5 ,
429faf58d14SMax Laier.Xr pfctl 8 ,
430faf58d14SMax Laier.Xr pflogd 8
431faf58d14SMax Laier.El
432fc32c802SMatthew Dillon.Sh HISTORY
433fc32c802SMatthew DillonThe
434fc32c802SMatthew Dillon.Nm
435fc32c802SMatthew Dillonmanual page was originally written by
436fc32c802SMatthew Dillon.An Matthew Dillon
437fc32c802SMatthew Dillonand first appeared
438fc32c802SMatthew Dillonin
439fc32c802SMatthew Dillon.Fx 4.3 ,
440fc32c802SMatthew DillonMay 2001.
441