Iptables (Italiano)

From ArchWiki
Revision as of 10:18, 1 October 2011 by Maveloth (talk | contribs) (targets: translated)
Jump to: navigation, search

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Iptables (Italiano)#)

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Tango-preferences-desktop-locale.pngThis article or section needs to be translated.Tango-preferences-desktop-locale.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Iptables (Italiano)#)

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end

iptable è un potente firewall integrato nel kernel Linux ed è una parte del progetto netfilter. Può essere configurato direttamente, oppure usando uno dei vari frontends oppure una delle GUI. Template:Codeline è utilizzato per gli ipv4 mentre Template:Codeline è usato per gli ipv6.


Nota: Il proprio kernel dovrà essere compilato con il supporto per iptables. Tutti i kernel stock di Arch Linux hanno il supporto per iptables.

Per prima cosa, installare il pacchetto Template:Package Official:

# pacman -S iptables

Successivamente, aggiungere Template:Codeline all'array DAEMONS nel file Template:Filename per far caricare le impostazioni personalizzate durante il boot:


Concetti di base


iptables contiene quattro tabelle: Template:Codeline e Template:Codeline.


Le catene sono utilizzate per idicare una serie di regole. Un pacchetto viene comparato dall'inizio della catena fino a che non soddisfa una regola. Ci sono tre catene principali: Template:Codeline e Template:Codeline. Tutti i pacchetti generati dal sistema ed in uscita, passano attraverso la catena Template:Codeline, tutti i pacchetti in entrata e destinati al sistema stesso passano attraverso la catena Template:Codeline, mentre i pacchetti che transitano per il sistema ma sono destinati ad altri sistemi passano dalla catena Template:Codeline. Queste catene hanno destinazioni di default nel caso nessuna regola venga soddisfatta. Catene personalizzate dagli utenti possono essere aggiunte per aumentare l'efficenza delle regole.


Una destinazione è il risultato che si ottiene quando un pacchetto soddisfa una regola. Le destinazioni sono specificate mediante l'uso di Template:Codeline (Template:Codeline). Le destinazioni più comuni sono Template:Codeline oppure Template:Codeline.


There are many modules which can be used to extend iptables such as connlimit, conntrack, limit and recent. These modules add extra functionality to allow complex filtering rules.


From the command line

You can check the current ruleset and the number of hits per rule by using the command:

# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination   
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination    
Chain OUTPUT (policy ACCEPT 0K packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

If the output looks like the above, then there are no rules.

You can flush and reset iptables to default using these commands:

# iptables -P INPUT ACCEPT
# iptables -P FORWARD ACCEPT
# iptables -P OUTPUT ACCEPT
# iptables -F
# iptables -X

Configuration file

The configuration file at Template:Filename points to the location of the configuration file. The ruleset is loaded when the daemon is started.


IPTABLES_FORWARD=0  # enable IP forwarding?

To save the current ruleset, use this command:

# /etc/rc.d/iptables save

To load the ruleset, use this command:

# /etc/rc.d/iptables restart

Saving counters

You can also, optionally, save byte and packet counters. To accomplish this, edit Template:Filename

In the save) section, change the line:

/usr/sbin/iptables-save > $IPTABLES_CONF


/usr/sbin/iptables-save -c > $IPTABLES_CONF

In the stop) section, add the following to save before stopping:

     $0 save
     sleep 2

In the start) section, change the line:

/usr/sbin/iptables-restore < $IPTABLES_CONF


/usr/sbin/iptables-restore -c < $IPTABLES_CONF

and save the file



The LOG target can be used to log packets that hit a rule. Unlike other targets like ACCEPT or DROP, the packet will continue moving through the chain after hitting a LOG target. This means that in order to enable logging for all dropped packets, you would have to add a duplicate LOG rule before each DROP rule. Since this reduces efficiency and makes things less simple, a LOGDROP chain can be created instead.

## /etc/iptables/iptables.rules


... other user defined chains ..

## LOGDROP chain
:LOGDROP - [0:0]

-A LOGDROP -m limit --limit 5/m --limit-burst 10 -j LOG

... rules ...

## log AND drop packets that hit this rule:
-A INPUT -m state --state INVALID -j LOGDROP

... more rules ...

Limiting log rate

The limit module should be used to prevent your iptables log from growing too large or causing needless hard drive writes. Without limiting, an attacker could fill your drive (or at least your Template:Filename partition) by causing writes to the iptables log.

-m limit is used to call on the limit module. You can then use --limit to set an average rate and --limit-burst to set an initial burst rate. Example:

-A LOGDROP -m limit --limit 5/m --limit-burst 10 -j LOG

This appends a rule to the LOGDROP chain which will log all packets that pass through it. The first 10 packets will the be logged, and from then on only 5 packets per minute will be logged. The "limit burst" is restored by one every time the "limit rate" is not broken.


Assuming you are using syslog-ng which is the default in Archlinux, you can control where iptables' log output goes this way:

filter f_everything { level(debug..emerg) and not facility(auth, authpriv); };


filter f_everything { level(debug..emerg) and not facility(auth, authpriv) and not filter(f_iptables); };

This will stop logging iptables output to Template:Filename.

If you also want iptables to log to a different file than Template:Filename, you can simply change the file value of destination d_iptables here (still in Template:Filename)

destination d_iptables { file("/var/log/iptables.log"); };


ulogd is a specialized userspace packet logging daemon for netfilter that can replace the default LOG target. An AUR package can be found here.

Ulteriori risorse