How to Open a Port on Debian 12

Ports are the endpoints of the computer that are used to establish the connection between two different machines over a network. These ports can either be open or closed, if they are open then it means that the network traffic can be passed through it. The close status means the ports are not allowing the network traffic through them. 

These ports are used for different processes or services such that port 80 of the system is used by the Apache web server or NGINX web server. To use the ports for any particular service the port must be open. 

This blog will explain different methods to open a port on Debian 12 using the terminal with the next-mentioned outline:

  1. What are the Types of Ports on Debian Linux
  2. What are the Ways to Open a Port on Debian
  3. Method 1: Open a Port on Debian 12 Using the iptables Command
  4. Method 2: Open a Port on Debian 12 Using the ufw Command
  5. Method 3: Open a Port on Debian 12 Using the nmap Command
  6. How to List Down the Open Ports on Debian 12

Let’s start the blog by exploring the types of the Port on Debian. 

What are the Types of Ports on Debian Linux?

There are two different types of ports on Debian which are explained in the below-mentioned table. 

PortsExplanation
Transmission Control Protocol (TCP)These ports are used to establish the connection for different purposes such as services and processes 
User Datagram Protocol (UDP)These ports are used for real-time applications such as video streaming

All the ports are identified with a combination of the numbers. Ports 0 to 1023 are used by the standard system services and processes such as Apache services use the port 80. Ports 1024 to 49151 are used for dynamic processes and temporary processes use the 49152 to 65535 port. 

What are the Ways to Open a Port on Debian?

Three different methods are used to open a port on Debian 12 which are explained in the next section.

Method 1: Open a Port on Debian 12 Using the iptables Command

The first method is to open the ports on Debian 12 by using the different rules of the iptables commands. The implementation of the iptables command’s rules can be explored from the mentioned blog.

To open the port on Debian using the iptables command, follow the below-mentioned command’s general syntax:

$ sudo iptables -A INPUT -p tcp --dport 4429 --jump ACCEPT

Options used in the above iptables command are explained as:

  • A Option: It is used to append the rules to the input chain
  • p Option: It is used to specify the port number
  • dport Option: It is used to define the destination of the port
  • Jump Option: It defines the target action of the command

The above command will make a match of the TCP packets and the destination port, then pass it through the firewall. 

To verify the opening of port 4429, run the command:

$ sudo iptables-save

The output shows the rule added with the previous command’s execution to open port 4429 on Debian. 

Another command to verify the opening of the port on Debian 12 by using the iptables command:

$ sudo iptables -L

Method 2: Open a Port on Debian 12 Using the ufw Command

Another method to open a port on Debian is by using the ufw software application. It is the firewall that can be used from the terminal as well as the graphical user interface. To install it, open the mentioned post in another tab of the browser and follow the explained instructions.

To open the post, first enable the ufw by running the command:

$ sudo ufw enable

Now run the command to open the port, for instance, we will open port 80 with ufw:

$ sudo ufw allow 80

To list down the status of the ports using the ufw, use the command:

$ sudo ufw status

Method 3: Open a Port on Debian 12 Using the nmap Command

The last method to open a port on Debian is by using the nmap command which is used as a network tool. To use the nmap command for opening the port, run the below-mentioned command by replacing the port number with your specific port number:

$ sudo nmap -open -p 5431 localhost

How to List Down the Open Ports on Debian 12?

To list down the open ports on Debian, use the ss command or the netstat command as shown below:

$ sudo ss -tulpn

Conclusion

To open a port on Debian 12,  open the terminal and use the iptables command utility. Also, ufw and nmap commands can be used to open the port.

Opening a port on Debian means allowing the network traffic through that specific port. This blog explained the three different ways to open a port on Debian 12.