How to Close and Open Ports with iptables

Linux dedicated servers typically rely a software firewall system called iptables. With it you can control which ports allow inbound and/or outbound access. It is very important to have iptables configured properly, both for your server’s functionality and for its security.
There are many tools, both command-line based and web-based that allow you to control and configure iptables. In some cases, particularly emergency situations, you may still prefer or need to use the command line. In such situations, here is an easy guide to follow.
As an example, let’s suppose you want to open the TCP port 25 for your SMTP server.
1. Login to your server via SSH
2. Become root: