How to Allow ssh port in iptables


How to Allow Deny iptables inbound outbound access for ssh port on Interface IP Based MAC Based etc

IPTables Allow SSH on any Interface

Below command will enable SSH port in all the interface.
# iptables -A INPUT -p tcp –dport 22 -j ACCEPT

IPTables Allow SSH on specific IP

Run the following command in the Linux Shell

# iptables -A INPUT -d 10.5.0.1/32 -p tcp –dport 22 -j ACCEPT

Or

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 10.5.0.1/32 -p tcp -m tcp –dport 22 -j ACCEPT
-A INPUT -j DROP
COMMIT

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

IPTables Allow SSH on Specific interface

# iptables -A INPUT -i eth0 -p tcp –dport 22 -j ACCEPT

Or

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

*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