LINUXsecure_LOGO
Issues on Linux and Security
 
-->
 
 
 
 
 
 
 
home
button Protection --> Iptables
 

Just under construction, version 0.1, last update 2003/01/28

Iptables (3 pages)

Contents
  1. What is Iptables?
  2. Builtin Chains and Building Chains
  3. Tables
  4. Targets
  5. Default Policy
  6. Filtering Options
  7. Step by Step: A Personal Firewall
  8. Step by Step: An Internet Gateway

What is Iptables?

Iptables is a command line tool to feed the linux kernel 2.4 based firewall (netfilter) with rules. The netfilter architecture is build in a modular manner. That means that new abilities can be loaded into the kernel. This is done via insmod. So this architecture is open for modifications.

Besides it's modular architecture, the netfilter firewall has one new ability, that makes it ready for competition with the Big Firewalls on the market. And this is state tracking. Statefulness of firewalls means, that these firewalls are able to track the connection states of network connections. This makes a firewall faster, because only the packets, starting a connection, have to be checked against the rule set (the others are only checked against the state table), and it makes it also more secure, because you can filter out some types of portscans and traffic, that does not belong to a established connection.

The new linux firewall has also the chain concept of its predessor ipchains. Chains are userdefined groups of rules you can pass packets to. That means, if a packet is matched by a rule, you do not have to accept or reject this packet, but you can pass it to another chain for further inspection.

This chain concept has two advantages. First, it can reduce the complexity of your ruleset by dividing your rules in sets of generel and specific ones. You can then pass packets form specific to general chains or vice versa. The second advantage is, that chains can make your firewall faster. Firewalls normally check against the rules in a sequential way, begining with the first rule defined. The first rule that matches the characteristics of a network packes is performed on that packet. So it is accepted or rejected. The rules for packets occuring most often, should be at top position of the ruleset to gain performance. This will normally make the ruleset more complex, because rules, that belong to the same service, are seperated. With chains, you can reduce the average number of comparisions of packets against rules by seperating the stream of packets according to their characteristics.

Builtin Chains and Building Chains

You can think about a chain as a group of rules. Every packet that is passed to a chain, is comapred to the rules in that chain. If one rule matches, then a target is apllied. This can be ACCEPT or DROP or another chain to which the packet is then passed. So you can build groups of rules that are connected in some sence like a real chain.

There are three builtin standard chains, namely INPUT, OUTPUT, and FORWARD. The names of the chains describe exactly what they are doing. The input chain is responsible for all packets, that are received by the firewall device. The OUTPUT chain is responsible for all packets leaving the firewall, and the FORWARD chain is responsibe for passing packets from the INPUT to the OUTPUT chain, so basically it acts as a router.

If the firewall is not a personal firewall, but acts as a router, every packet, that goes through it, first passes the INPUT chain, then the FORWARD one, then the OUTPUT chain. If iptables acts as a personal firewall, then every packet passes only the INPUT or the OUTPUT chain.

You can build new chains, for example to pass a packet from the INPUT chain to user defined chain for further inspection. The syntax is:

iptables -N <name>

Example 1 shows how to build a new chain with the name TCP_IN.

Example 1: Building a new chain
$ iptables -N TCP_IN

You can flush a chain (remove all rules from that chain), by using the -F option. The syntax is:

iptables -F <chain>

See example 2 for flushing the chain TCP_IN.

Example 2: Flushing a chain
$ iptables -F TCP_IN

If no chain is given, then all chains are flushed.

If you want to delete a chain, then you have to use the -X option. The syntax is:

iptables -X <chain>

See example 3 for deleting the chain TCP_IN.

Example 3: deleting a chain
$ iptables -X TCP_IN

If no chain is given, then all chains are deleted.

Tables

I do not want to describe tables in much detail, because I will not use them explicitly in my examples (but implicitly they are used). Tables contain chains. Three builtin tables exist. These are the tables filter, nat, and mangle. The table filter contains the standard butltin chains INPUT, OUTPUT, and FORWARD. nat is a special table used for network addess translation, and mangle a specialized table for packet alteration. If you are interested in learning more about it, read the related HOWTOs.

Targets

Target means the following: if a rule matches the characteristics of a packet (part of network traffic), the firewall passes it to the defined target. Besides passing it to antoher chain for further inspection, you can use the buildin targets that are: ACCEPT, DROP, QUEUE, RETURN. You can also put LOG into the group of targets. LOG does print out a log line via syslog if the packet matches, but instead of going on with the next packet, the firewall continues to compare the actual packtet with the ruleset in order to find a rule (or the default policy) that tells her, what to do with the packet (to accept or to drop it).

ACCEPT simply means, that the apacket is accepted, and so it passes the firewall, whereas DROP means, that the firewall will not let the packet pass. RETURN will pass a packet, if it has not matched any rule within a chain to the next chain, and QUEUE will pass the packet to userspace. But the targets, that will be interesting for us, are only ACCEPT and DROP.

Targets are, with exceptions like in the default policy, used with the following syntax

iptables -A <chain> <rule specifications> -j <target>

So, in order to let all packets, that are received by the firewall, pass without checking for further specifics (the same as the default policy ACCEPT), see example 4.

Example 4: Setting a taget for a rule
$ iptables -A INPUT -j ACCEPT

Default Policy

The default policy is the policy that is applied to a packet if no rule has matched. Fortunately, you have to relate the way you write your rules to the default policy chosen. There are mainly two ways. Everything, that is not allowed is accepted. So the default policy will be drop or reject. Or, everything that is not denied or rejected, is allowed. In this case, the default policy would be accept.

Normally, it is easier (and also much safer) to define, what traffic is allowed. And so, the default policy is nearly always drop or reject. The syntax of defining a default policy is:

iptables -P <chain> <target>

In example 5, I will set the default policies for INPUT, OUTPUT, and FORWARY on deny.

Example 5: Setting a default policy
$ iptables -P INPUT DROP
$ iptables -P OUTPUT DROP
$ iptables -P FORWARD DROP

1 | 2 | 3 | next >>


back to top

button Whats New
[2005-02-18] mp3riot version 1.3 released
[2004-10-08] mp3riot version 1.2 is out.
[2004-04-30] Added section Bridging
[2004-01-09] working progress on mp3riot version 1.2
The LWN.net Weekly Edition for September 9, 2010 is available.
[$] LWN.net Weekly Edition for September 9, 2010

The Mozilla project has released firefox 3.6.9 and 3.5.12and SeaMonkey 2.0.7. These updates fix a relatively long list of scary security problems; the firefox 3.6.9 update also add support for X-Frame-Options, which can be used by web sites to prevent their content from being trapped inside another site's frames.
Firefox and SeaMonkey updates released

Debianhas updated typo3-src(fix regression from previous update), freetype(multiple vulnerabilities), and xulrunner(multiple vulnerabilities). Gentoohas updated sarg(buffer overflows - vulnerability from 2008), acroread(multiple vulnerabilities), and clamav(multiple vulnerabilities). openSUSEhas updated kernel(multiple vulnerabilities) and sudo(local privilege escalation). Red Hathas updated seamonkey(RHEL3-4: multiple vulnerabilities), firefox(RHEL4-5: multiple vulnerabilities), and thunderbird(RHEL4-5: multiple vulnerabilities). SUSEhas updated kernel(multiple vulnerabilities). Ubuntuhas updated lftp(remote file creation).
Wednesday's security updates

The second alpha version of the revised Mozilla Public Licensehas been posted; the text has been annotated to make it relatively easy to see what has been changed. "The most significant change in this draft is the patent language. We have made it easier to read but also, we hope, better at protecting communities who choose to use the MPL. It should also have the side effect of making the license Apache-compatible, allowing projects licensed under the next MPL release to include Apache-licensed code in their code bases."
Mozilla Public License Alpha 2

The Mozilla Labs Gaming project has announced its existence. "Modern Open Web technologies introduced a complete stack of technologies such as Open Video, audio, WebGL, touch events, device orientation, geo location, and fast JavaScript engines which make it possible to build complex (and not so complex) games on the Web. With these technologies being delivered through modern browsers today, the time is ripe for pushing the platform. And what better way than through games?"The project is starting with a competitionto see who can build the best web-based game.
Mozilla Labs Gaming launches

Microsoft's CodePlex foundationCodePlex.com has announcedthe donation of $25,000 to support the development of the Mercurial source code management system. "While Team Foundation Server is still the most used version control system on CodePlex, our users are clearly benefiting from having access to Mercurial for their open source projects. The CodePlex team is happy to be able to offer our community of more than 17,000 projects a choice. With Mercurial as an important feature of CodePlex, we are excited to be making this donation to help support the Mercurial project."
CodePlex.com donates $25,000 to Mercurial project

Mozilla has released Thunderbird 3.1.3 and Thunderbird 3.0.7 with security and stability updates. See the release notes for details (3.1.3and 3.0.7).
Thunderbird 3.1.3 and 3.0.7 security updates now available

Watching Ubuntu and Fedora development is something like watching episodes of Iron Chef: Given roughly the same ingredients and the same amount of time, the two projects produce vastly different dishes. The Fedora 14 and Ubuntu 10.10 release cycle is particularly pronounced in this regard, with Ubuntu's focus largely on refining improvements from 10.04 and Fedora introducing major changes to the infrastructure. Subscribers can click below for the full story from this week's Distributions page.
[$] Looking at Fedora 14 and Ubuntu 10.10

Debianhas updated quagga(denial of service). Gentoohas updated maildrop(privilege escalation) and sudo(privilege escalation). openSUSEhas updated xorg-x11-server(privilege escalation). Red Hathas updated sudo(privilege escalation), kernel(RHEL 4, RHEL 4.7: privilege escalation), and rpm(RHEL 4, RHEL 5: privilege escalation). Ubuntuhas updated sudo(privilege escalation).
Security advisories for Tuesday

Your editor had the good fortune to be able to attend the first LinuxCon Brazil event, held in São Paulo. There were a number of interesting talks to be seen, presented by speakers from Brazil and far beyond. This article will cover three in particular (by Jane Silber, Vinod Kutty, and Jon 'Maddog' Hall) which were interesting as a result of the very different views they gave on how Linux users work with their systems.
[$] LC Brazil: Consumers, experts, or admins?

The 1.10.0 release of the Cairo graphics library has finally been released. "One of the more interesting departures for cairo for this release is the inclusion of a tracing utility, cairo-trace. cairo-trace generates a human-readable, replayable, compact representation of the sequences of drawing commands made by an application. This can be used to inspecting applications to understand issues and as a means for profiling real-world usage of cairo."The profiling feature has evidently been used to improve performance in a number of areas. There is also improved printing support, better 16-bit buffer support, and better use of hardware acceleration.
Cairo 1.10.0 available

Martin Graesslin looksat problems with the interaction between KWin and some graphics drivers. "Now that I have explained all our checks we did to ensure a smooth user experience, I want to explain how it could happen that there are regressions in 4.5. In 4.5 we introduced two new features which require OpenGL Shaders: the blur effect and the lanczos filter. Both are not hard requirements. Blur effect can easily be turned off by disabling the effect and the lanczos filter is controlled by the general effect level settings which is also used for Plasma and Oxygen animations. Both new features check for the required extensions and get only activated iff the driver claims support for it. So everything should be fine, shouldn't it? Apparently not when it comes to the free graphics drivers (please note and remember: we do not see such problems with the proprietary NVIDIA driver!)."(Thanks to Jos Poortvliet)
Graesslin: Driver dilemma in KDE workspaces 4.5

Debianhas updated smbind(sql injection). Fedorahas updated pam_mount(F13, F12: arbitrary code execution), libhx(F13, F12: arbitrary code execution), F13: python(multiple vulnerabilities), and F12: sblim-sfcb(arbitrary code execution). Mandrivahas updated lvm2(privilege escalation). Pardushas updated phpmyadmin(cross-site scripting) and mysql(multiple vulnerabilities).
Monday's security updates

Fedora will be holding a Systemd test dayon September 7, 2010. "This week's Test Day, which will take place on Tuesday 2010/09/07 rather than the more usual Thursday, is on systemd, so it's a very important one! It will also serve at least two functions: as usual, the testing will help us to improve the code so that if it does go into the final Fedora 14 release it will work as well as possible, but the Fedora steering committee will also be using the results of the Test Day to help inform their final decision as to whether to go ahead with systemd for the Beta and final release, or whether to revert to upstart. So there's a lot riding on this Test Day."
Systemd Test Day on Tuesday 2010/09/07

Version 7.2 of the GDB debugger is out. New features include support for the D language, some C++ improvements, better Python support, better tracepoint support, and more; see the announcement for the details.
GDB 7.2 released

Linux Kernel 'snd_seq_oss_open()' Multiple Local Memory Corruption Vulnerabilities
Vuln: Linux Kernel 'snd_seq_oss_open()' Multiple Local Memory Corruption Vulnerabilities

EMC Celerra Unified Storage Platform NAS Security Bypass Vulnerability
Vuln: EMC Celerra Unified Storage Platform NAS Security Bypass Vulnerability

Wireshark 0.8.20 through 1.2.8 Multiple Vulnerabilities
Vuln: Wireshark 0.8.20 through 1.2.8 Multiple Vulnerabilities

Wireshark DOCSIS Dissector Denial of Service Vulnerability
Vuln: Wireshark DOCSIS Dissector Denial of Service Vulnerability

ESA-2010-015: EMC Celerra NFS authentication bypass vulnerability using IP spoofing.
Bugtraq: ESA-2010-015: EMC Celerra NFS authentication bypass vulnerability using IP spoofing.

[USN-985-1] mountall vulnerability
Bugtraq: [USN-985-1] mountall vulnerability

ESA-2010-016: RSA, The Security Division of EMC, releases security hot fix for a potential vulnerability in RSAŽ Access Manager Agent when working with RSAŽ Adaptive Authentication.
Bugtraq: ESA-2010-016: RSA, The Security Division of EMC, releases security hot fix for a potential vulnerability in RSAŽ Access Manager Agent when working with RSAŽ Adaptive Authentication.

ESA-2010-014: RSA, The Security Division of EMC, releases security hot fixes for potential vulnerability in RSAŽ Access Manager Server under certain conditions.
Bugtraq: ESA-2010-014: RSA, The Security Division of EMC, releases security hot fixes for potential vulnerability in RSAŽ Access Manager Server under certain conditions.

News, Infocus, Columns, Vulnerabilities, Bugtraq ...
More rss feeds from SecurityFocus

-->