source: postlfs/security/firewalling.xml@ b84342d6

10.0 10.1 11.0 11.1 11.2 11.3 12.0 12.1 7.10 7.4 7.5 7.6 7.6-blfs 7.6-systemd 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 9.0 9.1 basic bdubbs/svn elogind gnome kde5-13430 kde5-14269 kde5-14686 kea ken/TL2024 ken/inkscape-core-mods ken/tuningfonts krejzi/svn lazarus lxqt nosym perl-modules plabs/newcss plabs/python-mods python3.11 qt5new rahul/power-profiles-daemon renodr/vulkan-addition systemd-11177 systemd-13485 trunk upgradedb xry111/intltool xry111/llvm18 xry111/soup3 xry111/test-20220226 xry111/xf86-video-removal
Last change on this file since b84342d6 was a805e52, checked in by Bruce Dubbs <bdubbs@…>, 12 years ago

Add a reference on maintaining a RAID system.
Minor updates to firewall script.
Fix instructions for creating dhclient version of ifconfig.eth0.

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@9351 af4574ff-66df-0310-9fd7-8a98e5e911e0

  • Property mode set to 100644
File size: 24.8 KB
RevLine 
[b4b71892]1<?xml version="1.0" encoding="ISO-8859-1"?>
[6732c094]2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
[b4b71892]4 <!ENTITY % general-entities SYSTEM "../../general.ent">
5 %general-entities;
6]>
7
[dd362e5]8<sect1 id="fw-firewall" xreflabel="Firewalling">
[8920dfa]9 <?dbhtml filename="firewall.html"?>
10
11 <sect1info>
12 <othername>$LastChangedBy$</othername>
13 <date>$Date$</date>
14 </sect1info>
15
16 <title>Setting Up a Network Firewall</title>
17
[0afcfa88]18 <para>Before you read this part of the chapter, you should have
[8920dfa]19 already installed iptables as described in the previous section.</para>
20
21 <sect2 id="fw-intro" xreflabel="Firewalling Introduction">
22 <title>Introduction to Firewall Creation</title>
23
[0afcfa88]24 <para>The general purpose of a firewall is to protect a computer or
[d612b9f]25 a network against malicious access.</para>
[8920dfa]26
[0afcfa88]27 <para>In a perfect world, every daemon or service on every machine
28 is perfectly configured and immune to flaws such as buffer overflows
29 or other problems regarding its security. Furthermore, you trust
30 every user accessing your services. In this world, you do not need
[8920dfa]31 to have a firewall.</para>
32
[0afcfa88]33 <para>In the real world however, daemons may be misconfigured and
34 exploits against essential services are freely available. You may
35 wish to choose which services are accessible by certain machines or
36 you may wish to limit which machines or applications are allowed
37 external access. Alternatively, you may simply not trust some of
38 your applications or users. You are probably connected to the
[8920dfa]39 Internet. In this world, a firewall is essential.</para>
40
[0afcfa88]41 <para>Don't assume however, that having a firewall makes careful
42 configuration redundant, or that it makes any negligent
43 misconfiguration harmless. It doesn't prevent anyone from exploiting
44 a service you intentionally offer but haven't recently updated or
45 patched after an exploit went public. Despite having a firewall, you
46 need to keep applications and daemons on your system properly
47 configured and up to date. A firewall is not a cure all, but should
[1ef78bc]48 be an essential part of your overall security strategy.</para>
[8920dfa]49
50 </sect2>
51
52 <sect2>
53 <title>Meaning of the Word "Firewall"</title>
54
55 <para>The word firewall can have several different meanings.</para>
56
57 <sect3>
58 <title><xref linkend="fw-persFw"/></title>
59
[1ef78bc]60 <para>This is a hardware device or software program commercially sold (or
61 offered via freeware) by companies such as Symantec which claims that
62 it secures a home or desktop computer connected to the Internet. This
63 type of firewall is highly relevant for users who do not know how their
[0afcfa88]64 computers might be accessed via the Internet or how to disable
65 that access, especially if they are always online and connected
[8920dfa]66 via broadband links.</para>
67
68 </sect3>
69
70 <sect3>
71 <title><xref linkend="fw-masqRouter"/></title>
72
[bbdb0ff4]73 <para>This is a system placed between the Internet and an intranet.
[0afcfa88]74 To minimize the risk of compromising the firewall itself, it should
[bbdb0ff4]75 generally have only one role&mdash;that of protecting the intranet.
76 Although not completely risk free, the tasks of doing the routing and
[0afcfa88]77 IP masquerading (rewriting IP headers of the packets it routes from
78 clients with private IP addresses onto the Internet so that they seem
79 to come from the firewall itself) are commonly considered relatively
[8920dfa]80 secure.</para>
81
82 </sect3>
83
[d612b9f]84 <sect3>
85 <title><xref linkend="fw-busybox"/></title>
[8920dfa]86
[0afcfa88]87 <para>This is often an old computer you may have retired and nearly
88 forgotten, performing masquerading or routing functions, but offering
89 non-firewall services such as a web-cache or mail. This may be used
[1ef78bc]90 for home networks, but is not to be considered as secure as a firewall
[0afcfa88]91 only machine because the combination of server and router/firewall on
[8920dfa]92 one machine raises the complexity of the setup.</para>
93
94 </sect3>
95
96 <sect3>
[0afcfa88]97 <title>Firewall with a Demilitarized Zone [Not Further
[8920dfa]98 Described Here]</title>
99
[0afcfa88]100 <para>This box performs masquerading or routing, but grants public
[1ef78bc]101 access to some branch of your network which, because of public IPs
[0afcfa88]102 and a physically separated structure, is essentially a separate
103 network with direct Internet access. The servers on this network are
104 those which must be easily accessible from both the Internet and
105 intranet. The firewall protects both networks. This type of firewall
[8920dfa]106 has a minimum of three network interfaces.</para>
107
108 </sect3>
109
110 <sect3>
111 <title>Packetfilter</title>
112
[0afcfa88]113 <para>This type of firewall does routing or masquerading, but does
114 not maintain a state table of ongoing communication streams. It is
[1ef78bc]115 fast, but quite limited in its ability to block undesired packets
[8920dfa]116 without blocking desired packets.</para>
117
118 </sect3>
119
120 </sect2>
121
122 <sect2 id="fw-writing" xreflabel="writing the firewalling-setup-scripts">
123 <title>Now You Can Start to Build your Firewall</title>
124
125 <caution>
[0afcfa88]126 <para>This introduction on how to setup a firewall is not a
127 complete guide to securing systems. Firewalling is a complex
128 issue that requires careful configuration. The scripts quoted
129 here are simply intended to give examples of how a firewall
130 works. They are not intended to fit into any particular
131 configuration and may not provide complete protection from
[8920dfa]132 an attack.</para>
133
[0afcfa88]134 <para>Customization of these scripts for your specific situation
135 will be necessary for an optimal configuration, but you should
136 make a serious study of the iptables documentation and creating
137 firewalls in general before hacking away. Have a look at the
138 list of <xref linkend="fw-library"/> at the end of this section for
139 more details. There you will find a list of URLs that contain quite
[8920dfa]140 comprehensive information about building your own firewall.</para>
141 </caution>
142
[1ef78bc]143 <para>The firewall configuration script installed in the iptables section
[0afcfa88]144 differs from the standard configuration script. It only has two of
145 the standard targets: start and status. The other targets are clear
[1ef78bc]146 and lock. For instance if you issue:</para>
[8920dfa]147
148<screen role="root"><userinput>/etc/rc.d/init.d/iptables start</userinput></screen>
149
[0afcfa88]150 <para>the firewall will be restarted just as it is upon system startup.
151 The status target will present a list of all currently implemented
152 rules. The clear target turns off all firewall rules and the lock
153 target will block all packets in and out of the computer with the
[8920dfa]154 exception of the loopback interface.</para>
155
[0afcfa88]156 <para>The main startup firewall is located in the file
157 <filename>/etc/rc.d/rc.iptables</filename>. The sections below provide
[8920dfa]158 three different approaches that can be used for a system.</para>
159
160 <note>
[bbdb0ff4]161 <para>You should always run your firewall rules from a script.
[0afcfa88]162 This ensures consistency and a record of what was done. It also
163 allows retention of comments that are essential for understanding
[8920dfa]164 the rules long after they were written.</para>
165 </note>
166
167 <sect3 id="fw-persFw" xreflabel="Personal Firewall">
168 <title>Personal Firewall</title>
169
[0afcfa88]170 <para>A Personal Firewall is designed to let you access all the
171 services offered on the Internet, but keep your box secure and
[8920dfa]172 your data private.</para>
173
[0afcfa88]174 <para>Below is a slightly modified version of Rusty Russell's
175 recommendation from the <ulink
[8920dfa]176 url="http://www.netfilter.org/documentation/HOWTO/packet-filtering-HOWTO.html">
[0afcfa88]177 Linux 2.4 Packet Filtering HOWTO</ulink>. It is still applicable
[8920dfa]178 to the Linux 2.6 kernels.</para>
179
[8e37798]180<screen role="root"><?dbfo keep-together="auto"?><userinput>cat &gt; /etc/rc.d/rc.iptables &lt;&lt; "EOF"
[8920dfa]181<literal>#!/bin/sh
[b4b71892]182
[0e3848e3]183# Begin $rc_base/rc.iptables
[b4b71892]184
[0afcfa88]185# Insert connection-tracking modules
[dd362e5]186# (not needed if built into the kernel)
[b4b71892]187modprobe ip_tables
188modprobe iptable_filter
189modprobe ip_conntrack
190modprobe ip_conntrack_ftp
191modprobe ipt_state
192modprobe ipt_LOG
193
[0e3848e3]194# Enable broadcast echo Protection
195echo 1 &gt; /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
[dd362e5]196
[0e3848e3]197# Disable Source Routed Packets
198echo 0 &gt; /proc/sys/net/ipv4/conf/all/accept_source_route
[c81fed4]199echo 0 &gt; /proc/sys/net/ipv4/conf/default/accept_source_route
[b4b71892]200
[0e3848e3]201# Enable TCP SYN Cookie Protection
202echo 1 &gt; /proc/sys/net/ipv4/tcp_syncookies
[b4b71892]203
[0e3848e3]204# Disable ICMP Redirect Acceptance
[5f2eb36]205echo 0 &gt; /proc/sys/net/ipv4/conf/default/accept_redirects
[0e3848e3]206
[5f2eb36]207# Do not send Redirect Messages
[0e3848e3]208echo 0 &gt; /proc/sys/net/ipv4/conf/all/send_redirects
[c81fed4]209echo 0 &gt; /proc/sys/net/ipv4/conf/default/send_redirects
[0e3848e3]210
[0afcfa88]211# Drop Spoofed Packets coming in on an interface, where responses
[0e3848e3]212# would result in the reply going out a different interface.
213echo 1 &gt; /proc/sys/net/ipv4/conf/all/rp_filter
[c81fed4]214echo 1 &gt; /proc/sys/net/ipv4/conf/default/rp_filter
[b4b71892]215
[0e3848e3]216# Log packets with impossible addresses.
217echo 1 &gt; /proc/sys/net/ipv4/conf/all/log_martians
[c81fed4]218echo 1 &gt; /proc/sys/net/ipv4/conf/default/log_martians
[b4b71892]219
[dd362e5]220# be verbose on dynamic ip-addresses (not needed in case of static IP)
[b4b71892]221echo 2 &gt; /proc/sys/net/ipv4/ip_dynaddr
222
[0afcfa88]223# disable Explicit Congestion Notification
[dd362e5]224# too many routers are still ignorant
[b4b71892]225echo 0 &gt; /proc/sys/net/ipv4/tcp_ecn
226
[0e3848e3]227# Set a known state
228iptables -P INPUT DROP
229iptables -P FORWARD DROP
230iptables -P OUTPUT DROP
[d612b9f]231
[0e3848e3]232# These lines are here in case rules are already in place and the
233# script is ever rerun on the fly. We want to remove all rules and
[bfb7882]234# pre-existing user defined chains before we implement new rules.
[0e3848e3]235iptables -F
236iptables -X
237iptables -Z
[d612b9f]238
[0e3848e3]239iptables -t nat -F
240
241# Allow local-only connections
242iptables -A INPUT -i lo -j ACCEPT
243
[0afcfa88]244# Free output on any interface to any ip for any service
[0e3848e3]245# (equal to -P ACCEPT)
246iptables -A OUTPUT -j ACCEPT
247
248# Permit answers on already established connections
[0afcfa88]249# and permit new connections related to established ones
[0e3848e3]250# (e.g. port mode ftp)
251iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
252
253# Log everything else. What's Windows' latest exploitable vulnerability?
254iptables -A INPUT -j LOG --log-prefix "FIREWALL:INPUT "
255
[8920dfa]256# End $rc_base/rc.iptables</literal>
[49625cbc]257EOF
258chmod 700 /etc/rc.d/rc.iptables</userinput></screen>
[b4b71892]259
[0afcfa88]260 <para>This script is quite simple, it drops all traffic coming
[1ef78bc]261 into your computer that wasn't initiated from your computer, but
[0afcfa88]262 as long as you are simply surfing the Internet you are unlikely
[d612b9f]263 to exceed its limits.</para>
[b4b71892]264
[0afcfa88]265 <para>If you frequently encounter certain delays at accessing
[1ef78bc]266 FTP servers, take a look at <xref linkend="fw-BB-4"/>.</para>
[b4b71892]267
[0afcfa88]268 <para>Even if you have daemons or services running on your system,
269 these will be inaccessible everywhere but from your computer itself.
270 If you want to allow access to services on your machine, such as
271 <command>ssh</command> or <command>ping</command>, take a look at
[d612b9f]272 <xref linkend="fw-busybox"/>.</para>
[b4b71892]273
[8920dfa]274 </sect3>
[b4b71892]275
[8920dfa]276 <sect3 id="fw-masqRouter" xreflabel="Masquerading Router">
277 <title>Masquerading Router</title>
[b4b71892]278
[0afcfa88]279 <para>A true Firewall has two interfaces, one connected to an
280 intranet, in this example <emphasis role="strong">eth0</emphasis>,
281 and one connected to the Internet, here <emphasis
282 role="strong">ppp0</emphasis>. To provide the maximum security
283 for the firewall itself, make sure that there are no unnecessary
[8920dfa]284 servers running on it such as <application>X11</application> et
[0afcfa88]285 al. As a general principle, the firewall itself should not access
[1ef78bc]286 any untrusted service (think of a remote server giving answers that
287 makes a daemon on your system crash, or even worse, that implements
[8920dfa]288 a worm via a buffer-overflow).</para>
[0e3848e3]289
[8e37798]290<screen role="root"><?dbfo keep-together="auto"?><userinput>cat &gt; /etc/rc.d/rc.iptables &lt;&lt; "EOF"
[8920dfa]291<literal>#!/bin/sh
[b4b71892]292
[0e3848e3]293# Begin $rc_base/rc.iptables
[b4b71892]294
295echo
[0e3848e3]296echo "You're using the example configuration for a setup of a firewall"
297echo "from Beyond Linux From Scratch."
[b4b71892]298echo "This example is far from being complete, it is only meant"
299echo "to be a reference."
300echo "Firewall security is a complex issue, that exceeds the scope"
[0e3848e3]301echo "of the configuration rules below."
302echo "You can find additional information"
[b4b71892]303echo "about firewalls in Chapter 4 of the BLFS book."
[4e88613]304echo "http://www.&lfs-domainname;/blfs"
[b4b71892]305echo
306
307# Insert iptables modules (not needed if built into the kernel).
308
309modprobe ip_tables
310modprobe iptable_filter
311modprobe ip_conntrack
312modprobe ip_conntrack_ftp
313modprobe ipt_state
314modprobe iptable_nat
315modprobe ip_nat_ftp
316modprobe ipt_MASQUERADE
317modprobe ipt_LOG
318modprobe ipt_REJECT
319
[0e3848e3]320# Enable broadcast echo Protection
321echo 1 &gt; /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
322
323# Disable Source Routed Packets
324echo 0 &gt; /proc/sys/net/ipv4/conf/all/accept_source_route
325
326# Enable TCP SYN Cookie Protection
327echo 1 &gt; /proc/sys/net/ipv4/tcp_syncookies
328
329# Disable ICMP Redirect Acceptance
330echo 0 &gt; /proc/sys/net/ipv4/conf/all/accept_redirects
331
[a805e52]332# Don't send Redirect Messages
[5f2eb36]333echo 0 &gt; /proc/sys/net/ipv4/conf/default/send_redirects
[0e3848e3]334
335# Drop Spoofed Packets coming in on an interface where responses
336# would result in the reply going out a different interface.
[5f2eb36]337echo 1 &gt; /proc/sys/net/ipv4/conf/default/rp_filter
[0e3848e3]338
339# Log packets with impossible addresses.
340echo 1 &gt; /proc/sys/net/ipv4/conf/all/log_martians
341
342# Be verbose on dynamic ip-addresses (not needed in case of static IP)
343echo 2 &gt; /proc/sys/net/ipv4/ip_dynaddr
344
[0afcfa88]345# Disable Explicit Congestion Notification
[0e3848e3]346# Too many routers are still ignorant
347echo 0 &gt; /proc/sys/net/ipv4/tcp_ecn
348
349# Set a known state
350iptables -P INPUT DROP
351iptables -P FORWARD DROP
352iptables -P OUTPUT DROP
[d612b9f]353
[0e3848e3]354# These lines are here in case rules are already in place and the
355# script is ever rerun on the fly. We want to remove all rules and
[bfb7882]356# pre-existing user defined chains before we implement new rules.
[0e3848e3]357iptables -F
358iptables -X
359iptables -Z
[d612b9f]360
[0e3848e3]361iptables -t nat -F
362
363# Allow local connections
[b4b71892]364iptables -A INPUT -i lo -j ACCEPT
365iptables -A OUTPUT -o lo -j ACCEPT
366
[0e3848e3]367# Allow forwarding if the initiated on the intranet
[b4b71892]368iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
[0e3848e3]369iptables -A FORWARD -i ! ppp+ -m state --state NEW -j ACCEPT
[b4b71892]370
[0e3848e3]371# Do masquerading
[dd362e5]372# (not needed if intranet is not using private ip-addresses)
[b4b71892]373iptables -t nat -A POSTROUTING -o ppp+ -j MASQUERADE
374
[0afcfa88]375# Log everything for debugging
[0e3848e3]376# (last of all rules, but before policy rules)
[5f2eb36]377iptables -A INPUT -j LOG --log-prefix "FIREWALL:INPUT "
378iptables -A FORWARD -j LOG --log-prefix "FIREWALL:FORWARD "
[b4b71892]379iptables -A OUTPUT -j LOG --log-prefix "FIREWALL:OUTPUT "
380
[0afcfa88]381# Enable IP Forwarding
[8920dfa]382echo 1 &gt; /proc/sys/net/ipv4/ip_forward</literal>
[49625cbc]383EOF
384chmod 700 /etc/rc.d/rc.iptables</userinput></screen>
[8920dfa]385
[0afcfa88]386 <para>With this script your intranet should be reasonably secure
387 against external attacks. No one should be able to setup a new
388 connection to any internal service and, if it's masqueraded,
389 makes your intranet invisible to the Internet. Furthermore, your
390 firewall should be relatively safe because there are no services
[8920dfa]391 running that a cracker could attack.</para>
392
393 <note>
[0afcfa88]394 <para>If the interface you're connecting to the Internet
[1ef78bc]395 doesn't connect via PPP, you will need to change
[3597eb6]396 <replaceable>&lt;ppp+&gt;</replaceable> to the name of the interface
[1ef78bc]397 (e.g., <emphasis role="strong">eth1</emphasis>) which you are
[8920dfa]398 using.</para>
399 </note>
400
401 </sect3>
402
403 <sect3 id="fw-busybox" xreflabel="BusyBox">
404 <title>BusyBox</title>
405
[0afcfa88]406 <para>This scenario isn't too different from the <xref
407 linkend="fw-masqRouter"/>, but additionally offers some
408 services to your intranet. Examples of this can be when
409 you want to administer your firewall from another host on
[8920dfa]410 your intranet or use it as a proxy or a name server.</para>
411
412 <note>
[0afcfa88]413 <para>Outlining a true concept of how to protect a server that
414 offers services on the Internet goes far beyond the scope of
415 this document. See the references at the end of this section
[8920dfa]416 for more information.</para>
417 </note>
418
419 <para>Be cautious. Every service you have enabled makes your
[0afcfa88]420 setup more complex and your firewall less secure. You are
421 exposed to the risks of misconfigured services or running
422 a service with an exploitable bug. A firewall should generally
423 not run any extra services. See the introduction to the
[8920dfa]424 <xref linkend="fw-masqRouter"/> for some more details.</para>
425
[1ef78bc]426 <para>If you want to add services such as internal Samba or
[bbdb0ff4]427 name servers that do not need to access the Internet themselves,
[0afcfa88]428 the additional statements are quite simple and should still be
[8920dfa]429 acceptable from a security standpoint. Just add the following lines
430 into the script <emphasis>before</emphasis> the logging rules.</para>
431
432<screen><literal>iptables -A INPUT -i ! ppp+ -j ACCEPT
433iptables -A OUTPUT -o ! ppp+ -j ACCEPT</literal></screen>
434
[0afcfa88]435 <para>If daemons, such as squid, have to access the Internet
436 themselves, you could open OUTPUT generally and restrict
[8920dfa]437 INPUT.</para>
438
439<screen><literal>iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
440iptables -A OUTPUT -j ACCEPT</literal></screen>
441
[0afcfa88]442 <para>However, it is generally not advisable to leave OUTPUT
443 unrestricted. You lose any control over trojans who would like
444 to "call home", and a bit of redundancy in case you've
445 (mis-)configured a service so that it broadcasts its existence
[8920dfa]446 to the world.</para>
447
448 <para>To accomplish this, you should restrict INPUT and OUTPUT
[0afcfa88]449 on all ports except those that it's absolutely necessary to have
450 open. Which ports you have to open depends on your needs: mostly
451 you will find them by looking for failed accesses in your log
[8920dfa]452 files.</para>
453
454 <itemizedlist spacing="compact" role='iptables'>
455 <title>Have a Look at the Following Examples:</title>
456 <listitem>
457 <para>Squid is caching the web:</para>
458
459<screen><literal>iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
[0e3848e3]460iptables -A INPUT -p tcp --sport 80 -m state --state ESTABLISHED \
[8920dfa]461 -j ACCEPT</literal></screen>
[d612b9f]462
[8920dfa]463 </listitem>
464 <listitem>
465 <para>Your caching name server (e.g., named) does its
[1ef78bc]466 lookups via UDP:</para>
[8920dfa]467
468<screen><literal>iptables -A OUTPUT -p udp --dport 53 -j ACCEPT</literal></screen>
469
470 </listitem>
471 <listitem>
[1ef78bc]472 <para>You want to be able to ping your computer to
[8920dfa]473 ensure it's still alive:</para>
474
475<screen><literal>iptables -A INPUT -p icmp -m icmp --icmp-type echo-request -j ACCEPT
476iptables -A OUTPUT -p icmp -m icmp --icmp-type echo-reply -j ACCEPT</literal></screen>
477
478 </listitem>
479 <listitem>
[c6b7bd5]480 <para id='fw-BB-4' xreflabel="BusyBox example number 4">If
[1ef78bc]481 you are frequently accessing FTP servers or enjoy chatting, you might
[0afcfa88]482 notice certain delays because some implementations of these daemons
483 have the feature of querying an identd on your system to obtain
484 usernames. Although there's really little harm in this, having an
485 identd running is not recommended because many security experts feel
[8920dfa]486 the service gives out too much additional information.</para>
487
[0afcfa88]488 <para>To avoid these delays you could reject the requests
[8920dfa]489 with a 'tcp-reset':</para>
490
491<screen><literal>iptables -A INPUT -p tcp --dport 113 -j REJECT --reject-with tcp-reset</literal></screen>
492
493 </listitem>
494 <listitem>
495 <para>To log and drop invalid packets (packets
[0afcfa88]496 that came in after netfilter's timeout or some types of
[a805e52]497 network scans) insert these rules at the top of the chain:</para>
[8920dfa]498
[a805e52]499<screen><literal>iptables -I INPUT 0 -p tcp -m state --state INVALID \
[5f2eb36]500 -j LOG --log-prefix "FIREWALL:INVALID "
[a805e52]501iptables -I INPUT 1 -p tcp -m state --state INVALID -j DROP</literal></screen>
[b4b71892]502
[8920dfa]503 </listitem>
504 <listitem>
505 <para>Anything coming from the outside should not have a
506 private address, this is a common attack called IP-spoofing:</para>
[0e3848e3]507
[8920dfa]508<screen><literal>iptables -A INPUT -i ppp+ -s 10.0.0.0/8 -j DROP
[0e3848e3]509iptables -A INPUT -i ppp+ -s 172.16.0.0/12 -j DROP
[8920dfa]510iptables -A INPUT -i ppp+ -s 192.168.0.0/16 -j DROP</literal></screen>
[0e3848e3]511
[0afcfa88]512 <para>There are other addresses that you may also want to
513 drop: 0.0.0.0/8, 127.0.0.0/8, 224.0.0.0/3 (multicast and
[bbdb0ff4]514 experimental), 169.254.0.0/16 (Link Local Networks), and
[8920dfa]515 192.0.2.0/24 (IANA defined test network).</para>
516 </listitem>
517 <listitem>
[0afcfa88]518 <para>If your firewall is a DHCP client, you need to allow
[8920dfa]519 those packets:</para>
[0e3848e3]520
[8920dfa]521<screen><literal>iptables -A INPUT -i ppp0 -p udp -s 0.0.0.0 --sport 67 \
522 -d 255.255.255.255 --dport 68 -j ACCEPT</literal></screen>
[b4b71892]523
[8920dfa]524 </listitem>
525 <listitem>
[0afcfa88]526 <para>To simplify debugging and be fair to anyone who'd like
527 to access a service you have disabled, purposely or by mistake,
[8920dfa]528 you could REJECT those packets that are dropped.</para>
[b4b71892]529
[8920dfa]530 <para>Obviously this must be done directly after logging as the very
531 last lines before the packets are dropped by policy:</para>
[b4b71892]532
[8920dfa]533<screen><literal>iptables -A INPUT -j REJECT</literal></screen>
[b4b71892]534
[8920dfa]535 </listitem>
536 </itemizedlist>
[b4b71892]537
[0afcfa88]538 <para>These are only examples to show you some of the capabilities
[8920dfa]539 of the firewall code in Linux. Have a look at the man page of iptables.
[0afcfa88]540 There you will find much more information. The port numbers needed for
541 this can be found in <filename>/etc/services</filename>, in case you
[8920dfa]542 didn't find them by trial and error in your log file.</para>
[0e3848e3]543
[8920dfa]544 </sect3>
[b4b71892]545
[8920dfa]546 </sect2>
[b4b71892]547
[8920dfa]548 <sect2 id="fw-finale" xreflabel="Conclusion">
549 <title>Conclusion</title>
[b4b71892]550
[8920dfa]551 <para>Finally, there is one fact you must not forget: The effort spent
[0afcfa88]552 attacking a system corresponds to the value the cracker expects to gain
553 from it. If you are responsible for valuable information, you need to
[8920dfa]554 spend the time to protect it properly.</para>
[b4b71892]555
[8920dfa]556 </sect2>
[b4b71892]557
[8920dfa]558 <sect2 id="postlfs-security-fw-extra" xreflabel="Extra Information">
559 <title>Extra Information</title>
[b4b71892]560
[1ef78bc]561 <sect3 id="fw-library" xreflabel="links for further reading">
562 <title>Where to Start with Further Reading on Firewalls</title>
[8920dfa]563
564 <blockquote>
565 <literallayout>
[b4b71892]566<ulink url="http://www.netfilter.org/">www.netfilter.org - Homepage of the netfilter/iptables project</ulink>
567<ulink url="http://www.netfilter.org/documentation/FAQ/netfilter-faq.html">Netfilter related FAQ</ulink>
568<ulink url="http://www.netfilter.org/documentation/index.html#HOWTO">Netfilter related HOWTO's</ulink>
569<ulink url="http://en.tldp.org/LDP/nag2/x-087-2-firewall.html">en.tldp.org/LDP/nag2/x-087-2-firewall.html</ulink>
570<ulink url="http://en.tldp.org/HOWTO/Security-HOWTO.html">en.tldp.org/HOWTO/Security-HOWTO.html</ulink>
571<ulink url="http://en.tldp.org/HOWTO/Firewall-HOWTO.html">en.tldp.org/HOWTO/Firewall-HOWTO.html</ulink>
572<ulink url="http://www.linuxsecurity.com/docs/">www.linuxsecurity.com/docs/</ulink>
573<ulink url="http://www.little-idiot.de/firewall">www.little-idiot.de/firewall (German &amp; outdated, but very comprehensive)</ulink>
574<ulink url="http://linux.oreillynet.com/pub/a/linux/2000/03/10/netadmin/ddos.html">linux.oreillynet.com/pub/a/linux/2000/03/10/netadmin/ddos.html</ulink>
575<ulink url="http://staff.washington.edu/dittrich/misc/ddos">staff.washington.edu/dittrich/misc/ddos</ulink>
576<ulink url="http://www.e-infomax.com/ipmasq">www.e-infomax.com/ipmasq</ulink>
577<ulink url="http://www.circlemud.org/~jelson/writings/security/index.htm">www.circlemud.org/~jelson/writings/security/index.htm</ulink>
578<ulink url="http://www.securityfocus.com">www.securityfocus.com</ulink>
579<ulink url="http://www.cert.org/tech_tips/">www.cert.org - tech_tips</ulink>
580<ulink url="http://security.ittoolbox.com/">security.ittoolbox.com</ulink>
581<ulink url="http://www.insecure.org/reading.html">www.insecure.org/reading.html</ulink>
[8920dfa]582 </literallayout>
583 </blockquote>
584
[f9bef9e]585 <!-- The following are all dead links from the section above. They are
586 moved out of the section so the literallayout won't produce blank
587 lines in the rendered text
588
589<ulink url="http://www-106.ibm.com/developerworks/security/library/s-fire.html">www.ibm.com/developerworks/security/library/s-fire.html</ulink>
590<ulink url="http://www-106.ibm.com/developerworks/security/library/s-fire2.html">www.ibm.com/developerworks/security/library/s-fire2.html</ulink>
591<ulink url="http://www.interhack.net/pubs/fw-faq/">www.interhack.net/pubs/fw-faq/</ulink>
592<ulink url="http://www.linuxgazette.com/issue65/stumpel.html">www.linuxgazette.com/issue65/stumpel.html</ulink>
593<ulink url="http://www.linux-firewall-tools.com/linux/">www.linux-firewall-tools.com/linux/</ulink>
594<ulink url="http://logi.cc/linux/athome-firewall.php3">logi.cc/linux/athome-firewall.php3</ulink>
595<ulink url="http://www.robertgraham.com/pubs/firewall-seen.html">www.robertgraham.com/pubs/firewall-seen.html</ulink>
596
597 -->
598
[8920dfa]599 </sect3>
600
601 </sect2>
[b4b71892]602
[f45b1953]603</sect1>
Note: See TracBrowser for help on using the repository browser.