0

I am having CentOS 6 on my server.

When I disable the firewall via the following commands, ssh starts working fine, however when I turn the firewall back on, ssh stops.

service iptables save  
service iptables stop  
chkconfig iptables off  

Here is the list of iptable rules

[root@server1 ~]# sudo iptables -S
-P INPUT DROP
-P FORWARD DROP
-P OUTPUT ACCEPT
-N IPTABLES-UP
-A INPUT -s 127.0.0.1/32 -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -s 58.74.16.32/28 -j ACCEPT
-A INPUT -s 121.97.80.16/28 -j ACCEPT
-A INPUT -s 203.177.90.0/24 -j ACCEPT
-A INPUT -s 122.55.79.144/28 -j ACCEPT
-A INPUT -s 125.212.38.80/28 -j ACCEPT
-A INPUT -s 192.168.10.0/24 -j ACCEPT
-A INPUT -s 192.168.50.0/24 -j ACCEPT
-A INPUT -s 192.168.60.0/24 -j ACCEPT
-A INPUT -s 192.168.70.0/24 -j ACCEPT
-A INPUT -s 192.168.160.0/24 -j ACCEPT
-A INPUT -s 192.168.170.0/24 -j ACCEPT
-A INPUT -s 192.168.150.0/24 -j ACCEPT
-A INPUT -s 192.168.237.0/24 -j ACCEPT
-A INPUT -s 192.168.235.0/24 -j ACCEPT
-A INPUT -s 192.168.228.0/22 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 25 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 26 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 26 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 587 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 587 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 465 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 465 -j ACCEPT
-A INPUT -p udp -m udp --sport 53 -j ACCEPT
-A INPUT -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -p udp -m udp --sport 123 -j ACCEPT
-A INPUT -p udp -m udp --dport 123 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -j DROP
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A FORWARD -p icmp -j ACCEPT
-A FORWARD -s 192.168.0.0/16 -d 192.168.0.0/16 -j ACCEPT
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -j DROP
-A OUTPUT -d 127.0.0.1/32 -j ACCEPT
-A OUTPUT -p icmp -j ACCEPT
-A OUTPUT -j ACCEPT

The port of SSH is also not changed.

Can you help me out why I am not able to connect via ssh?

3
  • 2
    Please, don't post images of text.
    – Kusalananda
    Jan 29, 2017 at 20:52
  • I am connected via Serial Console, I can't copy the text :(
    – prateek569
    Jan 29, 2017 at 20:53
  • I have transcribed the contents of your screenshot for you, but you may want to check for errors in transcription.
    – Fox
    May 6, 2017 at 19:45

1 Answer 1

3

According to what I read on your screenshot you have several iptables rules and the last one drop all the rest

iptables -A input -j DROP

Before droping the rest of the request you should add a rule to allow ssh into your server

iptables -A input -p 22 -j ACCEPT 
1
  • Expanding on this answer with more explanation, rather than just a command, would improve it. Jan 29, 2017 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.