<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_plain.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:bib="http://bibtexml.sf.net/" xmlns:md="http://cnx.rice.edu/mdml/0.4" id="id3514774">
<name xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">Analysis of an iptables configuration</name>
<metadata xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
  <md:version xmlns:bib="http://bibtexml.sf.net/">**new**</md:version>
  <md:created xmlns:bib="http://bibtexml.sf.net/">2005/08/12 12:18:53.135 GMT-5</md:created>
  <md:revised xmlns:bib="http://bibtexml.sf.net/">2005/08/12 12:21:05.445 GMT-5</md:revised>
  <md:authorlist xmlns:bib="http://bibtexml.sf.net/">
      <md:author xmlns:bib="http://bibtexml.sf.net/" id="pshuff">
      <md:firstname xmlns:bib="http://bibtexml.sf.net/">Pat</md:firstname>
      
      <md:surname xmlns:bib="http://bibtexml.sf.net/">Shuff</md:surname>
      <md:email xmlns:bib="http://bibtexml.sf.net/">pshuff@rice.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist xmlns:bib="http://bibtexml.sf.net/">
    <md:maintainer xmlns:bib="http://bibtexml.sf.net/" id="pshuff">
      <md:firstname xmlns:bib="http://bibtexml.sf.net/">Pat</md:firstname>
      
      <md:surname xmlns:bib="http://bibtexml.sf.net/">Shuff</md:surname>
      <md:email xmlns:bib="http://bibtexml.sf.net/">pshuff@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist xmlns:bib="http://bibtexml.sf.net/">
    <md:keyword xmlns:bib="http://bibtexml.sf.net/">firewall</md:keyword>
    <md:keyword xmlns:bib="http://bibtexml.sf.net/">ip filters</md:keyword>
    <md:keyword xmlns:bib="http://bibtexml.sf.net/">ip firewall</md:keyword>
    <md:keyword xmlns:bib="http://bibtexml.sf.net/">iptables</md:keyword>
    <md:keyword xmlns:bib="http://bibtexml.sf.net/">linux</md:keyword>
  </md:keywordlist>

  <md:abstract xmlns:bib="http://bibtexml.sf.net/">In this module we will look at a typical setup file used to configure iptables on a Linux system and the tools to verify that the system is properly secure and operational.</md:abstract>
</metadata>
<content xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/">
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3756136">One of the steps in securing a system is
making sure that applications are restricted from connecting to the
internet and systems on the internet are prohibited from connecting
to our system. For a Linux system the application iptables can be
configured to act as a firewall and enable or disable connections.
In this section we will look a typical configuration and analyze
the option flags and operation of the operating system with the
given configuration.</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3162534">The configuration file for iptables can be
found in /etc/sysconfig/iptables. A sample file looks like:</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3239152"># Generated by iptables-save v1.2.8 on Wed Aug
10 11:11:18 2005</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3587427">*filter</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3042037">:INPUT DROP [0:0]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2737475">:FORWARD DROP [0:0]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2748036">:OUTPUT ACCEPT [0:0]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3325691">-A INPUT -i lo -j ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3219431">-A INPUT -p tcp -m state --state ESTABLISHED
-j ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3589595">-A INPUT -p tcp -m tcp --dport 22 -j
ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3671377">-A INPUT -p icmp -m icmp --icmp-type 0 -j
ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3680749">-A INPUT -p icmp -m icmp --icmp-type 8 -j
ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2953132">-A INPUT -p icmp -m icmp --icmp-type 3 -j
ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id4121049">-A INPUT -p icmp -m icmp --icmp-type 11 -j
ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3498932">-A INPUT -p icmp -m icmp --icmp-type 30 -j
ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3212672">-A INPUT -p udp -m state --state ESTABLISHED
-j ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id4104811">-A INPUT -p icmp -m state --state
RELATED,ESTABLISHED -j ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2727390">COMMIT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2390905"># Completed on Wed Aug 10 11:11:18 2005</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3343713">The first line is a comment line. All comment
lines start with a â€œ#â€ character. The
first and last lines of this file are comments generated by the
iptables-save command. The second line defines a table that will be
used. We can define multiple tables that perform different
functions. These tables can be accessed using the
â€“t option on the command line. The default table
is filter. Note that each filter has chains associated with it and
can be configured to do a variety of simple or complex
configurations.</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3991713">The three chains that we have defined are
INPUT, FORWARD, and OUTPUT. These three rules by themselves will
drop all incoming packets and all forward requests. All packets
initiated by this host will be allowed. All three of these chains
do not have any restrictions on IP addresses or ranges so by
default all incoming packets will be dropped and outgoing packets
will be allowed.</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3520445">The â€“A extensions that
follow the OUTPUT chain are exceptions to the drop all packets.
Since all of these apply to the INPUT chain, this machine is
configured to not act as a router and drop all forward requests. If
the machine in question has only one Ethernet connection, the
default is to drop all forward requests. If the machine has
multiple Ethernet connections, the iptables configuration file
tells the kernel to drop the request for routing.</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3263129">The â€“i option tells the
kernel module which Ethernet interface should be filtered. The
default is the Ethernet interface that is the primary interface as
defined by the operating system. The lo interface is the loop back
interface that is used for all local traffic typically associated
with 127.0.0.1. The naming convention used for the Ethernet
interface names is the same as that for the ifconfig command. The
one that is most common is the eth0 interface. The command
line</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2607301">-A INPUT â€“I lo
â€“j ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3694812">says that the kernel should accept anything
received through the local loopback interface and allow it to be
used by user applications. This overrides the global drop command
that we started with.</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3246876">The â€“p option defines the
protocol that the rule will apply to. The protocols are listed in
the /etc/protocols file. Looking at this file on a Linux 2.4 system
we see that there are 132 different supported protocols. Typically,
we are only concerned with three, UDP, TCP, and ICMP. The
line</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3446073">-A INPUT -p tcp -m tcp --dport 22 -j
ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2982344">for example, defines a rule for a data packet
arriving with a TCP header addressed to port 22. The
â€“dport command specifies the port number and the
â€“m option is a directive for matching. The
packet must contain and TCP header and be a valid TCP packet. We
can make this example a little more complex by adding the notion of
state</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3209972">-A INPUT -p tcp -m state --state ESTABLISHED
-j ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3741605">This match directive says that only
connections defined by the kernel will be created. The kernel
maintains state of connection definitions and no new connection
types can be constructed or defined because they will be rejected.
There are four states that can be used; INVALID, ESTABLISHED, NEW,
and RElATED. Invalid means that the packet is associated with no
know stream or connection and could be a partial or corrupted
header. Established means that the packet is part of an already
established connection and is also a valid packet. New means that
the packet has or will start a new connection and that the
connection previously did not exist. Related means that the packet
is starting a new connection and is associated with an already
established connection. An example of this would be the FTP
protocol. When a control ftp connection is created, it correlates
to a new connection. When a file is transferred via ftp a second
connection, or related connection, is created to transfer the data
across the wire.</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3292325">The last command line example that we need to
study is</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2734036">-A INPUT -p icmp -m icmp --icmp-type 0 -j
ACCEPT</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3607189">With this declaration we introduce the icmp
type to match. This type can be specified either by their numeric
values or by their names. To get a complete list of icmp types we
can execute</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2898345">iptables â€“p icmp
â€“help</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3191834">The Internet Control Message Protocol (ICMP)
has many messages that</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id4056351">are identified by a "type" field.</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2987473">TypeNameReference</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3503196">--------------------------------------</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3746320">0Echo Reply [RFC792]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3323247">1Unassigned [JBP]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3257320">2Unassigned [JBP]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3130995">3Destination Unreachable [RFC792]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3452362">4Source Quench [RFC792]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2767539">5Redirect [RFC792]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3240151">6Alternate Host Address [JBP]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3619786">7Unassigned [JBP]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2618352">8Echo [RFC792]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3521959">9Router Advertisement[RFC1256]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3620299">10Router Solicitation[RFC1256]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3443359">11Time Exceeded [RFC792]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3746616">12Parameter Problem [RFC792]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id4092339">13Timestamp [RFC792]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3252064">14Timestamp Reply [RFC792]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3011082">15Information Request [RFC792]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id4222843">16Information Reply [RFC792]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2697676">17Address Mask Request [RFC950]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2742764">18Address Mask Reply [RFC950]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3666136">19Reserved (for Security) [Solo]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3893624">20-29Reserved (for Robustness Experiment)
[ZSu]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3467984">30Traceroute[RFC1393]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3137650">31Datagram Conversion Error[RFC1475]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3434485">32 Mobile Host Redirect [David Johnson]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id4181286">33 IPv6 Where-Are-You [Bill Simpson]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3742431">34 IPv6 I-Am-Here [Bill Simpson]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3841674">35 Mobile Registration Request [Bill
Simpson]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3763467">36 Mobile Registration Reply [Bill
Simpson]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3343439">37 Domain Name Request [RFC1788]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3520487">38 Domain Name Reply [RFC1788]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2699828">39 SKIP [Markson]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2606100">40 Photuris [RFC2521]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id3645049">41 ICMP messages utilized by experimental
[RFC-ietf-seamoby-iana-02.txt]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id4106924">mobility protocols such as Seamoby</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2759079">42-255 Reserved [JBP]</para>
<para xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="id2730084">The â€“p icmp is a generic
definition, the â€“m icmp is also a generic
definition. The â€“icmp-type 0
â€“j ACCEPT says to accept all echo
requests.</para>
</content>
</document>
