Categories: Hostripples Featured

Introduction and basic usages of iptables under Unix/Linux

* What is iptables in Linux ? 

Iptables is a rule based firewall system and is normally pre-installed on a Unix operating system which is controlling the incoming and outgoing packets.

Basic structure of iptables

The structure for the iptables is like, Tables which has chains and the chains which contains rules.
Tables —> Chains —> Rules. The rules are defined to control the packets for Input/Output.

List of different Tables in iptables structure.

1. Filter Table
It is the default table in iptables. There are no need to specify the table name for defining the Rules. Different inbuilt chains in this table;
1.1 INPUT Chain
INPUT Chain is for managing packets input to the server. Here we can add Rules to control INPUT connections from remote to the server.

1.2 FORWARD Chain
To add Rules to manage packet connections from one network interface(NIC) to another on the same machine.

1.3 OUTPUT Chain
The OUTPUT Chain control packets from the server to outside. Here we can add different rules to manage outbound connection from the server.

* How/command to list all rules from the Filter table of iptables ?

Syntax:

iptables -t filter --list
or
iptables -t filter -L

Or simply;

iptables --list
or
iptables -L

Sample output:

root@test [~]# iptables -t filter --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
acctboth   all  --  anywhere             anywhere

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

2. NAT table
Network address translation (NAT) is a methodology of modifying network address information in Internet Protocol (IP) datagram packet headers while they are in transit across a traffic routing device for the purpose of remapping one IP address space into another. The default inbuilt chains for NAT tables are;
2.1 PREROUTING chain
As the name indicates its translate packets before routing.
2.2 POSTROUTING chain
Translate packets after routing completes.
2.3 OUTPUT chain

* How/command to list all rules from the NAT table of iptables ?

Syntax:

iptables -t nat --list
or
iptables -t nat -L

Example:

root@test [~]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

3. Mangle table
This table is used for packet alternation. Different inbuilt chains are;
3.1 PREROUTING chain
3.2 OUTPUT chain
3.3 FORWARD chain
3.4 INPUT chain
3.5 POSTROUTING chain

* How/command to list all rules from the Mangle table of iptables ?

Syntax:

iptables -t mangle --list
or
iptables -t mangle -L

Example:

root@test [~]# iptables -t mangle --list
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

That’s it.


Vishwajit Kale
Vishwajit Kale blazed onto the digital marketing scene back in 2015 and is the digital marketing strategist of Hostripples, a company that aims to provide affordable web hosting solutions. Vishwajit is experienced in digital and content marketing along with SEO. He's fond of writing technology blogs, traveling and reading.

Recent Posts

Meet Sora: The Game-Changing AI Video Model from ChatGPT

The world of artificial intelligence is evolving faster than ever — and one of the biggest breakthroughs is here. Sora,…

5 days ago

How to Design a Website for Black Friday 2025 (Complete Guide)

Black Friday 2025 is here — the biggest shopping moment of the year, where customers expect unbeatable prices, fast performance,…

3 weeks ago

301 Redirects for WordPress: What, Why & How (SEO Best Practices)

When you move or delete a page on your WordPress website, visitors — and search engines — can easily hit…

3 weeks ago

Meet Perplexity: AI That Thinks Like a Researcher

Introduction Artificial Intelligence has made remarkable strides — from writing poetry to generating code. Yet, most AIs still act like…

1 month ago

Top 15 AI Text Writers in 2025 — Features, Uses, Pros & Cons Explained

Introduction Artificial Intelligence has revolutionized the way we create, refine, and scale written content — from blogs and marketing campaigns…

1 month ago