In IP chains, the input chain applies to all datagrams received by the host, irrespective of whether they are destined for the local host or routed to some other host. In
Figure 9.8: Datagram processing chain in IP chains
In Figure 9.8, the components labeled 'demasq' and 'masq' are separate kernel components responsible for the incoming and outgoing processing of masqueraded datagrams. These have been reimplemented as
Consider the case of a configuration for which the default policy for each of the input, forward, and output chains is deny. In IP chains, six rules would be needed to allow any session through a firewall host: two each in the input, forward, and output chains (one would cover each forward path and one would cover each return path). You can imagine how this could easily become extremely complex and difficult to manage when you want to mix sessions that could be routed and sessions that could connect to the local host without being routed. IP chains allow you to create chains that would simplify this task a little, but the design isn't obvious and requires a certain level of expertise.
In the
Figure 9.9: Datagram processing chain in netfilter
The PACKET-FILTERING-HOWTO offers a detailed list of the changes that have been made, so let's focus on the more practical aspects here.
Backward Compatability with ipfwadm and ipchains
The remarkable flexibility of Linux
The two
rmmod ip_tables
modprobe ipchains
ipchains
Using iptables
The iptables utility is used to configure
Before you can use the iptables command, you must load the
modprobe ip_tables
The iptables command is used to configure both IP filtering and Network Address Translation. To facilitate this, there are two tables of rules called
The general syntax of most iptables commands is:
iptables
Now we'll take a look at some options in detail, after which we'll review some examples.
Commands
There are a number of ways we can manipulate rules and rulesets with the iptables command. Those relevant to IP firewalling are:
- A chain
Append one or more rules to the end of the nominated chain. If a hostname is supplied as either a source or destination and it resolves to more than one IP address, a rule will be added for each address.
- I chain rulenum
Insert one or more rules to the start of the nominated chain. Again, if a hostname is supplied in the rule specification, a rule will be added for each of the addresses to which it resolves.
- D chain
Delete one or more rules from the specified chain matching the rule specification.
- D chain rulenum
Delete the rule residing at position
- R chain rulenum
Replace the rule residing at position
- C chain
Check the datagram described by the rule specification against the specific chain. This command will return a message describing how the chain processed the datagram. This is very useful for testing your firewall configuration and we will look at it in detail later.
- L [chain]
List the rules of the specified chain, or for all chains if no chain is specified.
- F [chain]
Flush the rules of the specified chain, or for all chains if no chain is specified.
