Lets learn "About linux iptables"

 



Security is an important part of any system. In Linux systems, the firewall rules are responsible for providing security to the system. To configure the firewall rules in Linux, IPTables utility is used. Linux IPTables is a user-space program that helps to configure kernel rules to filter network packets and defining the NAT rules. In this tutorial, we'll learn in detail about different tables and chains in IPTables.                 

The high-level structure of IPTables

IPTables consist of in-built tables and those in-built tables contain different chains that can be in-built or user-defined and in each chain different rules are defined.
So the structure is IPTables -> In-built Tables -> Chains -> Rules


Now that we've learned about the high-level structure of iptables, let's dive into different in-build tables and its chains.

IPTables in-built tables and their built-in Chains

Basically, IPTables has 4 in-built tables

Filter Table

As the name suggests, Filter table is mainly used for filtering network packets. It is the most widely used IPTables table. In the iptable command, if you do not specify any table by default Filter table gets used. Filter table has the following in-built chains.
  • INPUT Chain: This chain is used for any packet coming to the system. 
  • OUTPUT Chain: This chain is used for any packet going out from the system.
  • FORWARD Chain: This chain is used for any packet routed through the system.

NAT Table

NAT means Network Address Translation. So NAT table is used for network address translation related rules. NAT Table has three in-built chains.
  • PREROUTING Chain: This chain modifies the packet before routing. This chain basically performs DNAT ( Destination NAT which means modifying the destination IP of the packet ). When a packet enters the system just before deciding if routing this required or not, this chain is used.
  • POSTROUTING Chain: This chain modifies the packet post routing. This chain basically performs SNAT ( Source NAT which means modifying the source IP of the packet ). In this case, translation happens just before packet leaves the system.
  • OUTPUT Chain: This chain is used for NAT for locally generated packets.

Mangle Table

Mangle table is used for packet alteration in various ways. This table can make changes to different header fields in the packet. For e.g, if you wanna change MTU, TTL in the packet header. you can use this table. Mangle table has the following in-built chains. 
  • PREROUTING Chain.
  • OUTPUT Chain.
  • FORWARD Chain.
  • INPUT Chain.
  • POSTROUTING Chain.

Raw Table

IPTables are a stateful firewall which means packets are inspected with respect to their state like a packet can be a part of new connection or existing connection. Raw table is used for packet alteration before the kernel starts tracking its state. Raw table has the following in-built chains.
  • PREROUTING Chain.
  • OUTPUT Chain.

Summarizing all tables in one diagram.

HOPE you like this tutorial. Please put down the comment below if you have any doubt. Linux IPTables rule structure is explained here. Stay tuned for more tutorials :)


Comments

Popular posts from this blog

Lets learn "About kube proxy in iptables mode"

Lets learn "System design for paste bin (or any text sharing website)"

Lets learn "Factory design pattern"