≡ Menu

How to: Allow telnet and ssh through iptables under Linux

Q. I run both RHEL / CentOS Linux server and by default firewall blocked out everything including telnet / ssh access. How do I allow telnet - port 23 and ssh port 22 thought Linux iptables firewall ?

A.By default firewall rules stored at /etc/sysconfig/iptables location / file under CentOS / RHEL. All you have to do is modify this file to add rules to open port 22 or 23.

Login as the root user.

Open /etc/sysconfig/iptables file, enter:
# vi /etc/sysconfig/iptables
Find line that read as follows:
To open port 22 (ssh), enter (before COMMIT line):

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

To open port 23 (telnet), enter (before COMMIT line):

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 23 -j ACCEPT

Save and close the file. Restart the firewall:
# /etc/init.d/iptables restart

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 5 comments… add one }

  • X-Modius November 27, 2007, 8:55 pm

    To get fancy with iptables and block repeated failed connection attempts, check out this article:


  • Shiva May 24, 2008, 7:42 am

    send me code of linux firewall in C.

  • nixCraft May 24, 2008, 3:48 pm
  • Liju June 1, 2008, 4:15 pm


    I don’t think this is not a good idea to allow telnet access nowaday.nobody is using telnet on linux box. Disable this service first

    Also it is not a good idea to allow ssh access to everyone over the net
    # Permitt SSH access to my ip and my network
    /sbin/iptables -A INPUT -s -p tcp –dport ssh -j ACCEPT
    /sbin/iptables -A INPUT -s -p tcp –dport ssh -j ACCEPT

  • V.Balaviswanathan June 18, 2009, 9:11 am

    Thanks for the info, How do I use iptables in squid to block messanger or chat tools? Could any one help me please

Leave a Comment