Guide For Setting Up A Basic iptables Configuration on CentOS for cPanel

Print Friendly, PDF & Email

This is a guide for setting up a basic iptables configuration on CentOS. You’ll want to do this as soon as you have your server setup. Most iptables configurations already have port 22 open, but you will need to add the rest.

First, you’re going to want to login to your server via ssh. You can check to see if iptables is already installed by typing:
rpm -q iptables

You should see something like:
iptables-1.3.5-5.3.el5_4.1

If for some reason you don’t have iptables installed, a simple yum command will do the trick:
yum install iptables

To start opening ports, type in the following commands – don’t include the (parenthesis):

iptables -A INPUT -p tcp –dport 21 -j ACCEPT (ftp)
iptables -A INPUT -p tcp –dport 22 -j ACCEPT (ssh)
iptables -A INPUT -p tcp –dport 80 -j ACCEPT (http)
iptables -A INPUT -p tcp –dport 143 -j ACCEPT (imap)
iptables -A INPUT -p tcp –dport 443 -j ACCEPT (https)
iptables -A INPUT -p tcp –dport 2082 -j ACCEPT (cpanel)
iptables -A INPUT -p tcp –dport 2083 -j ACCEPT (cpanel ssl)
iptables -A INPUT -p tcp –dport 2086 -j ACCEPT (whm)
iptables -A INPUT -p tcp –dport 2087 -j ACCEPT (whm ssl)

Now, you’re going to want to save your recent changes:
service iptables save 

Next, stop the service:
service iptables stop

Now, start iptables back up again, and you should be set! Make sure to verify all of the ports before logging out of your ssh session.
service iptables start

No comments yet.

Leave a Reply