Reading Time: < 1 minute
Following the tutorial on How to Open a Port in Ubuntu (Linux) by Default using IP Tables, we will learn how to close a port in Ubuntu using IP Tables.
To check if the port is open, you can use the following website: https://www.yougetsignal.com/tools/open-ports/. Enter your machine’s IP and the port you want to evaluate.
If the port is open and you want to close it, you need to run the following command:
iptables -I INPUT -p tcp --dport 80 -j REJECT
You may need to use the command with sudo.
To close any other port, replace 80 with the port number you want to close:
iptables -I INPUT -p tcp --dport PORT_NUMBER -j REJECT
Replace PORT_NUMBER with the number of the port you want to close.
Now you can check on the website https://www.yougetsignal.com/tools if the port is closed.