How to Open a Port in UFW Updated on March 6, 2025 by InMotion Hosting Contributor 2 Minutes, 30 Seconds to Read Uncomplicated Firewall (UFW) is a user-friendly command-line interface for managing iptables, designed to simplify firewall configuration on Linux systems. It is the default firewall management tool in Ubuntu-based distributions starting from version 8.04, including Linux Mint. UncomplicatedFirewall (UFW) helps users easily control network traffic by allowing or restricting access to specific ports. Knowing how to open a port in UFW is essential when setting up services like Apache, Webmin, or other server applications that require external access. While UFW is primarily used through the command line, desktop users who prefer a graphical interface can use GUFW, a GUI frontend for UFW. This guide will walk you through the process of opening a port in UFW, ensuring that your system remains secure while allowing necessary connections. Open a Port in UFW There are multiple ways to open a port in UFW. Below, we cover how to open ports using the port number, service name, and custom IP/port combination. Log into SSH as root. Check if the application port is defined as a service (e.g. OpenVPN, PostgreSQL, IRC): cat /etc/services | grep service-name Or cat /etc/services | grep port To navigate the full list, use Page Up, Page Down, and arrow keys after using the less command: less /etc/services If the service is listed, you can open the port using the service name (TCP/UDP protocol optional): sudo ufw allow servicename sudo ufw allow servicename/tcp If there is no service listed for the port, you can open the port by specifying the port and protocol (TCP/UDP): sudo ufw allow 10000 sudo ufw allow 1352/udp If you need to allow all connections from a specific system or network IP address: sudo ufw allow from 1.2.3.4 To allow all connections from a particular subnet of IP: sudo ufw allow from 1.2.3.0/24 To allow connections on a specific port from an IP address: sudo ufw allow from 1.2.3.4 to any port 22 After you open a port in UFW, ensure UFW is enabled: sudo ufw enable Close a Port in UFW After you uninstall software, you should close any ports you no longer need to open on your system. You can accomplish this using the service name or port number. To close a port in UFW using the service name: sudo ufw deny pop3 To close a port in UFW using the port number: sudo ufw deny 995 Check Open Ports in UFW After making changes to any firewall, you should verify your changes to ensure they’re correct and active. To check whether UFW is running: sudo ufw status To check whether UFW is running with additional information, such as logging and profile status: sudo ufw status verbose To find the rule number for UFW rules: sudo ufw status numbered Then you can remove the rule: sudo ufw delete 1 Need to install and enable Uncomplicated Firewall (UFW) on your server? Get started with our UFW Basics guide. Ready to dive deeper into web server security? Check out our guide on hardening your managed VPS or dedicated server. Share this Article InMotion Hosting Contributor Content Writer InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals! More Articles by InMotion Hosting Related Articles Content Security Policy (CSP) Headers – Complete Reference Guide Why You Need To Keep Your Website’s PHP Version Up-to-Date Learning About Mod_security and Disabling Mod_security Close Open Ports for PCI Compliance How to Pass PCI Compliance Scans DDoS Protection Using Corero How to Open a Port in Firewalld Secure Your Debian Cloud Server With UFW (Uncomplicated Firewall) How to Open a Port in UFW WP Cerber Security Antispam and Bot Detection Settings