A Tutorial for Controlling Network Traffic with iptables
Source: Akamai
iptables is an application that allows users to configure specific rules that will be enforced by the kernel’s netfilter framework. It acts as a packet filter and firewall that examines and directs traffic based on port, protocol and other criteria. This guide will focus on the configuration and application of iptables rulesets and will provide examples of ways they are commonly used.
By default, the iptables tool is included with your Linode-supplied distribution. In order to use iptables, you will need root (sudo) privileges.
Use Linux iptables to Manage IPv4 Traffic
The iptables Command
Many options can be used with the iptables command. As stated above, iptables sets the rules that control network traffic. You can define different tables to handle these rules through chains, lists of rules that match a subset of packets. The table contains a variety of built-in chains, but you can add your own.
Basic iptables Parameters and Syntax
Before we begin creating rules, let’s review the syntax of an iptables rule.
For example, the following command adds a rule to the beginning of the chain that will drop all packets from the address 198.51.100.0:
iptables -I INPUT -s 198.51.100.0 -j DROP
The sample command above:
- Calls the
iptablesprogram - Uses the
-Ioption for insertion. Using a rule with the insertion option will add it to the beginning of a chain and will be applied first. To indicate a specific placement in the chain, you may also use a number with the-Ioption. - The
-sparameter, along with the IP address (198.51.100.0), indicates the source. - Finally, the
-jparameter stands for jump. It specifies the target of the rule and what action will be performed if the packet is a match.
| Parameter | Description |
|---|---|
-p, --protocol |
The protocol, such as TCP, UDP, etc. |
-s, --source |
Can be an address, network name, hostname, etc. |
-d, --destination |
An address, hostname, network name, etc. |
-j, --jump |
Specifies the target of the rule; i.e. what to do if the packet matches. |
-g, --goto chain |
Specifies that the processing will continue in a user-specified chain. |
-i, --in-interface |
Names the interface from where packets are received. |
-o, --out-interface |
Name of the interface by which a packet is being sent. |
-f, --fragment |
The rule will only be applied to the second and subsequent fragments of fragmented packets. |
-c, --set-counters |
Enables the admin to initialize the packet and byte counters of a rule. |


If you have customized iptables rules, and would like to load the customized iptables rules persistently across reboots on Debian, you can leverage
Ce guide va vous apprendre à sécuriser un serveur et donc vous initier aux thématiques de la sécurité informatique. En quoi est-ce important ? Par définition, un serveur est ouvert sur le monde, un minimum de sécurité est donc intéressant afin de se prémunir des attaques les plus simplistes.