How to Open Port in Linux

What is Port?

Port numbers are associated with TCP/IP network connections. A port number is a way to identify a specific process to which an Internet or other network message is to be forwarded when it arrives at a server. They allow different applications on the same computer to share network resources simultaneously. Home network routers and computer software work with these ports and sometimes support configuring port number settings.

How Does Port Numbers Work?

Port numbers relate to network addressing. In TCP/IP networking, both TCP and UDP utilize their own set of ports that work together with IP addresses.

In both TCP and UDP, port numbers start at 0 and go up to 65535. Numbers in the lower ranges are dedicated to common Internet protocols (like port 80 for HTTP and port 443 for HTTPS).

To open a port in Linux Firewall

This article will be showing you how to open ports in your Linux Web Hosting India servers firewall. This can be very useful, and also dangerous, so be sure you know what port you want to open up. Hackers can use these open ports to gain unauthorized access to your Linux server, so be careful!

Login SSH into your server as Root

SSH_1.png

Get to the directory where the configuration file is for CSF
cd /etc/csf

Press (Enter)

This is where CSF keeps all of its files, not just the configuration file.

SSH_2.png
Open the configuration file so that we can edit it. Something like "Vim" editor vim csf.conf

Find TCP_IN Line on the file csf.conf

SSH_3.png

Once you have the file open, you will see a "TCP_IN" and "TCP_OUT" section. It will look like this:

Allow incoming TCP ports

TCP_IN = "20,21,1122, 25, 26, 53, 80, 110, 143, 443, 465, 587, 993, 995, 2077, 2078, 2082, 2083, 2086, 2087, 2095, 2096, 8010"

SSH_4.png

Allow incoming TCP ports

TCP_IN = "20,21,1122, 25, 26, 53, 80, 110, 143, 443, 465, 587, 993, 995, 2077, 2078, 2082, 2083, 2086, 2087, 2095, 2096, 8010"

SSH_5.png

All those numbers there are ports that are currently "open". Yours may look different so don't panic! It all depends on your configuration.

SSH_6.png

Save and get out of this file (:wq!) Restart the firewall so that your changes take effect! csf -r

SSH_7.png Stopping CSF csf -x