Installing and configuring iptables firewall on CentOs 7

First install iptables with this command

Now start iptables

Use the below command to flush any existing rules that might be there

Now add rules one by one by executing the following commands

Block null packets

Reject is a syn-flood attack

XMAS packets

Allow localhost traffic

Allow http port 80

Allow https port 443

Allow SMTP

Allow POP3

Allow IMAP

Allow SSH

Caution: You could potentially loose ssh access to your server if you are not careful with this. If you have changed the SSH port number and are not using the default port 22 to login then replace 22 with the appropriate port number.

Allow established outgoing connections to receive incoming replies.

Now allow all outgoing connections and block all the incoming connections except the ones we have explicitly allowed in the above rules.
Now save the firewall rules
or
Enable
Now restart iptables
or
Useful command:
List iptables firewall rules
Previous Post
How to change SSH port on CentOs 7 VPS
Next Post
Installing and configuring fail2ban on CentOs 7

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Menu