IPTABLES BASIC IN RedHat Enterprise Linux

IPTABLES BASIC IN RedHat Enterprise Linux

IPTABLES is the software firewall in Linux operating system. This post covers the basics of linux software firewall IPTABLES.

Types Of Firewall:

1. Hardware Firewall
2. Software FirewallHardware Firewall:
A Dedicated Device used to Allow/Deny specific Port/network.
Eg:- SonicWall,SmartWall …, List of Alphabetical Hardware FireWall’s
Software Firewall:
Used In OS Level which can be implemented in a small Organization. Same used for block/allow port/Network.
Eg :- Windows Firewall (ipsec) Default in windows, Linux (IPTABLES), Ipchains (Redhat 8).
BASIC SYNTAX FOR IPTABLES:
# iptables  –t  <tablename>  <action> <chain> <options>  -j  <target>
TABLE NAME:
Filter
Nat
Mangle
ACTION:
-A  – Append a rule
-P  – To set default policy
-D  – To delete a rule
-R  – To replace a rule
-F  – To flush all the rule
-L  – To list all the rule
-I   – To insert rule
-N – To print the line number
CHAINS:
Input
Output
Forward
PreRouting
PostRouting
OPTIONS OR MATCHING CRITERIA:
-s  ?  source ip/netmask
-d  ? destination ip/netmask
–sport          ? source port
–dport ? destination port
-p  ? protocol (tcp, udp, icmp, etc..)
-I  ? input interface (eth0,—-)
-o  ? output interface (eth0,—)
TARGET:
Accept
Drop
Reject
Snat
Dnat
Log
Masquerade
Configuration file for IPTABLES:
The Configuration file for IPTABLES is located under /etc.
1. /etc/sysconfig/iptables-config
The IPTABLES Rules are stored in :
1. /etc/sysconfig/iptables
Services used in IPTABLES:
1.service iptables restart
2.service iptables save
3.service iptables start
4.service iptables status

 

How To Enable IP-Forwarding in Rhel:

1. Open /etc/sysctl.conf
2. Go to Line No = 7
3. Change net.ipv4.ip_forward = 0 to net.ipv4.ip_forward = 1
4. Save and Exit
5. Type sysctl -p  to check the ip forwarding.

To List Iptables:
1. iptables -L (Capital “L”)
To Flush Iptables :
1.iptables -F (Capital “F”)
In the above Diagram you can see that iptable rule is flushed. as previous some rule is added.
once u flushed the rule there is no rule in the iptables as u can see in the above Example.
Example 1:
How to disable Ping Request using IPTABLES.
Command:
# iptables -t filter -A INPUT -p icmp -j REJECT
As you can see after applying the iptable rule we cannot able to ping that specific server from command prompt.
NOTE : 
Like the above example we can allow/Deny specific port like ssh,FTP,Telnet etc….,
Example 2:
1.How to block a specific ipaddress to communicate
Command:
# iptables -t filter -A INPUT -s 192.168.0.0/24 -j REJECT
Using the above command we can able to reject the whole 192 sub-net .
NOTE:
using the same example we can Allow/Deny a specific network or whole network.
Example 3:
1. How to block the Specific Port number.
Command:
# iptables -t filter -A INPUT -p tcp –sport 20 -j REJECT   (Rejecting FTP Port)
In the above example the FTP port is Rejected, That’s why we are not able to connect telnet Via 20 port number.
NOTE:
Using the Same above Example we can able to Allow/Deny other Ports Like ssh(22),DNS(53)…,
To Save the IPTABLE Rule to a File:
#iptables-save > /filename.iptables
To Restore the IPTABLE Rule From file:
#iptables-restore < /filename.iptables



Leave a Reply

Your email address will not be published. Required fields are marked *