Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Iptables
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Overview== iptables allows the [[system administrator]] to define ''tables'' containing ''chains'' of ''rules'' for the treatment of packets. Each table is associated with a [[Netfilter#iptables|different kind of packet processing]]. Packets are processed by sequentially traversing the rules in chains. A rule in a chain can cause a goto or jump to another chain, and this can be repeated to whatever level of nesting is desired. (A jump is like a βcallβ, i.e. the point that was jumped from is remembered.) Every network packet arriving at or leaving from the computer traverses at least one chain. [[Image:Netfilter-packet-flow.svg|350px|thumb|Packet flow paths. Packets start at a given box and will flow along a certain path, depending on the circumstances.]] The origin of the packet determines which chain it traverses initially. There are five ''predefined chains'' (mapping to the five available Netfilter hooks), though a table may not have all chains. Predefined chains have a ''policy'', for example DROP, which is applied to the packet if it reaches the end of the chain. The system administrator can create as many other chains as desired. These chains have no policy; if a packet reaches the end of the chain it is returned to the chain which called it. A chain may be empty. * <code>PREROUTING</code>: Packets will enter this chain before a routing decision is made. * <code>INPUT</code>: Packet is going to be locally delivered. It does not have anything to do with processes having an opened socket; local delivery is controlled by the "local-delivery" routing table: <code>ip route show table local</code>. * <code>FORWARD</code>: All packets that have been routed and were not for local delivery will traverse this chain. * <code>OUTPUT</code>: Packets sent from the machine itself will be visiting this chain. * <code>POSTROUTING</code>: Routing decision has been made. Packets enter this chain just before handing them off to the hardware. A chain does not exist by itself; it belongs to a ''table''. There are three tables: ''nat'', ''filter'', and ''mangle''. Unless preceded by the option ''-t'', an <code>iptables</code> command concerns the ''filter'' table by default. For example, the command <code>iptables -L -v -n</code>, which shows some chains and their rules, is equivalent to <code>iptables -t filter -L -v -n</code>. To show chains of table ''nat'', use the command <code>iptables -t nat -L -v -n</code> Each rule in a chain contains the specification of which packets it matches. It may also contain a ''target'' (used for extensions) or ''verdict'' (one of the built-in decisions). As a packet traverses a chain, each rule in turn is examined. If a rule does not match the packet, the packet is passed to the next rule. If a rule does match the packet, the rule takes the action indicated by the target/verdict, which may result in the packet being allowed to continue along the chain or may not. Matches make up the large part of rulesets, as they contain the conditions packets are tested for. These can happen for about any layer in the [[w:OSI_model|OSI]] model, as with e.g. the <code>--mac-source</code> and <code>-p tcp --dport</code> parameters, and there are also protocol-independent matches, such as <code>-m time</code>. The packet continues to traverse the chain until either # a rule matches the packet and decides the ultimate fate of the packet, for example by calling one of the <code>ACCEPT</code> or <code>DROP</code>, or a module returning such an ultimate fate; or # a rule calls the <code>RETURN</code> verdict, in which case processing returns to the calling chain; or # the end of the chain is reached; traversal either continues in the parent chain (as if <code>RETURN</code> was used), or the base chain policy, which is an ultimate fate, is used. Targets also return a verdict like <code>ACCEPT</code> (<code>NAT</code> modules will do this) or <code>DROP</code> (e.g. the <code>REJECT</code> module), but may also imply <code>CONTINUE</code> (e.g. the <code>LOG</code> module; <code>CONTINUE</code> is an internal name) to continue with the next rule as if no target/verdict was specified at all.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)