Home / VPS & Dedicated / How to open and close ports with iptables

How to open and close ports with iptables

Fixing a cable
Question: How do I open and close ports with an iptables firewall setup?

Answer: You can easily open ports on a dedicated server with these simply commands. Depending on whether you need to open a UDP or TCP port, use one or both of the following:

iptables -A INUPT -p tcp –dport -j ACCEPT
iptables -A INUPT -p udp –dport -j ACCEPT

And to close a port, enter:

iptables -A INUPT -p tcp –dport -j DROP
iptables -A INUPT -p udp –dport -j DROP

Then, save and restart iptables:

service iptables save
service iptables restart

You can keep track of which ports have been opened and closed by viewing the /var/log/messages file.

Photo: Flickr

Check Also

servers

Importance of web hosting to business

The world of business is very ruthless and unfair in some cases. It is a …

Powered by Namesco
© Copyright InternetBlog.Org.Uk 2024, All Rights Reserved