1. Introduction
Port opening is a necessary configuration that allows specific applications and services to be accessed from external sources. Ubuntu closes most ports by default to enhance security, but when you need to open a particular port, the tool “ufw (Uncomplicated Firewall)” makes the process simple. This article explains in detail how to open ports on Ubuntu.
2. About Ubuntu’s Firewall (ufw)
Ubuntu comes with ufw preinstalled, a tool designed to simplify firewall configuration. It allows users to control port access with a single command, making it convenient for both server administrators and desktop users. Opening ports is often required for services such as web servers and SSH connections.
3. Prerequisites
Administrator privileges are required to open ports. All commands shown in this article will be executed using sudo. Also, ensure that ufw is installed on your system. While it is usually preinstalled on Ubuntu, if it is not available, you can install it using the following command:
sudo apt-get install ufw4. Checking the Current Firewall Status
First, check the current status of the firewall. The following command displays whether ufw is enabled and which ports are currently open:
sudo ufw statusThe output shows the current rules and port configurations. Here, you can verify existing port settings.
5. How to Open Ports with ufw
To open a specific port, use the ufw allow command. For example, to open port 80 for a web server, run:
sudo ufw allow 80Similarly, to open port 22 for SSH access, execute:
sudo ufw allow 22Once executed, the specified port will be opened and accessible from external sources.

6. Reloading Firewall Settings
To apply changes, you must reload ufw. This can be done with the following command:
sudo ufw reloadRunning this command immediately applies the updated settings and activates the opened ports.
7. Managing and Deleting Rules
To view existing rules, use:
sudo ufw status verboseTo delete a specific rule—such as removing the open port 22 rule—use:
sudo ufw delete allow 22You can also delete rules by specifying their rule numbers. First, check rule numbers using:
sudo ufw status numberedThen delete the desired rule using its number:
sudo ufw delete [number]8. Testing the Configuration
To verify that a port has been opened correctly, use the following methods:
- Use the
netstatcommand to confirm port status. - Check accessibility using an online external port testing tool.
If issues arise, review your firewall rules or network configuration.
9. Security Considerations
Opening ports is essential for using certain applications and services, but it also poses security risks. Open ports accept external access, increasing exposure to unauthorized connections. Only open the ports you truly need, and ensure unnecessary ports remain closed.
10. Conclusion
This article explained how to open ports on Ubuntu using ufw. Port opening is crucial for running network applications, but it introduces security risks, so proper management is essential. Regularly review your firewall configurations and apply the latest security measures.


