[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 |
|
---|
[baf47952] | 7 | <!ENTITY iptables-download-http "http://www.netfilter.org/projects/iptables/files/iptables-&iptables-version;.tar.bz2">
|
---|
[b4b71892] | 8 | <!ENTITY iptables-download-ftp "ftp://ftp.netfilter.org/pub/iptables/iptables-&iptables-version;.tar.bz2">
|
---|
[4d1ad24] | 9 | <!ENTITY iptables-md5sum "b5b0b43afc245176c36a14c4fca6e661">
|
---|
| 10 | <!ENTITY iptables-size "662 KB">
|
---|
| 11 | <!ENTITY iptables-buildsize "11 MB">
|
---|
[d10edc46] | 12 | <!ENTITY iptables-time "0.1 SBU">
|
---|
[b4b71892] | 13 | ]>
|
---|
| 14 |
|
---|
[4591404] | 15 | <sect1 id="iptables" xreflabel="Iptables-&iptables-version;">
|
---|
[71072bbe] | 16 | <?dbhtml filename="iptables.html"?>
|
---|
| 17 |
|
---|
| 18 | <sect1info>
|
---|
| 19 | <othername>$LastChangedBy$</othername>
|
---|
| 20 | <date>$Date$</date>
|
---|
| 21 | </sect1info>
|
---|
| 22 |
|
---|
| 23 | <title>Iptables-&iptables-version;</title>
|
---|
| 24 |
|
---|
| 25 | <indexterm zone="iptables">
|
---|
| 26 | <primary sortas="a-Iptables">Iptables</primary>
|
---|
| 27 | </indexterm>
|
---|
| 28 |
|
---|
| 29 | <sect2 role="package">
|
---|
| 30 | <title>Introduction to Iptables</title>
|
---|
| 31 |
|
---|
[4591404] | 32 | <para>
|
---|
[d6da5da] | 33 | The next part of this chapter deals with firewalls. The principal
|
---|
[4591404] | 34 | firewall tool for Linux is <application>Iptables</application>. You will
|
---|
| 35 | need to install <application>Iptables</application> if you intend on using
|
---|
| 36 | any form of a firewall.
|
---|
| 37 | </para>
|
---|
[71072bbe] | 38 |
|
---|
[9eb7ee7] | 39 | &lfs83_checked;
|
---|
[93236c2] | 40 |
|
---|
[71072bbe] | 41 | <bridgehead renderas="sect3">Package Information</bridgehead>
|
---|
| 42 | <itemizedlist spacing="compact">
|
---|
| 43 | <listitem>
|
---|
[4591404] | 44 | <para>
|
---|
| 45 | Download (HTTP): <ulink url="&iptables-download-http;"/>
|
---|
| 46 | </para>
|
---|
[71072bbe] | 47 | </listitem>
|
---|
| 48 | <listitem>
|
---|
[4591404] | 49 | <para>
|
---|
| 50 | Download (FTP): <ulink url="&iptables-download-ftp;"/>
|
---|
| 51 | </para>
|
---|
[71072bbe] | 52 | </listitem>
|
---|
| 53 | <listitem>
|
---|
[4591404] | 54 | <para>
|
---|
| 55 | Download MD5 sum: &iptables-md5sum;
|
---|
| 56 | </para>
|
---|
[71072bbe] | 57 | </listitem>
|
---|
| 58 | <listitem>
|
---|
[4591404] | 59 | <para>
|
---|
| 60 | Download size: &iptables-size;
|
---|
| 61 | </para>
|
---|
[71072bbe] | 62 | </listitem>
|
---|
| 63 | <listitem>
|
---|
[4591404] | 64 | <para>
|
---|
| 65 | Estimated disk space required: &iptables-buildsize;
|
---|
| 66 | </para>
|
---|
[71072bbe] | 67 | </listitem>
|
---|
| 68 | <listitem>
|
---|
[4591404] | 69 | <para>
|
---|
| 70 | Estimated build time: &iptables-time;
|
---|
| 71 | </para>
|
---|
[71072bbe] | 72 | </listitem>
|
---|
| 73 | </itemizedlist>
|
---|
[d6da5da] | 74 |
|
---|
[924fcd6] | 75 | <bridgehead renderas="sect3">Iptables Dependencies</bridgehead>
|
---|
| 76 |
|
---|
| 77 | <bridgehead renderas="sect4">Optional</bridgehead>
|
---|
| 78 | <para role="optional">
|
---|
| 79 | <ulink url="http://www.netfilter.org/projects/nftables/index.html">nftables</ulink>
|
---|
| 80 | </para>
|
---|
| 81 |
|
---|
| 82 |
|
---|
[3597eb6] | 83 | <para condition="html" role="usernotes">User Notes:
|
---|
[4591404] | 84 | <ulink url="&blfs-wiki;/iptables"/>
|
---|
| 85 | </para>
|
---|
[ce6ccc9] | 86 | </sect2>
|
---|
[b4b71892] | 87 |
|
---|
[4591404] | 88 | <sect2 role="kernel" id="iptables-kernel">
|
---|
[71072bbe] | 89 | <title>Kernel Configuration</title>
|
---|
[b4b71892] | 90 |
|
---|
[4591404] | 91 | <para>
|
---|
| 92 | A firewall in Linux is accomplished through a portion of the
|
---|
| 93 | kernel called netfilter. The interface to netfilter is
|
---|
| 94 | <application>Iptables</application>. To use it, the appropriate
|
---|
[38155d1] | 95 | kernel configuration parameters are found in:
|
---|
[4591404] | 96 | </para>
|
---|
[f8962fe] | 97 |
|
---|
[38155d1] | 98 | <screen><literal>[*] Networking support ---> [CONFIG_NET]
|
---|
| 99 | Networking Options --->
|
---|
| 100 | [*] Network packet filtering framework (Netfilter) ---> [CONFIG_NETFILTER]</literal></screen>
|
---|
| 101 |
|
---|
[71072bbe] | 102 | <indexterm zone="iptables iptables-kernel">
|
---|
| 103 | <primary sortas="d-iptables">Iptables</primary>
|
---|
| 104 | </indexterm>
|
---|
[48ecffe8] | 105 |
|
---|
[71072bbe] | 106 | </sect2>
|
---|
[48ecffe8] | 107 |
|
---|
[71072bbe] | 108 | <sect2 role="installation">
|
---|
| 109 | <title>Installation of Iptables</title>
|
---|
[48ecffe8] | 110 |
|
---|
[71072bbe] | 111 | <note>
|
---|
[4591404] | 112 | <para>
|
---|
| 113 | The installation below does not include building some specialized
|
---|
| 114 | extension libraries which require the raw headers in the
|
---|
| 115 | <application>Linux</application> source code. If you wish to build the
|
---|
| 116 | additional extensions (if you aren't sure, then you probably don't), you
|
---|
| 117 | can look at the <filename>INSTALL</filename> file to see an example of
|
---|
| 118 | how to change the <parameter>KERNEL_DIR=</parameter> parameter to point
|
---|
| 119 | at the <application>Linux</application> source code. Note that if you
|
---|
| 120 | upgrade the kernel version, you may also need to recompile
|
---|
| 121 | <application>Iptables</application> and that the BLFS team has not tested
|
---|
| 122 | using the raw kernel headers.
|
---|
| 123 | </para>
|
---|
| 124 |
|
---|
| 125 | <para>
|
---|
| 126 | For some non-x86 architectures, the raw kernel headers may be
|
---|
| 127 | required. In that case, modify the <parameter>KERNEL_DIR=</parameter>
|
---|
| 128 | parameter to point at the <application>Linux</application> source
|
---|
| 129 | code.
|
---|
| 130 | </para>
|
---|
[71072bbe] | 131 | </note>
|
---|
| 132 |
|
---|
[4402a39] | 133 | <para>
|
---|
[4d1ad24] | 134 | Fix a build failure if
|
---|
[4402a39] | 135 | <ulink url="http://www.netfilter.org/projects/nftables/index.html">nftables</ulink>
|
---|
[4d1ad24] | 136 | is not installed:
|
---|
[4402a39] | 137 | </para>
|
---|
| 138 |
|
---|
[4d1ad24] | 139 | <screen><userinput>sed -e "/iptables\/nft\.h/d" \
|
---|
| 140 | -i extensions/libxt_limit.c
|
---|
| 141 | sed -e "/^struct nftnl_rule;/a struct iptables_command_state;" \
|
---|
| 142 | -i iptables/nft-bridge.h</userinput></screen>
|
---|
[4402a39] | 143 |
|
---|
[4591404] | 144 | <para>
|
---|
| 145 | Install <application>Iptables</application> by running the following
|
---|
| 146 | commands:
|
---|
| 147 | </para>
|
---|
| 148 |
|
---|
[924fcd6] | 149 | <screen><userinput>./configure --prefix=/usr \
|
---|
| 150 | --sbindir=/sbin \
|
---|
| 151 | --disable-nftables \
|
---|
| 152 | --enable-libipq \
|
---|
[04f35fe3] | 153 | --with-xtlibdir=/lib/xtables &&
|
---|
[bf157fc2] | 154 | make</userinput></screen>
|
---|
[ce6ccc9] | 155 |
|
---|
| 156 | <para>This package does not come with a test suite.</para>
|
---|
[71072bbe] | 157 |
|
---|
| 158 | <para>Now, as the <systemitem class="username">root</systemitem> user:</para>
|
---|
| 159 |
|
---|
[93236c2] | 160 | <screen role="root"><userinput>make install &&
|
---|
[5c9b6c1] | 161 | ln -sfv ../../sbin/xtables-legacy-multi /usr/bin/iptables-xml &&
|
---|
[04f35fe3] | 162 |
|
---|
[5ae7a99] | 163 | for file in ip4tc ip6tc ipq iptc xtables
|
---|
[23407e4] | 164 | do
|
---|
[5ae7a99] | 165 | mv -v /usr/lib/lib${file}.so.* /lib &&
|
---|
| 166 | ln -sfv ../../lib/$(readlink /usr/lib/lib${file}.so) /usr/lib/lib${file}.so
|
---|
[23407e4] | 167 | done</userinput></screen>
|
---|
[71072bbe] | 168 |
|
---|
| 169 | </sect2>
|
---|
[d40737d] | 170 |
|
---|
[71072bbe] | 171 | <sect2 role="commands">
|
---|
| 172 | <title>Command Explanations</title>
|
---|
| 173 |
|
---|
[4591404] | 174 | <para>
|
---|
[ddc02883] | 175 | <parameter>--disable-nftables</parameter>: This switch disables building
|
---|
[f586237] | 176 | nftables compat. Omit this switch if you have installed nftables.
|
---|
[4591404] | 177 | </para>
|
---|
| 178 |
|
---|
| 179 | <para>
|
---|
[924fcd6] | 180 | <parameter>--enable-libipq</parameter>: This switch enables building
|
---|
[4591404] | 181 | of <filename class="libraryfile">libipq.so</filename> which
|
---|
| 182 | can be used by some packages outside of BLFS.
|
---|
| 183 | </para>
|
---|
| 184 |
|
---|
[924fcd6] | 185 | <para>
|
---|
| 186 | <parameter>--with-xtlibdir=/lib/xtables</parameter>: Ensure all
|
---|
| 187 | <application>Iptables</application> modules are installed in the
|
---|
| 188 | <filename class="directory">/lib/xtables</filename> directory.
|
---|
| 189 | </para>
|
---|
| 190 |
|
---|
[7801f02] | 191 | <para>
|
---|
| 192 | <option>--enable-nfsynproxy</option>: This switch enables installation
|
---|
| 193 | of <application>nfsynproxy</application> SYNPROXY configuration tool.
|
---|
| 194 | </para>
|
---|
| 195 |
|
---|
[4591404] | 196 | <para>
|
---|
[5c9b6c1] | 197 | <command>ln -sfv ../../sbin/xtables-legacy-multi /usr/bin/iptables-xml</command>:
|
---|
[5ae7a99] | 198 | Ensure the symbolic link for <command>iptables-xml</command> is relative.
|
---|
[4591404] | 199 | </para>
|
---|
[93236c2] | 200 |
|
---|
[71072bbe] | 201 | </sect2>
|
---|
[d40737d] | 202 |
|
---|
[71072bbe] | 203 | <sect2 role="configuration">
|
---|
| 204 | <title>Configuring Iptables</title>
|
---|
| 205 |
|
---|
[4591404] | 206 | <para>
|
---|
| 207 | Introductory instructions for configuring your firewall are
|
---|
| 208 | presented in the next section: <xref linkend="fw-firewall"/>
|
---|
| 209 | </para>
|
---|
[71072bbe] | 210 |
|
---|
| 211 | <sect3 id="iptables-init">
|
---|
[f586237] | 212 | <title><phrase revision="sysv">Boot Script</phrase>
|
---|
| 213 | <phrase revision="systemd">Systemd Unit</phrase></title>
|
---|
[71072bbe] | 214 |
|
---|
[f586237] | 215 | <para revision="sysv">
|
---|
[4591404] | 216 | To set up the iptables firewall at boot, install the
|
---|
| 217 | <filename>/etc/rc.d/init.d/iptables</filename> init script included
|
---|
[f586237] | 218 | in the <xref linkend="bootscripts"/> package.
|
---|
| 219 | </para>
|
---|
| 220 |
|
---|
| 221 | <para revision="systemd">
|
---|
| 222 | To set up the iptables firewall at boot, install the
|
---|
| 223 | <filename>iptables.service</filename> unit included in the
|
---|
| 224 | <xref linkend="systemd-units"/> package.
|
---|
[4591404] | 225 | </para>
|
---|
[71072bbe] | 226 |
|
---|
| 227 | <indexterm zone="iptables iptables-init">
|
---|
| 228 | <primary sortas="f-iptables">iptables</primary>
|
---|
| 229 | </indexterm>
|
---|
| 230 |
|
---|
| 231 | <screen role="root"><userinput>make install-iptables</userinput></screen>
|
---|
| 232 |
|
---|
| 233 | </sect3>
|
---|
| 234 |
|
---|
| 235 | </sect2>
|
---|
| 236 |
|
---|
| 237 | <sect2 role="content">
|
---|
| 238 | <title>Contents</title>
|
---|
| 239 |
|
---|
| 240 | <segmentedlist>
|
---|
| 241 | <segtitle>Installed Programs</segtitle>
|
---|
| 242 | <segtitle>Installed Libraries</segtitle>
|
---|
[bf157fc2] | 243 | <segtitle>Installed Directories</segtitle>
|
---|
[71072bbe] | 244 |
|
---|
| 245 | <seglistitem>
|
---|
[4591404] | 246 | <seg>
|
---|
| 247 | ip6tables, ip6tables-restore, ip6tables-save, iptables, iptables-restore,
|
---|
[c2de366] | 248 | iptables-save, iptables-xml, nfsynproxy (optional) and xtables-multi
|
---|
[4591404] | 249 | </seg>
|
---|
| 250 | <seg>
|
---|
[c8f569a] | 251 | libip4tc.so, libip6tc.so, libipq.so, libiptc.so, and libxtables.so
|
---|
[4591404] | 252 | </seg>
|
---|
| 253 | <seg>
|
---|
| 254 | /lib/xtables and /usr/include/libiptc
|
---|
| 255 | </seg>
|
---|
[71072bbe] | 256 | </seglistitem>
|
---|
| 257 | </segmentedlist>
|
---|
| 258 |
|
---|
| 259 | <variablelist>
|
---|
| 260 | <bridgehead renderas="sect3">Short Descriptions</bridgehead>
|
---|
| 261 | <?dbfo list-presentation="list"?>
|
---|
| 262 | <?dbhtml list-presentation="table"?>
|
---|
| 263 |
|
---|
| 264 | <varlistentry id="iptables-prog">
|
---|
| 265 | <term><command>iptables</command></term>
|
---|
| 266 | <listitem>
|
---|
[4591404] | 267 | <para>
|
---|
| 268 | is used to set up, maintain, and inspect the tables of
|
---|
| 269 | IP packet filter rules in the Linux kernel.
|
---|
| 270 | </para>
|
---|
[71072bbe] | 271 | <indexterm zone="iptables iptables-prog">
|
---|
| 272 | <primary sortas="b-iptables">iptables</primary>
|
---|
| 273 | </indexterm>
|
---|
| 274 | </listitem>
|
---|
| 275 | </varlistentry>
|
---|
| 276 |
|
---|
| 277 | <varlistentry id="iptables-restore">
|
---|
| 278 | <term><command>iptables-restore</command></term>
|
---|
| 279 | <listitem>
|
---|
[4591404] | 280 | <para>
|
---|
| 281 | is used to restore IP Tables from data specified on
|
---|
| 282 | STDIN. Use I/O redirection provided by your
|
---|
| 283 | shell to read from a file.
|
---|
| 284 | </para>
|
---|
[71072bbe] | 285 | <indexterm zone="iptables iptables-restore">
|
---|
| 286 | <primary sortas="b-iptables-restore">iptables-restore</primary>
|
---|
| 287 | </indexterm>
|
---|
| 288 | </listitem>
|
---|
| 289 | </varlistentry>
|
---|
| 290 |
|
---|
| 291 | <varlistentry id="iptables-save">
|
---|
| 292 | <term><command>iptables-save</command></term>
|
---|
| 293 | <listitem>
|
---|
[4591404] | 294 | <para>
|
---|
| 295 | is used to dump the contents of an IP Table in easily
|
---|
| 296 | parseable format to STDOUT. Use I/O-redirection
|
---|
| 297 | provided by your shell to write to a file.
|
---|
| 298 | </para>
|
---|
[71072bbe] | 299 | <indexterm zone="iptables iptables-save">
|
---|
| 300 | <primary sortas="b-iptables-save">iptables-save</primary>
|
---|
| 301 | </indexterm>
|
---|
| 302 | </listitem>
|
---|
| 303 | </varlistentry>
|
---|
| 304 |
|
---|
[6a97e97] | 305 | <varlistentry id="iptables-xml">
|
---|
| 306 | <term><command>iptables-xml</command></term>
|
---|
| 307 | <listitem>
|
---|
[4591404] | 308 | <para>
|
---|
| 309 | is used to convert the output of
|
---|
| 310 | <command>iptables-save</command> to an XML format. Using the
|
---|
| 311 | <filename>iptables.xslt</filename> stylesheet converts the XML
|
---|
| 312 | back to the format of <command>iptables-restore</command>.
|
---|
| 313 | </para>
|
---|
[6a97e97] | 314 | <indexterm zone="iptables iptables-xml">
|
---|
| 315 | <primary sortas="b-iptables-xml">iptables-xml</primary>
|
---|
| 316 | </indexterm>
|
---|
| 317 | </listitem>
|
---|
| 318 | </varlistentry>
|
---|
| 319 |
|
---|
[71072bbe] | 320 | <varlistentry id="ip6tables">
|
---|
[bf157fc2] | 321 | <term><command>ip6tables*</command></term>
|
---|
[71072bbe] | 322 | <listitem>
|
---|
[4591404] | 323 | <para>
|
---|
| 324 | are a set of commands for IPV6 that parallel the iptables
|
---|
| 325 | commands above.
|
---|
| 326 | </para>
|
---|
[71072bbe] | 327 | <indexterm zone="iptables ip6tables">
|
---|
| 328 | <primary sortas="b-ip6tables">ip6tables</primary>
|
---|
| 329 | </indexterm>
|
---|
| 330 | </listitem>
|
---|
| 331 | </varlistentry>
|
---|
| 332 |
|
---|
[7801f02] | 333 | <varlistentry id="nfsynproxy">
|
---|
| 334 | <term><command>nfsynproxy</command></term>
|
---|
| 335 | <listitem>
|
---|
| 336 | <para>
|
---|
| 337 | (optional) configuration tool. SYNPROXY target makes handling of
|
---|
| 338 | large SYN floods possible without the large performance penalties
|
---|
| 339 | imposed by the connection tracking in such cases.
|
---|
| 340 | </para>
|
---|
| 341 | <indexterm zone="iptables nfsynproxy">
|
---|
| 342 | <primary sortas="b-nfsynproxy">nfsynproxy</primary>
|
---|
| 343 | </indexterm>
|
---|
| 344 | </listitem>
|
---|
| 345 | </varlistentry>
|
---|
| 346 |
|
---|
[c2de366] | 347 | <varlistentry id="xtables-multi">
|
---|
| 348 | <term><command>xtables-multi</command></term>
|
---|
| 349 | <listitem>
|
---|
| 350 | <para>
|
---|
| 351 | is a binary that behaves according to the name it is called by.
|
---|
| 352 | </para>
|
---|
| 353 | <indexterm zone="iptables xtables-multi">
|
---|
| 354 | <primary sortas="b-xtables-multi">xtables-multi</primary>
|
---|
| 355 | </indexterm>
|
---|
| 356 | </listitem>
|
---|
| 357 | </varlistentry>
|
---|
| 358 |
|
---|
[71072bbe] | 359 | </variablelist>
|
---|
| 360 |
|
---|
| 361 | </sect2>
|
---|
[b4b71892] | 362 |
|
---|
[f45b1953] | 363 | </sect1>
|
---|