Security

Open and close ports in CSF (TCP_IN, TCP_OUT, UDP_IN, UDP_OUT)

Edit the CSF port lists to open a port for a new service, close ports you do not use, and restrict a port such as SSH to trusted IPs on a cPanel/WHM server.

IntermediateWHM (root)2 min read

CSF only lets traffic through on the ports listed in its configuration. When you add a service, such as a Node.js app on a custom port or a new SSH port, you must open that port in CSF. Closing ports you do not use is just as important, because every open port is one more thing attackers can probe.

Before you start

The four port lists

SettingControls
TCP_INIncoming TCP connections to the server (web, mail, cPanel, SSH).
TCP_OUTOutgoing TCP connections from the server (updates, remote SMTP, APIs).
UDP_INIncoming UDP, such as DNS on port 53.
UDP_OUTOutgoing UDP, such as DNS lookups and NTP.

Each value is a comma-separated list. Ranges use a colon, for example 30000:35000 for passive FTP.

Open a port in WHM

  1. Go to WHM → Plugins → ConfigServer Security & Firewall.
  2. Click Firewall Configuration.
  3. Find TCP_IN and add your port to the end of the list, for example ,3000. Do not add spaces.
  4. If the service also connects out on a new port, add it to TCP_OUT.
  5. Scroll down, click Change, then Restart csf+lfd.

Open a port from SSH

  1. Edit the file:
    nano /etc/csf/csf.conf
  2. Change the line, for example:
    TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,2077,2078,2079,2080,2082,2083,2086,2087,2095,2096,3000"
  3. Reload the rules:
    csf -r

Restrict a port to trusted IPs

To keep SSH off the public internet, remove its port from TCP_IN and allow it only for your IPs in /etc/csf/csf.allow:

tcp|in|d=22|s=203.0.113.10

Run csf -r afterwards. If you change the SSH port itself, open the new port before restarting SSH, as described in change the SSH port safely.

Warning: Keep your current SSH session open while you change ports and test with a second session. If you lose access, use your provider's console and recover from a firewall lockout.

Close a port

Remove the number from the list and reload. Common candidates on a hosting server are 21 if you only use SFTP, 2082/2086/2095 if you only allow SSL logins, and 3306 if no remote MySQL client needs it.

Check afterwards

  • Confirm the service listens: ss -tlnp | grep 3000.
  • Test from outside with nc -zv your-server-ip 3000. If the port is open in CSF but unreachable, see port open but unreachable.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.