Friday, July 8, 2011

How to enable ssh port in iptables ?

Enabling source IP based access

Edit /etc/sysconfig/iptables and add the following lines

#vim /etc/sysconfig/iptables 

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1888:534373]
-A INPUT -i lo -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -d x.x.x.x/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -j DROP
COMMIT

replace x.x.x.x with your interface ip


Enabling interface based access

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1888:534373]
-A INPUT -i lo -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -j DROP
COMMIT


Restart iptables service


#service iptables restart