[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 |
|
---|
[97e37e1] | 7 | <!ENTITY iptables-download-http "https://www.netfilter.org/projects/iptables/files/iptables-&iptables-version;.tar.xz">
|
---|
| 8 | <!ENTITY iptables-download-ftp "ftp://ftp.netfilter.org/pub/iptables/iptables-&iptables-version;.tar.xz">
|
---|
| 9 | <!ENTITY iptables-md5sum "ffa00f68d63e723c21b8a091c5c0271b">
|
---|
| 10 | <!ENTITY iptables-size "633 KB">
|
---|
[f959ec4] | 11 | <!ENTITY iptables-buildsize "16 MB">
|
---|
[ab6bf6a] | 12 | <!ENTITY iptables-time "0.1 SBU">
|
---|
[b4b71892] | 13 | ]>
|
---|
| 14 |
|
---|
[14c0be2f] | 15 | <sect1 id="iptables" xreflabel="iptables-&iptables-version;">
|
---|
[71072bbe] | 16 | <?dbhtml filename="iptables.html"?>
|
---|
| 17 |
|
---|
| 18 |
|
---|
[14c0be2f] | 19 | <title>iptables-&iptables-version;</title>
|
---|
[71072bbe] | 20 |
|
---|
| 21 | <indexterm zone="iptables">
|
---|
[14c0be2f] | 22 | <primary sortas="a-iptables">iptables</primary>
|
---|
[71072bbe] | 23 | </indexterm>
|
---|
| 24 |
|
---|
| 25 | <sect2 role="package">
|
---|
[14c0be2f] | 26 | <title>Introduction to iptables</title>
|
---|
[71072bbe] | 27 |
|
---|
[4591404] | 28 | <para>
|
---|
[14c0be2f] | 29 | <application>iptables</application> is a userspace command line program
|
---|
[ab6bf6a] | 30 | used to configure the Linux 2.4 and later kernel packet filtering ruleset.
|
---|
[4591404] | 31 | </para>
|
---|
[71072bbe] | 32 |
|
---|
[1d04be9c] | 33 | &lfs113_checked;
|
---|
[93236c2] | 34 |
|
---|
[71072bbe] | 35 | <bridgehead renderas="sect3">Package Information</bridgehead>
|
---|
| 36 | <itemizedlist spacing="compact">
|
---|
| 37 | <listitem>
|
---|
[4591404] | 38 | <para>
|
---|
| 39 | Download (HTTP): <ulink url="&iptables-download-http;"/>
|
---|
| 40 | </para>
|
---|
[71072bbe] | 41 | </listitem>
|
---|
| 42 | <listitem>
|
---|
[4591404] | 43 | <para>
|
---|
| 44 | Download (FTP): <ulink url="&iptables-download-ftp;"/>
|
---|
| 45 | </para>
|
---|
[71072bbe] | 46 | </listitem>
|
---|
| 47 | <listitem>
|
---|
[4591404] | 48 | <para>
|
---|
| 49 | Download MD5 sum: &iptables-md5sum;
|
---|
| 50 | </para>
|
---|
[71072bbe] | 51 | </listitem>
|
---|
| 52 | <listitem>
|
---|
[4591404] | 53 | <para>
|
---|
| 54 | Download size: &iptables-size;
|
---|
| 55 | </para>
|
---|
[71072bbe] | 56 | </listitem>
|
---|
| 57 | <listitem>
|
---|
[4591404] | 58 | <para>
|
---|
| 59 | Estimated disk space required: &iptables-buildsize;
|
---|
| 60 | </para>
|
---|
[71072bbe] | 61 | </listitem>
|
---|
| 62 | <listitem>
|
---|
[4591404] | 63 | <para>
|
---|
| 64 | Estimated build time: &iptables-time;
|
---|
| 65 | </para>
|
---|
[71072bbe] | 66 | </listitem>
|
---|
| 67 | </itemizedlist>
|
---|
[d6da5da] | 68 |
|
---|
[14c0be2f] | 69 | <bridgehead renderas="sect3">iptables Dependencies</bridgehead>
|
---|
[924fcd6] | 70 |
|
---|
| 71 | <bridgehead renderas="sect4">Optional</bridgehead>
|
---|
| 72 | <para role="optional">
|
---|
[018c0cc3] | 73 | <!-- <xref linkend="nftables"/>, -->
|
---|
[c5b59ac] | 74 | <xref linkend="libpcap"/> (required for BPF compiler or nfsynproxy support),
|
---|
[6d6c19d] | 75 | <ulink url="https://github.com/tadamdam/bpf-utils">bpf-utils</ulink>
|
---|
[ab6bf6a] | 76 | (required for Berkeley Packet Filter support),
|
---|
[6d6c19d] | 77 | <ulink url="https://netfilter.org/projects/libnfnetlink/">libnfnetlink</ulink>
|
---|
[018c0cc3] | 78 | (required for connlabel support),
|
---|
[ab6bf6a] | 79 | <ulink url="https://netfilter.org/projects/libnetfilter_conntrack/">libnetfilter_conntrack</ulink>
|
---|
[8558044] | 80 | (required for connlabel support), and
|
---|
[018c0cc3] | 81 | <ulink url="https://netfilter.org/projects/nftables/">nftables</ulink>
|
---|
[924fcd6] | 82 | </para>
|
---|
| 83 |
|
---|
[ce6ccc9] | 84 | </sect2>
|
---|
[b4b71892] | 85 |
|
---|
[4591404] | 86 | <sect2 role="kernel" id="iptables-kernel">
|
---|
[71072bbe] | 87 | <title>Kernel Configuration</title>
|
---|
[b4b71892] | 88 |
|
---|
[4591404] | 89 | <para>
|
---|
[14c0be2f] | 90 | A firewall in Linux is accomplished through the netfilter interface. To
|
---|
| 91 | use <application>iptables</application> to configure netfilter, the
|
---|
| 92 | following kernel configuration parameters are required:
|
---|
[4591404] | 93 | </para>
|
---|
[f8962fe] | 94 |
|
---|
[7474050] | 95 | <screen><literal>[*] Networking support ---> [CONFIG_NET]
|
---|
[38155d1] | 96 | Networking Options --->
|
---|
[7474050] | 97 | [*] Network packet filtering framework (Netfilter) ---> [CONFIG_NETFILTER]
|
---|
| 98 | [*] Advanced netfilter configuration [CONFIG_NETFILTER_ADVANCED]
|
---|
| 99 | Core Netfilter Configuration --->
|
---|
| 100 | <*/M> Netfilter connection tracking support [CONFIG_NF_CONNTRACK]
|
---|
| 101 | <*/M> Netfilter Xtables support (required for ip_tables) [CONFIG_NETFILTER_XTABLES]
|
---|
| 102 | <*/M> LOG target support [CONFIG_NETFILTER_XT_TARGET_LOG]
|
---|
| 103 | IP: Netfilter Configuration --->
|
---|
| 104 | <*/M> IP tables support (required for filtering/masq/NAT) [CONFIG_IP_NF_IPTABLES]</literal></screen>
|
---|
[14c0be2f] | 105 |
|
---|
| 106 | <para>
|
---|
| 107 | Include any connection tracking protocols that will be used, as well as
|
---|
[c7548853] | 108 | any protocols that you wish to use for match support under the
|
---|
[018c0cc3] | 109 | "Core Netfilter Configuration" section. The above options are enough
|
---|
| 110 | for running <xref linkend="fw-persFw-ipt"/> below.
|
---|
[14c0be2f] | 111 | </para>
|
---|
[38155d1] | 112 |
|
---|
[71072bbe] | 113 | <indexterm zone="iptables iptables-kernel">
|
---|
[14c0be2f] | 114 | <primary sortas="d-iptables">iptables</primary>
|
---|
[71072bbe] | 115 | </indexterm>
|
---|
[48ecffe8] | 116 |
|
---|
[71072bbe] | 117 | </sect2>
|
---|
[48ecffe8] | 118 |
|
---|
[71072bbe] | 119 | <sect2 role="installation">
|
---|
[14c0be2f] | 120 | <title>Installation of iptables</title>
|
---|
[48ecffe8] | 121 |
|
---|
[71072bbe] | 122 | <note>
|
---|
[4591404] | 123 | <para>
|
---|
| 124 | The installation below does not include building some specialized
|
---|
| 125 | extension libraries which require the raw headers in the
|
---|
| 126 | <application>Linux</application> source code. If you wish to build the
|
---|
| 127 | additional extensions (if you aren't sure, then you probably don't), you
|
---|
| 128 | can look at the <filename>INSTALL</filename> file to see an example of
|
---|
| 129 | how to change the <parameter>KERNEL_DIR=</parameter> parameter to point
|
---|
| 130 | at the <application>Linux</application> source code. Note that if you
|
---|
| 131 | upgrade the kernel version, you may also need to recompile
|
---|
[14c0be2f] | 132 | <application>iptables</application> and that the BLFS team has not
|
---|
| 133 | tested using the raw kernel headers.
|
---|
[4591404] | 134 | </para>
|
---|
[71072bbe] | 135 | </note>
|
---|
| 136 |
|
---|
[4591404] | 137 | <para>
|
---|
[14c0be2f] | 138 | Install <application>iptables</application> by running the following
|
---|
[4591404] | 139 | commands:
|
---|
| 140 | </para>
|
---|
| 141 |
|
---|
[924fcd6] | 142 | <screen><userinput>./configure --prefix=/usr \
|
---|
| 143 | --disable-nftables \
|
---|
[f2a586e] | 144 | --enable-libipq &&
|
---|
[bf157fc2] | 145 | make</userinput></screen>
|
---|
[ce6ccc9] | 146 |
|
---|
[14c0be2f] | 147 | <para>
|
---|
[c7548853] | 148 | <!-- there is a iptables-test.py script which seems to run a
|
---|
[2c87187] | 149 | lot of tests. Unfortunately, success rate is 50% only. Needs
|
---|
[c7548853] | 150 | to be clarified how to use and which prerequisites are required
|
---|
| 151 | to run to 100%. Contacted Shekhar Sharma for that (Dec'19),
|
---|
| 152 | waiting for answer (thomas). -->
|
---|
[14c0be2f] | 153 | This package does not come with a test suite.
|
---|
| 154 | </para>
|
---|
[71072bbe] | 155 |
|
---|
[14c0be2f] | 156 | <para>
|
---|
| 157 | Now, as the <systemitem class="username">root</systemitem> user:
|
---|
| 158 | </para>
|
---|
[71072bbe] | 159 |
|
---|
[f2a586e] | 160 | <screen role="root"><userinput>make install</userinput></screen>
|
---|
[71072bbe] | 161 |
|
---|
| 162 | </sect2>
|
---|
[d40737d] | 163 |
|
---|
[71072bbe] | 164 | <sect2 role="commands">
|
---|
| 165 | <title>Command Explanations</title>
|
---|
| 166 |
|
---|
[4591404] | 167 | <para>
|
---|
[ddc02883] | 168 | <parameter>--disable-nftables</parameter>: This switch disables building
|
---|
[ab6bf6a] | 169 | nftables compatibility. <!--Omit this switch if you have installed
|
---|
[f7415c4d] | 170 | <xref linkend="nftables"/>.-->
|
---|
[4591404] | 171 | </para>
|
---|
| 172 |
|
---|
| 173 | <para>
|
---|
[924fcd6] | 174 | <parameter>--enable-libipq</parameter>: This switch enables building
|
---|
[4591404] | 175 | of <filename class="libraryfile">libipq.so</filename> which
|
---|
| 176 | can be used by some packages outside of BLFS.
|
---|
| 177 | </para>
|
---|
| 178 |
|
---|
[7801f02] | 179 | <para>
|
---|
| 180 | <option>--enable-nfsynproxy</option>: This switch enables installation
|
---|
| 181 | of <application>nfsynproxy</application> SYNPROXY configuration tool.
|
---|
| 182 | </para>
|
---|
| 183 |
|
---|
[71072bbe] | 184 | </sect2>
|
---|
[018c0cc3] | 185 |
|
---|
[71072bbe] | 186 | <sect2 role="configuration">
|
---|
[14c0be2f] | 187 | <title>Configuring iptables</title>
|
---|
[018c0cc3] | 188 | <!--
|
---|
[14c0be2f] | 189 | <note>
|
---|
| 190 | <para>
|
---|
| 191 | If you intend to use <xref linkend="firewalld"/> to configure your
|
---|
| 192 | firewall rules, you should not use the example configurations provided
|
---|
| 193 | here, nor should you enable the
|
---|
[9456eb5] | 194 | <phrase revision="sysv">bootscript.</phrase>
|
---|
| 195 | <phrase revision="systemd">systemd unit.</phrase>
|
---|
[14c0be2f] | 196 | </para>
|
---|
| 197 | </note>
|
---|
[018c0cc3] | 198 | -->
|
---|
[14c0be2f] | 199 | <note>
|
---|
| 200 | <para>
|
---|
[d772a7e] | 201 | In the following example configurations, <emphasis
|
---|
[14c0be2f] | 202 | role="strong">LAN1</emphasis> is used for the internal LAN interface,
|
---|
| 203 | and <emphasis role="strong">WAN1</emphasis> is used for the external
|
---|
[2c87187] | 204 | interface connected to the Internet. You will need to replace these
|
---|
[14c0be2f] | 205 | values with appropriate interface names for your system.
|
---|
| 206 | </para>
|
---|
| 207 | </note>
|
---|
| 208 |
|
---|
| 209 | <sect3 id="fw-persFw-ipt"
|
---|
| 210 | xreflabel="Creating a Personal Firewall With iptables">
|
---|
| 211 | <title>Personal Firewall</title>
|
---|
| 212 |
|
---|
| 213 | <para>
|
---|
| 214 | A Personal Firewall is designed to let you access all the
|
---|
[ab6bf6a] | 215 | services offered on the Internet while keeping your computer secure and
|
---|
[14c0be2f] | 216 | your data private.
|
---|
| 217 | </para>
|
---|
| 218 |
|
---|
| 219 | <para>
|
---|
| 220 | Below is a slightly modified version of Rusty Russell's
|
---|
| 221 | recommendation from the <ulink
|
---|
[cd29bc9] | 222 | url="https://www.netfilter.org/documentation/HOWTO/packet-filtering-HOWTO.html">
|
---|
[14c0be2f] | 223 | Linux 2.4 Packet Filtering HOWTO</ulink>. It is still applicable
|
---|
[ab6bf6a] | 224 | to the Linux 5.x kernels.
|
---|
[14c0be2f] | 225 | </para>
|
---|
| 226 |
|
---|
| 227 | <screen role="root" revision="sysv"><?dbfo keep-together="auto"?><userinput>cat > /etc/rc.d/rc.iptables << "EOF"
|
---|
| 228 | <literal>#!/bin/sh
|
---|
| 229 |
|
---|
| 230 | # Begin rc.iptables
|
---|
| 231 |
|
---|
| 232 | # Insert connection-tracking modules
|
---|
| 233 | # (not needed if built into the kernel)
|
---|
| 234 | modprobe nf_conntrack
|
---|
| 235 | modprobe xt_LOG
|
---|
| 236 |
|
---|
| 237 | # Enable broadcast echo Protection
|
---|
| 238 | echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
|
---|
| 239 |
|
---|
| 240 | # Disable Source Routed Packets
|
---|
| 241 | echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
|
---|
| 242 | echo 0 > /proc/sys/net/ipv4/conf/default/accept_source_route
|
---|
| 243 |
|
---|
| 244 | # Enable TCP SYN Cookie Protection
|
---|
| 245 | echo 1 > /proc/sys/net/ipv4/tcp_syncookies
|
---|
| 246 |
|
---|
| 247 | # Disable ICMP Redirect Acceptance
|
---|
| 248 | echo 0 > /proc/sys/net/ipv4/conf/default/accept_redirects
|
---|
| 249 |
|
---|
| 250 | # Do not send Redirect Messages
|
---|
| 251 | echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
|
---|
| 252 | echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
|
---|
| 253 |
|
---|
| 254 | # Drop Spoofed Packets coming in on an interface, where responses
|
---|
| 255 | # would result in the reply going out a different interface.
|
---|
| 256 | echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
|
---|
| 257 | echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter
|
---|
| 258 |
|
---|
| 259 | # Log packets with impossible addresses.
|
---|
| 260 | echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
|
---|
| 261 | echo 1 > /proc/sys/net/ipv4/conf/default/log_martians
|
---|
| 262 |
|
---|
| 263 | # be verbose on dynamic ip-addresses (not needed in case of static IP)
|
---|
| 264 | echo 2 > /proc/sys/net/ipv4/ip_dynaddr
|
---|
| 265 |
|
---|
| 266 | # disable Explicit Congestion Notification
|
---|
| 267 | # too many routers are still ignorant
|
---|
| 268 | echo 0 > /proc/sys/net/ipv4/tcp_ecn
|
---|
| 269 |
|
---|
| 270 | # Set a known state
|
---|
| 271 | iptables -P INPUT DROP
|
---|
| 272 | iptables -P FORWARD DROP
|
---|
| 273 | iptables -P OUTPUT DROP
|
---|
| 274 |
|
---|
| 275 | # These lines are here in case rules are already in place and the
|
---|
| 276 | # script is ever rerun on the fly. We want to remove all rules and
|
---|
| 277 | # pre-existing user defined chains before we implement new rules.
|
---|
| 278 | iptables -F
|
---|
| 279 | iptables -X
|
---|
| 280 | iptables -Z
|
---|
| 281 |
|
---|
| 282 | iptables -t nat -F
|
---|
| 283 |
|
---|
| 284 | # Allow local-only connections
|
---|
| 285 | iptables -A INPUT -i lo -j ACCEPT
|
---|
| 286 |
|
---|
| 287 | # Free output on any interface to any ip for any service
|
---|
| 288 | # (equal to -P ACCEPT)
|
---|
| 289 | iptables -A OUTPUT -j ACCEPT
|
---|
| 290 |
|
---|
| 291 | # Permit answers on already established connections
|
---|
| 292 | # and permit new connections related to established ones
|
---|
| 293 | # (e.g. port mode ftp)
|
---|
[018c0cc3] | 294 | iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
---|
[14c0be2f] | 295 |
|
---|
[ab6bf6a] | 296 | # Log everything else.
|
---|
[018c0cc3] | 297 | iptables -A INPUT -j LOG --log-prefix "FIREWALL:INPUT "
|
---|
[14c0be2f] | 298 |
|
---|
| 299 | # End $rc_base/rc.iptables</literal>
|
---|
| 300 | EOF
|
---|
| 301 | chmod 700 /etc/rc.d/rc.iptables</userinput></screen>
|
---|
| 302 |
|
---|
| 303 | <screen role="root" revision="systemd"><?dbfo keep-together="auto"?><userinput>install -v -dm755 /etc/systemd/scripts
|
---|
| 304 |
|
---|
| 305 | cat > /etc/systemd/scripts/iptables << "EOF"
|
---|
| 306 | <literal>#!/bin/sh
|
---|
| 307 |
|
---|
| 308 | # Begin /etc/systemd/scripts/iptables
|
---|
| 309 |
|
---|
| 310 | # Insert connection-tracking modules
|
---|
| 311 | # (not needed if built into the kernel)
|
---|
| 312 | modprobe nf_conntrack
|
---|
| 313 | modprobe xt_LOG
|
---|
| 314 |
|
---|
| 315 | # Enable broadcast echo Protection
|
---|
| 316 | echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
|
---|
| 317 |
|
---|
| 318 | # Disable Source Routed Packets
|
---|
| 319 | echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
|
---|
| 320 | echo 0 > /proc/sys/net/ipv4/conf/default/accept_source_route
|
---|
| 321 |
|
---|
| 322 | # Enable TCP SYN Cookie Protection
|
---|
| 323 | echo 1 > /proc/sys/net/ipv4/tcp_syncookies
|
---|
| 324 |
|
---|
| 325 | # Disable ICMP Redirect Acceptance
|
---|
| 326 | echo 0 > /proc/sys/net/ipv4/conf/default/accept_redirects
|
---|
| 327 |
|
---|
| 328 | # Do not send Redirect Messages
|
---|
| 329 | echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
|
---|
| 330 | echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
|
---|
| 331 |
|
---|
| 332 | # Drop Spoofed Packets coming in on an interface, where responses
|
---|
| 333 | # would result in the reply going out a different interface.
|
---|
| 334 | echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
|
---|
| 335 | echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter
|
---|
| 336 |
|
---|
| 337 | # Log packets with impossible addresses.
|
---|
| 338 | echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
|
---|
| 339 | echo 1 > /proc/sys/net/ipv4/conf/default/log_martians
|
---|
| 340 |
|
---|
| 341 | # be verbose on dynamic ip-addresses (not needed in case of static IP)
|
---|
| 342 | echo 2 > /proc/sys/net/ipv4/ip_dynaddr
|
---|
| 343 |
|
---|
| 344 | # disable Explicit Congestion Notification
|
---|
| 345 | # too many routers are still ignorant
|
---|
| 346 | echo 0 > /proc/sys/net/ipv4/tcp_ecn
|
---|
| 347 |
|
---|
| 348 | # Set a known state
|
---|
| 349 | iptables -P INPUT DROP
|
---|
| 350 | iptables -P FORWARD DROP
|
---|
| 351 | iptables -P OUTPUT DROP
|
---|
| 352 |
|
---|
| 353 | # These lines are here in case rules are already in place and the
|
---|
| 354 | # script is ever rerun on the fly. We want to remove all rules and
|
---|
| 355 | # pre-existing user defined chains before we implement new rules.
|
---|
| 356 | iptables -F
|
---|
| 357 | iptables -X
|
---|
| 358 | iptables -Z
|
---|
| 359 |
|
---|
| 360 | iptables -t nat -F
|
---|
| 361 |
|
---|
| 362 | # Allow local-only connections
|
---|
| 363 | iptables -A INPUT -i lo -j ACCEPT
|
---|
| 364 |
|
---|
| 365 | # Free output on any interface to any ip for any service
|
---|
| 366 | # (equal to -P ACCEPT)
|
---|
| 367 | iptables -A OUTPUT -j ACCEPT
|
---|
| 368 |
|
---|
| 369 | # Permit answers on already established connections
|
---|
| 370 | # and permit new connections related to established ones
|
---|
| 371 | # (e.g. port mode ftp)
|
---|
[018c0cc3] | 372 | iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
---|
[14c0be2f] | 373 |
|
---|
[ab6bf6a] | 374 | # Log everything else.
|
---|
[018c0cc3] | 375 | iptables -A INPUT -j LOG --log-prefix "FIREWALL:INPUT "
|
---|
[14c0be2f] | 376 |
|
---|
| 377 | # End /etc/systemd/scripts/iptables</literal>
|
---|
| 378 | EOF
|
---|
| 379 | chmod 700 /etc/systemd/scripts/iptables</userinput></screen>
|
---|
| 380 |
|
---|
| 381 | <para>
|
---|
| 382 | This script is quite simple, it drops all traffic coming
|
---|
| 383 | into your computer that wasn't initiated from your computer, but
|
---|
| 384 | as long as you are simply surfing the Internet you are unlikely
|
---|
| 385 | to exceed its limits.
|
---|
| 386 | </para>
|
---|
| 387 |
|
---|
| 388 | <para>
|
---|
| 389 | If you frequently encounter certain delays at accessing
|
---|
| 390 | FTP servers, take a look at <xref linkend="fw-BB-4-ipt"/>.
|
---|
| 391 | </para>
|
---|
| 392 |
|
---|
| 393 | <para>
|
---|
| 394 | Even if you have daemons or services running on your system,
|
---|
| 395 | these will be inaccessible everywhere but from your computer itself.
|
---|
| 396 | If you want to allow access to services on your machine, such as
|
---|
| 397 | <command>ssh</command> or <command>ping</command>, take a look at
|
---|
| 398 | <xref linkend="fw-busybox-ipt"/>.
|
---|
| 399 | </para>
|
---|
| 400 |
|
---|
| 401 | </sect3>
|
---|
| 402 |
|
---|
| 403 | <sect3 id="fw-masqRouter-ipt"
|
---|
| 404 | xreflabel="Creating a Masquerading Router With iptables">
|
---|
| 405 | <title>Masquerading Router</title>
|
---|
| 406 |
|
---|
| 407 | <para>
|
---|
[ab6bf6a] | 408 | A Network Firewall has two interfaces, one connected to an
|
---|
[14c0be2f] | 409 | intranet, in this example <emphasis role="strong">LAN1</emphasis>,
|
---|
| 410 | and one connected to the Internet, here <emphasis
|
---|
| 411 | role="strong">WAN1</emphasis>. To provide the maximum security
|
---|
| 412 | for the firewall itself, make sure that there are no unnecessary
|
---|
[ab6bf6a] | 413 | servers running on it such as <application>X11</application>.
|
---|
[14c0be2f] | 414 | As a general principle, the firewall itself should not access
|
---|
| 415 | any untrusted service (think of a remote server giving answers that
|
---|
| 416 | makes a daemon on your system crash, or even worse, that implements
|
---|
| 417 | a worm via a buffer-overflow).
|
---|
| 418 | </para>
|
---|
| 419 |
|
---|
| 420 | <screen role="root" revision="sysv"><?dbfo keep-together="auto"?><userinput>cat > /etc/rc.d/rc.iptables << "EOF"
|
---|
| 421 | <literal>#!/bin/sh
|
---|
| 422 |
|
---|
| 423 | # Begin rc.iptables
|
---|
| 424 |
|
---|
| 425 | echo
|
---|
| 426 | echo "You're using the example configuration for a setup of a firewall"
|
---|
| 427 | echo "from Beyond Linux From Scratch."
|
---|
| 428 | echo "This example is far from being complete, it is only meant"
|
---|
| 429 | echo "to be a reference."
|
---|
| 430 | echo "Firewall security is a complex issue, that exceeds the scope"
|
---|
| 431 | echo "of the configuration rules below."
|
---|
| 432 | echo "You can find additional information"
|
---|
| 433 | echo "about firewalls in Chapter 4 of the BLFS book."
|
---|
[4a570af1] | 434 | echo "https://www.&lfs-domainname;/blfs"
|
---|
[14c0be2f] | 435 | echo
|
---|
| 436 |
|
---|
| 437 | # Insert iptables modules (not needed if built into the kernel).
|
---|
| 438 |
|
---|
| 439 | modprobe nf_conntrack
|
---|
| 440 | modprobe nf_conntrack_ftp
|
---|
| 441 | modprobe xt_conntrack
|
---|
| 442 | modprobe xt_LOG
|
---|
| 443 | modprobe xt_state
|
---|
| 444 |
|
---|
| 445 | # Enable broadcast echo Protection
|
---|
| 446 | echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
|
---|
| 447 |
|
---|
| 448 | # Disable Source Routed Packets
|
---|
| 449 | echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
|
---|
| 450 |
|
---|
| 451 | # Enable TCP SYN Cookie Protection
|
---|
| 452 | echo 1 > /proc/sys/net/ipv4/tcp_syncookies
|
---|
| 453 |
|
---|
| 454 | # Disable ICMP Redirect Acceptance
|
---|
| 455 | echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
|
---|
| 456 |
|
---|
| 457 | # Don't send Redirect Messages
|
---|
| 458 | echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
|
---|
| 459 |
|
---|
| 460 | # Drop Spoofed Packets coming in on an interface where responses
|
---|
| 461 | # would result in the reply going out a different interface.
|
---|
| 462 | echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter
|
---|
| 463 |
|
---|
| 464 | # Log packets with impossible addresses.
|
---|
| 465 | echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
|
---|
| 466 |
|
---|
| 467 | # Be verbose on dynamic ip-addresses (not needed in case of static IP)
|
---|
| 468 | echo 2 > /proc/sys/net/ipv4/ip_dynaddr
|
---|
| 469 |
|
---|
| 470 | # Disable Explicit Congestion Notification
|
---|
| 471 | # Too many routers are still ignorant
|
---|
| 472 | echo 0 > /proc/sys/net/ipv4/tcp_ecn
|
---|
| 473 |
|
---|
| 474 | # Set a known state
|
---|
| 475 | iptables -P INPUT DROP
|
---|
| 476 | iptables -P FORWARD DROP
|
---|
| 477 | iptables -P OUTPUT DROP
|
---|
| 478 |
|
---|
| 479 | # These lines are here in case rules are already in place and the
|
---|
| 480 | # script is ever rerun on the fly. We want to remove all rules and
|
---|
| 481 | # pre-existing user defined chains before we implement new rules.
|
---|
| 482 | iptables -F
|
---|
| 483 | iptables -X
|
---|
| 484 | iptables -Z
|
---|
| 485 |
|
---|
| 486 | iptables -t nat -F
|
---|
| 487 |
|
---|
| 488 | # Allow local connections
|
---|
| 489 | iptables -A INPUT -i lo -j ACCEPT
|
---|
| 490 | iptables -A OUTPUT -o lo -j ACCEPT
|
---|
| 491 |
|
---|
| 492 | # Allow forwarding if the initiated on the intranet
|
---|
[018c0cc3] | 493 | iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
---|
| 494 | iptables -A FORWARD ! -i WAN1 -m conntrack --ctstate NEW -j ACCEPT
|
---|
[14c0be2f] | 495 |
|
---|
| 496 | # Do masquerading
|
---|
| 497 | # (not needed if intranet is not using private ip-addresses)
|
---|
| 498 | iptables -t nat -A POSTROUTING -o WAN1 -j MASQUERADE
|
---|
| 499 |
|
---|
| 500 | # Log everything for debugging
|
---|
| 501 | # (last of all rules, but before policy rules)
|
---|
[018c0cc3] | 502 | iptables -A INPUT -j LOG --log-prefix "FIREWALL:INPUT "
|
---|
| 503 | iptables -A FORWARD -j LOG --log-prefix "FIREWALL:FORWARD "
|
---|
| 504 | iptables -A OUTPUT -j LOG --log-prefix "FIREWALL:OUTPUT "
|
---|
[14c0be2f] | 505 |
|
---|
| 506 | # Enable IP Forwarding
|
---|
| 507 | echo 1 > /proc/sys/net/ipv4/ip_forward</literal>
|
---|
| 508 | EOF
|
---|
| 509 | chmod 700 /etc/rc.d/rc.iptables</userinput></screen>
|
---|
| 510 |
|
---|
| 511 | <screen role="root" revision="systemd"><?dbfo keep-together="auto"?><userinput>install -v -dm755 /etc/systemd/scripts
|
---|
| 512 |
|
---|
| 513 | cat > /etc/systemd/scripts/iptables << "EOF"
|
---|
| 514 | <literal>#!/bin/sh
|
---|
| 515 |
|
---|
| 516 | # Begin /etc/systemd/scripts/iptables
|
---|
| 517 |
|
---|
| 518 | echo
|
---|
| 519 | echo "You're using the example configuration for a setup of a firewall"
|
---|
| 520 | echo "from Beyond Linux From Scratch."
|
---|
| 521 | echo "This example is far from being complete, it is only meant"
|
---|
| 522 | echo "to be a reference."
|
---|
| 523 | echo "Firewall security is a complex issue, that exceeds the scope"
|
---|
| 524 | echo "of the configuration rules below."
|
---|
| 525 |
|
---|
| 526 | echo "You can find additional information"
|
---|
| 527 | echo "about firewalls in Chapter 4 of the BLFS book."
|
---|
[cd29bc9] | 528 | echo "https://www.&lfs-domainname;/blfs"
|
---|
[14c0be2f] | 529 | echo
|
---|
| 530 |
|
---|
| 531 | # Insert iptables modules (not needed if built into the kernel).
|
---|
| 532 |
|
---|
| 533 | modprobe nf_conntrack
|
---|
| 534 | modprobe nf_conntrack_ftp
|
---|
| 535 | modprobe xt_conntrack
|
---|
| 536 | modprobe xt_LOG
|
---|
| 537 | modprobe xt_state
|
---|
| 538 |
|
---|
| 539 | # Enable broadcast echo Protection
|
---|
| 540 | echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
|
---|
| 541 |
|
---|
| 542 | # Disable Source Routed Packets
|
---|
| 543 | echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
|
---|
| 544 |
|
---|
| 545 | # Enable TCP SYN Cookie Protection
|
---|
| 546 | echo 1 > /proc/sys/net/ipv4/tcp_syncookies
|
---|
| 547 |
|
---|
| 548 | # Disable ICMP Redirect Acceptance
|
---|
| 549 | echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
|
---|
| 550 |
|
---|
| 551 | # Don't send Redirect Messages
|
---|
| 552 | echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
|
---|
| 553 |
|
---|
| 554 | # Drop Spoofed Packets coming in on an interface where responses
|
---|
| 555 | # would result in the reply going out a different interface.
|
---|
| 556 | echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter
|
---|
| 557 |
|
---|
| 558 | # Log packets with impossible addresses.
|
---|
| 559 | echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
|
---|
| 560 |
|
---|
| 561 | # Be verbose on dynamic ip-addresses (not needed in case of static IP)
|
---|
| 562 | echo 2 > /proc/sys/net/ipv4/ip_dynaddr
|
---|
| 563 |
|
---|
| 564 | # Disable Explicit Congestion Notification
|
---|
| 565 | # Too many routers are still ignorant
|
---|
| 566 | echo 0 > /proc/sys/net/ipv4/tcp_ecn
|
---|
| 567 |
|
---|
| 568 | # Set a known state
|
---|
| 569 | iptables -P INPUT DROP
|
---|
| 570 | iptables -P FORWARD DROP
|
---|
| 571 | iptables -P OUTPUT DROP
|
---|
| 572 |
|
---|
| 573 | # These lines are here in case rules are already in place and the
|
---|
| 574 | # script is ever rerun on the fly. We want to remove all rules and
|
---|
| 575 | # pre-existing user defined chains before we implement new rules.
|
---|
| 576 | iptables -F
|
---|
| 577 | iptables -X
|
---|
| 578 | iptables -Z
|
---|
| 579 |
|
---|
| 580 | iptables -t nat -F
|
---|
| 581 |
|
---|
| 582 | # Allow local connections
|
---|
| 583 | iptables -A INPUT -i lo -j ACCEPT
|
---|
| 584 | iptables -A OUTPUT -o lo -j ACCEPT
|
---|
| 585 |
|
---|
| 586 | # Allow forwarding if the initiated on the intranet
|
---|
[018c0cc3] | 587 | iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
---|
| 588 | iptables -A FORWARD ! -i WAN1 -m conntrack --ctstate NEW -j ACCEPT
|
---|
[14c0be2f] | 589 |
|
---|
| 590 | # Do masquerading
|
---|
| 591 | # (not needed if intranet is not using private ip-addresses)
|
---|
| 592 | iptables -t nat -A POSTROUTING -o WAN1 -j MASQUERADE
|
---|
| 593 |
|
---|
| 594 | # Log everything for debugging
|
---|
| 595 | # (last of all rules, but before policy rules)
|
---|
[018c0cc3] | 596 | iptables -A INPUT -j LOG --log-prefix "FIREWALL:INPUT "
|
---|
| 597 | iptables -A FORWARD -j LOG --log-prefix "FIREWALL:FORWARD "
|
---|
| 598 | iptables -A OUTPUT -j LOG --log-prefix "FIREWALL:OUTPUT "
|
---|
[14c0be2f] | 599 |
|
---|
| 600 | # Enable IP Forwarding
|
---|
| 601 | echo 1 > /proc/sys/net/ipv4/ip_forward
|
---|
| 602 |
|
---|
| 603 | # The following sections allow inbound packets for specific examples
|
---|
| 604 | # Uncomment the example lines and adjust as necessary
|
---|
| 605 |
|
---|
| 606 | # Allow ping on the external interface
|
---|
[018c0cc3] | 607 | #iptables -A INPUT -p icmp -m icmp --icmp-type echo-request -j ACCEPT
|
---|
| 608 | #iptables -A OUTPUT -p icmp -m icmp --icmp-type echo-reply -j ACCEPT
|
---|
[14c0be2f] | 609 |
|
---|
| 610 | # Reject ident packets with TCP reset to avoid delays with FTP or IRC
|
---|
[018c0cc3] | 611 | #iptables -A INPUT -p tcp --dport 113 -j REJECT --reject-with tcp-reset
|
---|
[14c0be2f] | 612 |
|
---|
| 613 | # Allow HTTP and HTTPS to 192.168.0.2
|
---|
[018c0cc3] | 614 | #iptables -A PREROUTING -t nat -i WAN1 -p tcp --dport 80 -j DNAT --to 192.168.0.2
|
---|
| 615 | #iptables -A PREROUTING -t nat -i WAN1 -p tcp --dport 443 -j DNAT --to 192.168.0.2
|
---|
| 616 | #iptables -A FORWARD -p tcp -d 192.168.0.2 --dport 80 -j ACCEPT
|
---|
| 617 | #iptables -A FORWARD -p tcp -d 192.168.0.2 --dport 443 -j ACCEPT
|
---|
[14c0be2f] | 618 |
|
---|
| 619 | # End /etc/systemd/scripts/iptables</literal>
|
---|
| 620 | EOF
|
---|
| 621 | chmod 700 /etc/systemd/scripts/iptables</userinput></screen>
|
---|
| 622 |
|
---|
| 623 | <para>
|
---|
| 624 | With this script your intranet should be reasonably secure
|
---|
| 625 | against external attacks. No one should be able to setup a new
|
---|
| 626 | connection to any internal service and, if it's masqueraded,
|
---|
| 627 | makes your intranet invisible to the Internet. Furthermore, your
|
---|
| 628 | firewall should be relatively safe because there are no services
|
---|
| 629 | running that a cracker could attack.
|
---|
| 630 | </para>
|
---|
| 631 |
|
---|
| 632 | </sect3>
|
---|
[8558044] | 633 |
|
---|
[14c0be2f] | 634 | <sect3 id="fw-busybox-ipt" xreflabel="Creating a BusyBox With iptables">
|
---|
| 635 | <title>BusyBox</title>
|
---|
| 636 |
|
---|
| 637 | <para>
|
---|
| 638 | This scenario isn't too different from the <xref
|
---|
| 639 | linkend="fw-masqRouter-ipt"/>, but additionally offers some
|
---|
| 640 | services to your intranet. Examples of this can be when
|
---|
| 641 | you want to administer your firewall from another host on
|
---|
| 642 | your intranet or use it as a proxy or a name server.
|
---|
| 643 | </para>
|
---|
| 644 |
|
---|
| 645 | <note>
|
---|
| 646 | <para>
|
---|
| 647 | Outlining specifically how to protect a server that
|
---|
| 648 | offers services on the Internet goes far beyond the scope of
|
---|
| 649 | this document. See the references in <xref linkend="fw-extra-info"/>
|
---|
| 650 | for more information.
|
---|
| 651 | </para>
|
---|
| 652 | </note>
|
---|
| 653 |
|
---|
| 654 | <para>
|
---|
| 655 | Be cautious. Every service you have enabled makes your
|
---|
| 656 | setup more complex and your firewall less secure. You are
|
---|
| 657 | exposed to the risks of misconfigured services or running
|
---|
| 658 | a service with an exploitable bug. A firewall should generally
|
---|
| 659 | not run any extra services. See the introduction to the
|
---|
| 660 | <xref linkend="fw-masqRouter-ipt"/> for some more details.
|
---|
| 661 | </para>
|
---|
| 662 |
|
---|
| 663 | <para>
|
---|
| 664 | If you want to add services such as internal Samba or
|
---|
| 665 | name servers that do not need to access the Internet themselves,
|
---|
| 666 | the additional statements are quite simple and should still be
|
---|
| 667 | acceptable from a security standpoint. Just add the following lines
|
---|
| 668 | into the script <emphasis>before</emphasis> the logging rules.
|
---|
| 669 | </para>
|
---|
| 670 |
|
---|
| 671 | <screen><literal>iptables -A INPUT -i ! WAN1 -j ACCEPT
|
---|
| 672 | iptables -A OUTPUT -o ! WAN1 -j ACCEPT</literal></screen>
|
---|
| 673 |
|
---|
| 674 | <para>
|
---|
| 675 | If daemons, such as squid, have to access the Internet
|
---|
| 676 | themselves, you could open OUTPUT generally and restrict
|
---|
| 677 | INPUT.
|
---|
| 678 | </para>
|
---|
| 679 |
|
---|
[018c0cc3] | 680 | <screen><literal>iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
---|
[14c0be2f] | 681 | iptables -A OUTPUT -j ACCEPT</literal></screen>
|
---|
| 682 |
|
---|
| 683 | <para>
|
---|
| 684 | However, it is generally not advisable to leave OUTPUT
|
---|
| 685 | unrestricted. You lose any control over trojans who would like
|
---|
| 686 | to "call home", and a bit of redundancy in case you've
|
---|
| 687 | (mis-)configured a service so that it broadcasts its existence
|
---|
| 688 | to the world.
|
---|
| 689 | </para>
|
---|
| 690 |
|
---|
| 691 | <para>
|
---|
| 692 | To accomplish this, you should restrict INPUT and OUTPUT
|
---|
| 693 | on all ports except those that it's absolutely necessary to have
|
---|
| 694 | open. Which ports you have to open depends on your needs: mostly
|
---|
| 695 | you will find them by looking for failed accesses in your log
|
---|
| 696 | files.
|
---|
| 697 | </para>
|
---|
| 698 |
|
---|
| 699 | <itemizedlist spacing="compact" role='iptables'>
|
---|
| 700 | <title>Have a Look at the Following Examples:</title>
|
---|
| 701 | <listitem>
|
---|
| 702 | <para>
|
---|
| 703 | Squid is caching the web:
|
---|
| 704 | </para>
|
---|
| 705 |
|
---|
[018c0cc3] | 706 | <screen><literal>iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
|
---|
| 707 | iptables -A INPUT -p tcp --sport 80 -m conntrack --ctstate ESTABLISHED \
|
---|
[14c0be2f] | 708 | -j ACCEPT</literal></screen>
|
---|
| 709 |
|
---|
| 710 | </listitem>
|
---|
| 711 | <listitem>
|
---|
| 712 | <para>
|
---|
| 713 | Your caching name server (e.g., named) does its lookups via UDP:
|
---|
| 714 | </para>
|
---|
| 715 |
|
---|
[018c0cc3] | 716 | <screen><literal>iptables -A OUTPUT -p udp --dport 53 -j ACCEPT</literal></screen>
|
---|
[14c0be2f] | 717 |
|
---|
| 718 | </listitem>
|
---|
| 719 | <listitem>
|
---|
| 720 | <para>
|
---|
| 721 | You want to be able to ping your computer to ensure it's still
|
---|
| 722 | alive:
|
---|
| 723 | </para>
|
---|
| 724 |
|
---|
[018c0cc3] | 725 | <screen><literal>iptables -A INPUT -p icmp -m icmp --icmp-type echo-request -j ACCEPT
|
---|
| 726 | iptables -A OUTPUT -p icmp -m icmp --icmp-type echo-reply -j ACCEPT</literal></screen>
|
---|
[14c0be2f] | 727 |
|
---|
| 728 | </listitem>
|
---|
| 729 | <listitem>
|
---|
[ab6bf6a] | 730 | <para id='fw-BB-4-ipt' xreflabel="BusyBox with iptables example number 4">
|
---|
[14c0be2f] | 731 | If you are frequently accessing FTP servers or enjoy chatting, you
|
---|
| 732 | might notice delays because some implementations of these daemons
|
---|
| 733 | query an identd daemon on your system to obtain usernames. Although
|
---|
| 734 | there's really little harm in this, having an identd running is not
|
---|
| 735 | recommended because many security experts feel the service gives
|
---|
| 736 | out too much additional information.
|
---|
| 737 | </para>
|
---|
| 738 |
|
---|
| 739 | <para>
|
---|
| 740 | To avoid these delays you could reject the requests with a
|
---|
| 741 | 'tcp-reset' response:
|
---|
| 742 | </para>
|
---|
| 743 |
|
---|
[018c0cc3] | 744 | <screen><literal>iptables -A INPUT -p tcp --dport 113 -j REJECT --reject-with tcp-reset</literal></screen>
|
---|
[14c0be2f] | 745 |
|
---|
| 746 | </listitem>
|
---|
| 747 | <listitem>
|
---|
| 748 | <para>
|
---|
| 749 | To log and drop invalid packets (packets
|
---|
| 750 | that came in after netfilter's timeout or some types of
|
---|
| 751 | network scans) insert these rules at the top of the chain:
|
---|
| 752 | </para>
|
---|
| 753 |
|
---|
[018c0cc3] | 754 | <screen><literal>iptables -I INPUT 0 -p tcp -m conntrack --ctstate INVALID \
|
---|
| 755 | -j LOG --log-prefix "FIREWALL:INVALID "
|
---|
| 756 | iptables -I INPUT 1 -p tcp -m conntrack --ctstate INVALID -j DROP</literal></screen>
|
---|
[14c0be2f] | 757 |
|
---|
| 758 | </listitem>
|
---|
| 759 | <listitem>
|
---|
| 760 | <para>
|
---|
| 761 | Anything coming from the outside should not have a
|
---|
| 762 | private address, this is a common attack called IP-spoofing:
|
---|
| 763 | </para>
|
---|
| 764 |
|
---|
| 765 | <screen><literal>iptables -A INPUT -i WAN1 -s 10.0.0.0/8 -j DROP
|
---|
| 766 | iptables -A INPUT -i WAN1 -s 172.16.0.0/12 -j DROP
|
---|
| 767 | iptables -A INPUT -i WAN1 -s 192.168.0.0/16 -j DROP</literal></screen>
|
---|
| 768 |
|
---|
| 769 | <para>
|
---|
| 770 | There are other addresses that you may also want to drop:
|
---|
| 771 | 0.0.0.0/8, 127.0.0.0/8, 224.0.0.0/3 (multicast and
|
---|
| 772 | experimental), 169.254.0.0/16 (Link Local Networks), and
|
---|
| 773 | 192.0.2.0/24 (IANA defined test network).
|
---|
| 774 | </para>
|
---|
| 775 | </listitem>
|
---|
| 776 | <listitem>
|
---|
| 777 | <para>
|
---|
| 778 | If your firewall is a DHCP client, you need to allow those packets:
|
---|
| 779 | </para>
|
---|
| 780 |
|
---|
[018c0cc3] | 781 | <screen><literal>iptables -A INPUT -i WAN1 -p udp -s 0.0.0.0 --sport 67 \
|
---|
| 782 | -d 255.255.255.255 --dport 68 -j ACCEPT</literal></screen>
|
---|
[14c0be2f] | 783 |
|
---|
| 784 | </listitem>
|
---|
| 785 | <listitem>
|
---|
| 786 | <para>
|
---|
| 787 | To simplify debugging and be fair to anyone who'd like
|
---|
| 788 | to access a service you have disabled, purposely or by mistake,
|
---|
| 789 | you could REJECT those packets that are dropped.
|
---|
| 790 | </para>
|
---|
| 791 |
|
---|
| 792 | <para>
|
---|
| 793 | Obviously this must be done directly after logging as the very
|
---|
| 794 | last lines before the packets are dropped by policy:
|
---|
| 795 | </para>
|
---|
| 796 |
|
---|
| 797 | <screen><literal>iptables -A INPUT -j REJECT</literal></screen>
|
---|
| 798 |
|
---|
| 799 | </listitem>
|
---|
| 800 | </itemizedlist>
|
---|
| 801 |
|
---|
| 802 | <para>
|
---|
| 803 | These are only examples to show you some of the capabilities
|
---|
| 804 | of the firewall code in Linux. Have a look at the man page of iptables.
|
---|
| 805 | There you will find much more information. The port numbers needed for
|
---|
| 806 | this can be found in <filename>/etc/services</filename>, in case you
|
---|
| 807 | didn't find them by trial and error in your log file.
|
---|
| 808 | </para>
|
---|
| 809 |
|
---|
| 810 | </sect3>
|
---|
[71072bbe] | 811 |
|
---|
| 812 | <sect3 id="iptables-init">
|
---|
[f586237] | 813 | <title><phrase revision="sysv">Boot Script</phrase>
|
---|
| 814 | <phrase revision="systemd">Systemd Unit</phrase></title>
|
---|
[71072bbe] | 815 |
|
---|
[f586237] | 816 | <para revision="sysv">
|
---|
[4591404] | 817 | To set up the iptables firewall at boot, install the
|
---|
| 818 | <filename>/etc/rc.d/init.d/iptables</filename> init script included
|
---|
[f586237] | 819 | in the <xref linkend="bootscripts"/> package.
|
---|
| 820 | </para>
|
---|
| 821 |
|
---|
| 822 | <para revision="systemd">
|
---|
| 823 | To set up the iptables firewall at boot, install the
|
---|
| 824 | <filename>iptables.service</filename> unit included in the
|
---|
| 825 | <xref linkend="systemd-units"/> package.
|
---|
[4591404] | 826 | </para>
|
---|
[71072bbe] | 827 |
|
---|
| 828 | <indexterm zone="iptables iptables-init">
|
---|
| 829 | <primary sortas="f-iptables">iptables</primary>
|
---|
| 830 | </indexterm>
|
---|
| 831 |
|
---|
| 832 | <screen role="root"><userinput>make install-iptables</userinput></screen>
|
---|
| 833 |
|
---|
| 834 | </sect3>
|
---|
| 835 |
|
---|
| 836 | </sect2>
|
---|
[018c0cc3] | 837 |
|
---|
[71072bbe] | 838 | <sect2 role="content">
|
---|
| 839 | <title>Contents</title>
|
---|
| 840 |
|
---|
| 841 | <segmentedlist>
|
---|
| 842 | <segtitle>Installed Programs</segtitle>
|
---|
| 843 | <segtitle>Installed Libraries</segtitle>
|
---|
[bf157fc2] | 844 | <segtitle>Installed Directories</segtitle>
|
---|
[71072bbe] | 845 |
|
---|
| 846 | <seglistitem>
|
---|
[4591404] | 847 | <seg>
|
---|
[8558044] | 848 | ip6tables,
|
---|
[ab6bf6a] | 849 | ip6tables-apply,
|
---|
| 850 | ip6tables-legacy,
|
---|
| 851 | ip6tables-legacy-restore,
|
---|
| 852 | ip6tables-legacy-save,
|
---|
[8558044] | 853 | ip6tables-restore,
|
---|
| 854 | ip6tables-save,
|
---|
| 855 | iptables,
|
---|
[ab6bf6a] | 856 | iptables-apply,
|
---|
| 857 | iptables-legacy,
|
---|
| 858 | iptables-legacy-restore,
|
---|
| 859 | iptables-legacy-apply,
|
---|
| 860 | iptables-restore,
|
---|
[8558044] | 861 | iptables-save,
|
---|
| 862 | iptables-xml,
|
---|
[ab6bf6a] | 863 | nfsynproxy (optional),
|
---|
| 864 | and xtables-multi
|
---|
[4591404] | 865 | </seg>
|
---|
| 866 | <seg>
|
---|
[8558044] | 867 | libip4tc.so,
|
---|
| 868 | libip6tc.so,
|
---|
| 869 | libipq.so,
|
---|
[ab6bf6a] | 870 | libiptc.so,
|
---|
| 871 | and libxtables.so
|
---|
[4591404] | 872 | </seg>
|
---|
| 873 | <seg>
|
---|
[8558044] | 874 | /lib/xtables and
|
---|
[ab6bf6a] | 875 | /usr/include/libiptc
|
---|
[4591404] | 876 | </seg>
|
---|
[71072bbe] | 877 | </seglistitem>
|
---|
| 878 | </segmentedlist>
|
---|
| 879 |
|
---|
| 880 | <variablelist>
|
---|
| 881 | <bridgehead renderas="sect3">Short Descriptions</bridgehead>
|
---|
| 882 | <?dbfo list-presentation="list"?>
|
---|
| 883 | <?dbhtml list-presentation="table"?>
|
---|
| 884 |
|
---|
| 885 | <varlistentry id="iptables-prog">
|
---|
| 886 | <term><command>iptables</command></term>
|
---|
| 887 | <listitem>
|
---|
[4591404] | 888 | <para>
|
---|
| 889 | is used to set up, maintain, and inspect the tables of
|
---|
[4c24eb0a] | 890 | IP packet filter rules in the Linux kernel
|
---|
[4591404] | 891 | </para>
|
---|
[71072bbe] | 892 | <indexterm zone="iptables iptables-prog">
|
---|
| 893 | <primary sortas="b-iptables">iptables</primary>
|
---|
| 894 | </indexterm>
|
---|
| 895 | </listitem>
|
---|
[ab6bf6a] | 896 | </varlistentry>
|
---|
| 897 |
|
---|
| 898 | <varlistentry id="iptables-apply">
|
---|
| 899 | <term><command>iptables-apply</command></term>
|
---|
| 900 | <listitem>
|
---|
| 901 | <para>
|
---|
[4c24eb0a] | 902 | is a safer way to update iptables remotely
|
---|
[ab6bf6a] | 903 | </para>
|
---|
| 904 | <indexterm zone="iptables iptables-apply">
|
---|
| 905 | <primary sortas="b-iptables-apply">iptables-apply</primary>
|
---|
| 906 | </indexterm>
|
---|
| 907 | </listitem>
|
---|
| 908 | </varlistentry>
|
---|
| 909 |
|
---|
| 910 | <varlistentry id="iptables-legacy">
|
---|
| 911 | <term><command>iptables-legacy</command></term>
|
---|
| 912 | <listitem>
|
---|
| 913 | <para>
|
---|
[4c24eb0a] | 914 | is used to interact with iptables using the legacy command set
|
---|
[ab6bf6a] | 915 | </para>
|
---|
| 916 | <indexterm zone="iptables iptables-legacy">
|
---|
| 917 | <primary sortas="b-iptables-legacy">iptables-legacy</primary>
|
---|
| 918 | </indexterm>
|
---|
| 919 | </listitem>
|
---|
| 920 | </varlistentry>
|
---|
| 921 |
|
---|
| 922 | <varlistentry id="iptables-legacy-restore">
|
---|
| 923 | <term><command>iptables-legacy-restore</command></term>
|
---|
| 924 | <listitem>
|
---|
| 925 | <para>
|
---|
[4c24eb0a] | 926 | is used to restore a set of legacy iptables rules
|
---|
[ab6bf6a] | 927 | </para>
|
---|
| 928 | <indexterm zone="iptables iptables-legacy-restore">
|
---|
| 929 | <primary sortas="b-iptables-legacy-restore">iptables-legacy-restore</primary>
|
---|
| 930 | </indexterm>
|
---|
| 931 | </listitem>
|
---|
| 932 | </varlistentry>
|
---|
| 933 |
|
---|
| 934 | <varlistentry id="iptables-legacy-save">
|
---|
| 935 | <term><command>iptables-legacy-save</command></term>
|
---|
| 936 | <listitem>
|
---|
| 937 | <para>
|
---|
[4c24eb0a] | 938 | is used to save a set of legacy iptables rules
|
---|
[ab6bf6a] | 939 | </para>
|
---|
| 940 | <indexterm zone="iptables iptables-legacy-save">
|
---|
| 941 | <primary sortas="b-iptables-legacy-save">iptables-legacy-save</primary>
|
---|
| 942 | </indexterm>
|
---|
| 943 | </listitem>
|
---|
[71072bbe] | 944 | </varlistentry>
|
---|
| 945 |
|
---|
| 946 | <varlistentry id="iptables-restore">
|
---|
| 947 | <term><command>iptables-restore</command></term>
|
---|
| 948 | <listitem>
|
---|
[4591404] | 949 | <para>
|
---|
| 950 | is used to restore IP Tables from data specified on
|
---|
| 951 | STDIN. Use I/O redirection provided by your
|
---|
[4c24eb0a] | 952 | shell to read from a file
|
---|
[4591404] | 953 | </para>
|
---|
[71072bbe] | 954 | <indexterm zone="iptables iptables-restore">
|
---|
| 955 | <primary sortas="b-iptables-restore">iptables-restore</primary>
|
---|
| 956 | </indexterm>
|
---|
| 957 | </listitem>
|
---|
| 958 | </varlistentry>
|
---|
| 959 |
|
---|
| 960 | <varlistentry id="iptables-save">
|
---|
| 961 | <term><command>iptables-save</command></term>
|
---|
| 962 | <listitem>
|
---|
[4591404] | 963 | <para>
|
---|
| 964 | is used to dump the contents of an IP Table in easily
|
---|
| 965 | parseable format to STDOUT. Use I/O-redirection
|
---|
[4c24eb0a] | 966 | provided by your shell to write to a file
|
---|
[4591404] | 967 | </para>
|
---|
[71072bbe] | 968 | <indexterm zone="iptables iptables-save">
|
---|
| 969 | <primary sortas="b-iptables-save">iptables-save</primary>
|
---|
| 970 | </indexterm>
|
---|
| 971 | </listitem>
|
---|
| 972 | </varlistentry>
|
---|
| 973 |
|
---|
[6a97e97] | 974 | <varlistentry id="iptables-xml">
|
---|
| 975 | <term><command>iptables-xml</command></term>
|
---|
| 976 | <listitem>
|
---|
[4591404] | 977 | <para>
|
---|
| 978 | is used to convert the output of
|
---|
| 979 | <command>iptables-save</command> to an XML format. Using the
|
---|
| 980 | <filename>iptables.xslt</filename> stylesheet converts the XML
|
---|
[4c24eb0a] | 981 | back to the format of <command>iptables-restore</command>
|
---|
[4591404] | 982 | </para>
|
---|
[6a97e97] | 983 | <indexterm zone="iptables iptables-xml">
|
---|
| 984 | <primary sortas="b-iptables-xml">iptables-xml</primary>
|
---|
| 985 | </indexterm>
|
---|
| 986 | </listitem>
|
---|
| 987 | </varlistentry>
|
---|
| 988 |
|
---|
[71072bbe] | 989 | <varlistentry id="ip6tables">
|
---|
[bf157fc2] | 990 | <term><command>ip6tables*</command></term>
|
---|
[71072bbe] | 991 | <listitem>
|
---|
[4591404] | 992 | <para>
|
---|
| 993 | are a set of commands for IPV6 that parallel the iptables
|
---|
[4c24eb0a] | 994 | commands above
|
---|
[4591404] | 995 | </para>
|
---|
[71072bbe] | 996 | <indexterm zone="iptables ip6tables">
|
---|
| 997 | <primary sortas="b-ip6tables">ip6tables</primary>
|
---|
| 998 | </indexterm>
|
---|
| 999 | </listitem>
|
---|
| 1000 | </varlistentry>
|
---|
| 1001 |
|
---|
[7801f02] | 1002 | <varlistentry id="nfsynproxy">
|
---|
| 1003 | <term><command>nfsynproxy</command></term>
|
---|
| 1004 | <listitem>
|
---|
| 1005 | <para>
|
---|
| 1006 | (optional) configuration tool. SYNPROXY target makes handling of
|
---|
| 1007 | large SYN floods possible without the large performance penalties
|
---|
[4c24eb0a] | 1008 | imposed by the connection tracking in such cases
|
---|
[7801f02] | 1009 | </para>
|
---|
| 1010 | <indexterm zone="iptables nfsynproxy">
|
---|
| 1011 | <primary sortas="b-nfsynproxy">nfsynproxy</primary>
|
---|
| 1012 | </indexterm>
|
---|
| 1013 | </listitem>
|
---|
| 1014 | </varlistentry>
|
---|
| 1015 |
|
---|
[c2de366] | 1016 | <varlistentry id="xtables-multi">
|
---|
| 1017 | <term><command>xtables-multi</command></term>
|
---|
| 1018 | <listitem>
|
---|
| 1019 | <para>
|
---|
[4c24eb0a] | 1020 | is a binary that behaves according to the name it is called by
|
---|
[c2de366] | 1021 | </para>
|
---|
| 1022 | <indexterm zone="iptables xtables-multi">
|
---|
| 1023 | <primary sortas="b-xtables-multi">xtables-multi</primary>
|
---|
| 1024 | </indexterm>
|
---|
| 1025 | </listitem>
|
---|
| 1026 | </varlistentry>
|
---|
| 1027 |
|
---|
[71072bbe] | 1028 | </variablelist>
|
---|
| 1029 |
|
---|
| 1030 | </sect2>
|
---|
[b4b71892] | 1031 |
|
---|
[f45b1953] | 1032 | </sect1>
|
---|