IPtables:

Use the following one-line command to open the open the firewall ports:

sudo sh -c "iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT && iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT && service iptables save"

Run the following command to allow traffic on port 80:

sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

If you wish to remove the rule that was recently added,You can use below command

sudo iptables -D INPUT -p tcp --dport xxxx -j ACCEPT

If you do not wish to open port publicly, You can open the port for a Single IP.

sudo iptables -A INPUT -p tcp -s your_server_ip --dport xxxx -j ACCEPT

Once we have added the rules, We need to save the rules and make them permanent.If you are using Ubuntu You can use iptables-persistent and for Centos you use iptables save command

On Ubuntu 14.04 use the following commands to save/reload the iptables rules

sudo /etc/init.d/iptables-persistent save

sudo /etc/init.d/iptables-persistent reload

On Ubuntu 16.04 and Ubuntu 18.04 use the following commands

sudo netfilter-persistent save

sudo netfilter-persistent reload

If you are using centos,Use Below command

service iptables save

If there is an issue with your Iptables configuration rule, You can revert back the changes with the below command

iptables-restore < IPtablesbackup.txt 

Related posts

Latest posts

Leave a Comment

Leave a Reply

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