{"id":567,"date":"2024-09-06T12:08:34","date_gmt":"2024-09-06T12:08:34","guid":{"rendered":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/?p=567"},"modified":"2024-09-06T12:09:42","modified_gmt":"2024-09-06T12:09:42","slug":"open-a-port-in-ubuntu","status":"publish","type":"post","link":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/open-a-port-in-ubuntu\/","title":{"rendered":"How to Open a Port in Ubuntu using UFW"},"content":{"rendered":"<p>Open a Port in Ubuntu using UFW UncomplicatedFirewall (UFW) is a command-line, frontend iptables manager, similar to Firewalld and <a href=\"https:\/\/configserver.com\/configserver-security-and-firewall\/\" target=\"_blank\" rel=\"noopener\">ConfigServer Security &amp; Firewall<\/a> (CSF). It\u2019s beneficial to understand basic UFW commands since it\u2019s pre-installed with many Ubuntu-based operating systems (OSs) including Mint.<\/p>\n<p>Those configuring UFW for a desktop system who prefer not to use the CLI can use the GUFW GUI application.<\/p>\n<p>if you\u2019re installing new server management software such as Apache or Webmin, you\u2019ll need to ensure the appropriate ports are open.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-576 size-full\" src=\"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-content\/uploads\/2024\/09\/ufw.png\" alt=\"Open a Port in Ubuntu\" width=\"631\" height=\"354\" srcset=\"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-content\/uploads\/2024\/09\/ufw.png 631w, https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-content\/uploads\/2024\/09\/ufw-300x168.png 300w\" sizes=\"auto, (max-width: 631px) 100vw, 631px\" \/><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/open-a-port-in-ubuntu\/#Open_a_Port_in_Ubuntu_using_UFW\" >Open a Port in Ubuntu using UFW<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/open-a-port-in-ubuntu\/#Close_a_Port_in_UFW\" >Close a Port in UFW<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/open-a-port-in-ubuntu\/#Check_Open_Ports_in_UFW\" >Check Open Ports in UFW<\/a><\/li><\/ul><\/nav><\/div>\n<h2 id=\"open\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Open_a_Port_in_Ubuntu_using_UFW\"><\/span>Open a Port in Ubuntu using UFW<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>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.<\/p>\n<ul>\n<li>Log into SSH as root.<\/li>\n<li>Check if the application port is defined as a service (e.g. MySQL, OpenVPN, PostgreSQL, ):<\/li>\n<\/ul>\n<pre>cat \/etc\/services | grep service-name<\/pre>\n<p>or<\/p>\n<pre>cat \/etc\/services | grep port<\/pre>\n<p>To navigate the full list, use <kbd>Page Up<\/kbd>, <kbd>Page Down<\/kbd>, and arrow keys after using the <code>less<\/code> command:<\/p>\n<pre>less \/etc\/services<\/pre>\n<p>If the service is listed, you can open the port using the service name (TCP\/UDP protocol optional):<\/p>\n<pre>sudo ufw allow servicename<\/pre>\n<pre>sudo ufw allow servicename\/tcp<\/pre>\n<p>If there is no service listed for the port, you can open the port by specifying the port and protocol (TCP\/UDP):<\/p>\n<pre>sudo ufw allow 8000<\/pre>\n<pre>sudo ufw allow 1652\/udp<\/pre>\n<p>If you need to allow all connections from a specific system or network IP address:<\/p>\n<pre>sudo ufw allow from 10x.14x.11.12x<\/pre>\n<p>To allow all connections from a specific IP subnet:<\/p>\n<pre>sudo ufw allow from 10x.14x.11.12x\/24<\/pre>\n<p>To allow connections on a specific port from an IP address:<\/p>\n<pre>sudo ufw allow from 10x.14x.11.12x to any port 22xx<\/pre>\n<p>After you open a port in UFW, ensure UFW is enabled:<\/p>\n<pre>sudo ufw enable<\/pre>\n<h3 id=\"close\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Close_a_Port_in_UFW\"><\/span>Close a Port in UFW<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>After you uninstall software you should close any ports you no longer need open on your system. You can accomplish this using the service name or port number.<\/p>\n<p>To close a port in UFW using the service name:<\/p>\n<pre>sudo ufw deny pop3<\/pre>\n<p>To close a port in UFW using the port number:<\/p>\n<pre>sudo ufw deny 110<\/pre>\n<h2 id=\"check\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_Open_Ports_in_UFW\"><\/span>Check Open Ports in UFW<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>After making changes to any firewall, you should verify your changes to ensure they\u2019re correct and active.<\/p>\n<p>To check whether UFW is running:<\/p>\n<pre>sudo ufw status<\/pre>\n<p>To check whether UFW is running with additional information such as logging and profile status:<\/p>\n<pre>sudo ufw status verbose<\/pre>\n<p>To find the rule number for UFW rules:<\/p>\n<pre>sudo ufw status numbered<\/pre>\n<p>Then you can remove the rule:<\/p>\n<pre>sudo ufw delete 1<\/pre>\n<p>From the above article we will know and understand how to Open a Port in Ubuntu.<\/p>\n<p>To know about SSH Essentials: Working with SSH Servers, Clients, and Keys <a href=\"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/working-with-ssh-servers\/\">click here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Open a Port in Ubuntu using UFW UncomplicatedFirewall (UFW) is a command-line, frontend iptables manager, similar to Firewalld and ConfigServer Security &amp; Firewall (CSF). It\u2019s beneficial to understand basic UFW commands since it\u2019s pre-installed with many Ubuntu-based operating systems (OSs) including Mint. Those configuring UFW for a desktop system who prefer not to use the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":576,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41,42,66],"tags":[],"class_list":["post-567","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-control-panel","category-linux","category-ssh"],"_links":{"self":[{"href":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-json\/wp\/v2\/posts\/567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-json\/wp\/v2\/comments?post=567"}],"version-history":[{"count":11,"href":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-json\/wp\/v2\/posts\/567\/revisions"}],"predecessor-version":[{"id":579,"href":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-json\/wp\/v2\/posts\/567\/revisions\/579"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-json\/wp\/v2\/media\/576"}],"wp:attachment":[{"href":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-json\/wp\/v2\/media?parent=567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-json\/wp\/v2\/categories?post=567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hyderabadwebhosting.co.in\/tutorials\/wp-json\/wp\/v2\/tags?post=567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}