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