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