Iptables firewall rule chains configuration guide on linux with examples for beginners
In this
article we learn how to create iptables rules on linux operating system, how to
listing configured iptables rules and how to flush all listing rules of
iptables. By default iptables is
preinstalled for all linux distribution. If iptables is absent we execute the
following command .
#yum
install iptables
Iptables firewall rule chains configuration guide on linux with examples for beginners
What
is iptables
Iptables is
the command line firewall utility for linux operating system. We can create the
chain rule on firewall based on the rule when system try to establish
connection it checks the list of the
rules if the rule does not found it takes the default action. Basically iptables uses to allow or block the
traffic based on the iptables chain rules .
Action For the iptables
Three types
of actions can be performed on linux by setting the iptables.
- Accept: Allow the traffic
- Drop: Drop the traffic
- Reject: Don’t allow the traffic.
Types of chains in iptables
Three types
of chains are available for iptables rules .
- Input: Input chain uses for the incoming connection.
- Forward: Forward chain uses to forward the traffic .
- Output: Output chain uses for the outgoing connection.
Allow/deny the traffic configuration on iptables
Suppose we
have source ipaddress that is 192.168.1.2 and network is 192.168.1.0/24.We want
to drop traffic from source ipaddress that is 192.168.1.2.To do this activity
we execute the below command.
#iptables
-A
INPUT –s 192.168.1.2 –j DROP
Now we want
to drop the traffic the whole source network we con execute the below command.
#iptables
-A
INPUT –s 192.168.1.0/24 –j DROP
Allow/deny the traffic for the particular port configuration on iptables
Now we are
going to allow the ssh port for the source ipaddress 192.168.1.2.To do this we
mention the protocol that is tcp and the port no or port name by executing the
below commad.
#iptables
-A
INPUT –p tcp –s 192.168.1.2
--dport 22 –j ACCEPT
On iptables at the booting time
To start
the iptables after the booting automatically we execute the below command.
#chkconfig
iptables on
Start/Save/listing the iptables rules
To start
iptables we execute the below command .
#service
iptables start
After
configured the iptables rule we need to save the iptables configuration to do
this we execute the follwing command.
#/etc/init.d/iptables
save
To listing
the iptables rule we execute the below command.
#iptables
–L
To get the
packet and byte information we use “-v” switch and to get all information
numerically we use “-n” switch and to flush all information we use “-F” switch.
Conclusion
You
can get many switch function of the iptables command. To know all switches
function go to the man page of the iptables command using “man iptables”.
Nice post. Keep updating Devops Online Training
ReplyDelete