Configure firewall in Linux – IPTABLES

What is Iptables

IPTABLES is firewall built into Linux OS. Before starting configuring IPTABLE rules it is important that you understand if rules are configured wrongly your network service may get blocked.

Syntax for configuring iptables service

iptables [options] [chain] -j [target]

Options:

-A Appends new rule to the chain

-D Deletes an existing rule from the chain

-I insert a rule into the chain

-L Lists all rules

-X Delete Rules created by user can be deleted

-p protocol uses the protocol specified

-s address Defines address of source

-d address Defines address of destination

Chains:

INPUT Rules are applied to packets coming into the system

OUTPUT Rules are applied to packets going out of the system

FORWARD Incoming packets that are routed through the system

Targets:

ACCEPT – Add Rule allowing the packets through firewall

DROP – Add Rule blocking packets through firewall. It drops the packets and gives no response

REJECT – Add Rule Rejecting the packets reaching system and sends a rejected response

Check your firewall configuration

To check your existing firewall configuration enter below command
chkconfig iptables –list

Save new rules

Once you are through with firewall rules creation you have to save them with command

service iptables save

Service iptables restart

Once you have saved your firewall rules restart your iptables service

service iptables restart

Only after restart of services your changes will be effective.