{"id":31323,"date":"2019-07-20T11:31:27","date_gmt":"2019-07-20T16:31:27","guid":{"rendered":"https:\/\/www.rosehosting.com\/blog\/?p=31323"},"modified":"2022-06-03T03:33:38","modified_gmt":"2022-06-03T08:33:38","slug":"how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/","title":{"rendered":"How to Configure a Firewall with UFW on Ubuntu 18.04"},"content":{"rendered":"<div id=\"bsf_rt_marker\"><\/div><p><img decoding=\"async\" class=\"alignnone size-full wp-image-31347\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/how-to-configure-ufw-on-ubuntu-18.04.jpg\" alt=\"\" width=\"742\" height=\"372\" srcset=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/how-to-configure-ufw-on-ubuntu-18.04.jpg 742w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/how-to-configure-ufw-on-ubuntu-18.04-150x75.jpg 150w, https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/how-to-configure-ufw-on-ubuntu-18.04-300x150.jpg 300w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><\/p>\n<p>In this article, we will show you how to install and configure UFW on an <a href=\"https:\/\/www.rosehosting.com\/ubuntu-hosting.html\" target=\"_blank\" rel=\"noopener noreferrer\">Ubuntu 18.04 VPS<\/a>. First, we will take a moment to introduce and explain what firewalls are, and then we&#8217;ll show you how to use UFW and how to make the appropriate UFW configuration.<\/p>\n<p>A firewall is a software program that monitors the network traffic and prevents unauthorized access to or from a private network. In regards to the Linux kernel, a Netfilter subsystem is implemented, which is used to manipulate the network traffic. Almost all modern Linux firewall solutions use this system to filter network packets. Additionally &#8216;iptables&#8217; &#8211; a firewall utility accessible from the command line &#8211; is also part of the Netfilter framework. To simplify the process of creating firewall rules, Canonical (the creators of Ubuntu) developed an iptables interface called Uncomplicated Firewall (UFW).<\/p>\n<p><img decoding=\"async\" class=\"alignright size-full wp-image-31348\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/install-configure-ufw-firewall-ubuntu-vps.jpg\" alt=\"\" width=\"150\" height=\"75\" \/>If you are using Ubuntu 18.04 and want to secure your network without having to deal with learning how to use iptables, then UFW may be the appropriate solution you are looking for.<!--more--><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69ed6a9a84928\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><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><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69ed6a9a84928\"  aria-label=\"Toggle\" \/><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.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Prerequisites\" >Prerequisites<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Step-1-Connect-to-Your-Server\" >Step 1: Connect to Your Server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Step-2-Install-UFW\" >Step 2: Install UFW<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Step-3-UFW-Default-Policies\" >Step 3: UFW Default Policies<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Step-4-Allow-SSH-Connections\" >Step 4: Allow SSH Connections<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Step-5-Enable-UFW\" >Step 5: Enable UFW<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Step-6-Allow-Connections-on-Specific-Ports\" >Step 6: Allow Connections on Specific Ports<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Step-7-Allow-Port-Ranges\" >Step 7: Allow Port Ranges<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Step-8-Allow-Specific-IP-Addresses\" >Step 8: Allow Specific IP Addresses<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Step-9-Deny-Connections\" >Step 9: Deny Connections<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Step-10-Delete-UFW-Rules\" >Step 10: Delete UFW Rules<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#Step-11-Disable-or-Reset-UFW\" >Step 11: Disable or Reset UFW<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span>Prerequisites<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To follow this tutorial, you will need a server with Ubuntu 18.04 and SSH access with the root user (or a user with sudo privileges). Let&#8217;s begin with the tutorial.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step-1-Connect-to-Your-Server\"><\/span>Step 1: Connect to Your Server<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before we begin, you&#8217;ll need to connect to your server via SSH as root or user with sudo privileges. To do this, use the following command:<\/p>\n<pre>ssh root@<span style=\"color: #ff0000;\">IP_Address<\/span> -p <span style=\"color: #ff0000;\">Port_Number<\/span><\/pre>\n<p>of course, you will need to replace <code>IP_Address<\/code> and <code>Port_Number<\/code> with your actual server IP address and SSH port number.<\/p>\n<p>Once logged in, make sure that your server is up-to-date by running the following commands:<\/p>\n<pre>sudo apt update\r\nsudo apt upgrade<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step-2-Install-UFW\"><\/span>Step 2: Install UFW<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>UFW should be already installed by default on Ubuntu 18.04 &#8211; but if for some reason is is not installed, you can install it with this command:<\/p>\n<pre>sudo apt install ufw<\/pre>\n<p>Once the installation is complete, you can check the UFW status with the command:<\/p>\n<pre>sudo ufw status verbose<\/pre>\n<p>UFW by default is initially disabled, and if you never activated before you will get the output:<\/p>\n<pre>Output\r\nStatus: inactive<\/pre>\n<p>If you already have UFW activated on your server, the output will look quite different and will look similar to the following:<\/p>\n<pre>Output:\r\n\r\nStatus: active\r\nLogging: on (low)\r\nDefault: deny (incoming), allow (outgoing), disabled (routed)\r\nNew profiles: skip\r\n\r\nTo                         Action      From\r\n--                         ------      ----\r\n22\/tcp                     ALLOW IN    Anywhere\r\n80\/tcp                     ALLOW IN    Anywhere\r\n443\/tcp                    ALLOW IN    Anywhere\r\n22\/tcp (v6)                ALLOW IN    Anywhere (v6)\r\n80\/tcp (v6)                ALLOW IN    Anywhere (v6)\r\n443\/tcp (v6)               ALLOW IN    Anywhere (v6)\r\n....<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step-3-UFW-Default-Policies\"><\/span>Step 3: UFW Default Policies<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The first thing you need to know is the default policies. By default, UFW is configured to deny all incoming connections and allow all outgoing connections. In other words, all of the connections that will try to access your server will be refused and all of your applications and services that are locally found on your server will be able to reach the outside world and access other servers.<\/p>\n<p>If you want to check or change the default policies, you can find them in the <code>\/etc\/default\/ufw<\/code>\u00a0configuration file.<\/p>\n<p>To set these UFW rules to the default, you can run the following commands:<\/p>\n<pre>sudo ufw default deny incoming\r\nsudo ufw default allow outgoing<\/pre>\n<p>Keep in mind that servers usually need to respond to an incoming request from Internet users. So, in most cases, you cannot set your firewall to block all incoming connections. In the next step, we&#8217;ll learn how to allow specific connections.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step-4-Allow-SSH-Connections\"><\/span>Step 4: Allow SSH Connections<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before you enable UFW, you need to allow SSH access on your server by adding a rule that will allow incoming SSH connections. Otherwise, you will get locked and you will not be able to connect to your Ubuntu server.<\/p>\n<p>You can use the following command to configure the UFW firewall to allow all incoming SSH connections:<\/p>\n<pre>sudo ufw allow ssh<\/pre>\n<p>Then you will receive the following output:<\/p>\n<pre>Rules updated\r\nRules updated (v6)<\/pre>\n<p>Please note that this command is only if your server listens to the standardized SSH port: 22. If the SSH service uses a custom non-standard port, you will need to open that port. If the SSH service on your server uses a unique port, for example port 900, then you can use the following command:<\/p>\n<pre>sudo ufw allow 900<\/pre>\n<p>Note that you&#8217;ll need to know what port number your service currently uses.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step-5-Enable-UFW\"><\/span>Step 5: Enable UFW<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now your firewall is configured to allow SSH connections and you are sure that your current SSH connection will not be affected, you can continue with enabling the UFW firewall.<\/p>\n<pre>sudo ufw enable<\/pre>\n<p>After which you will receive the following output:<\/p>\n<pre>Command may disrupt existing ssh connections. Proceed with operation (y|n)? y\r\nFirewall is active and enabled on system startup<\/pre>\n<p>You will get a warning that tells you that you need to have configured allowing SSH rules, otherwise the existing SSH connection will be closed. Since you already have, type [y] and continue with [Enter].<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step-6-Allow-Connections-on-Specific-Ports\"><\/span>Step 6: Allow Connections on Specific Ports<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The applications and services that you use may need to have their ports opened for incoming and outgoing connections, depending on the application&#8217;s purpose. The most common ports you&#8217;ll need to unblock are ports 80 &amp; 443, which are used by the web server, and 25, 110, 143, 587 and 993, which are used by the mail server.<\/p>\n<p>We&#8217;ll show you through a few examples of how to allow incoming connections for some common services.<\/p>\n<p>To allow all HTTP (port 80) connections, run this command:<\/p>\n<pre>sudo ufw allow http<\/pre>\n<p>Also, if you want to specify the port, you can apply what is essentially the same rule but with a different syntax:<\/p>\n<pre>sudo ufw allow 80<\/pre>\n<p>To allow all HTTPS (port 443) connections, run the command:<\/p>\n<pre>sudo ufw allow https<\/pre>\n<p>Additionally, if you want to specify the HTTPS port, you can apply the rule with a different syntax:<\/p>\n<pre>sudo ufw allow 443<\/pre>\n<p>If you are using a mail server, some of the next rules could be useful.<\/p>\n<p>To allow all incoming SMTP you can run the command:<\/p>\n<pre>sudo ufw allow 25<\/pre>\n<p>To allow all incoming IMAP connections, run the command:<\/p>\n<pre>sudo ufw allow 143<\/pre>\n<p>And to allow all incoming IMAPS requests, you can use the command:<\/p>\n<pre>sudo ufw allow 993<\/pre>\n<p>If you are using POP3 instead, this command below will allow all incoming connections:<\/p>\n<pre>sudo ufw allow 110<\/pre>\n<p>And for all incoming POP3S requests, use this next command:<\/p>\n<pre>sudo ufw allow 995<\/pre>\n<p>Finally, if you are running a specific program that requires web access, you will need to enable to port specific to that program as well. For example, if you run Tomcat on your server, you will need port 8080. You can allow all incoming connections to this port with the command:<\/p>\n<pre>sudo ufw allow &lt;port number&gt;<\/pre>\n<p>You can do this for all specific ports that you may need.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step-7-Allow-Port-Ranges\"><\/span>Step 7: Allow Port Ranges<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>UFW also can allow access to port ranges instead of allowing access to a single port. When you want to allow port ranges at the UFW port, you need to specify the range of the port and the protocol, either TCP or UDP.<\/p>\n<p>For example, if you want to allow the ports from 8069 to 8080 for both TCP and UDP, you can use the following commands:<\/p>\n<pre>sudo ufw allow 8069:8080\/tcp\r\nsudo ufw allow 8069:8080\/udp<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step-8-Allow-Specific-IP-Addresses\"><\/span>Step 8: Allow Specific IP Addresses<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you want to allow only one IP address (for example a trusted machine found on your local network) to be able to access all ports, you can use the command:<\/p>\n<pre>sudo ufw allow from 206.207.208.209<\/pre>\n<p>On top of this, you can also allow a specific IP address to a particular port! Let&#8217;s say you want to allow a specific IP address to use the MySQL port (MySQL uses port 3306), then you can simply use this command:<\/p>\n<pre>sudo ufw allow from 206.207.208.209 to any port 3306<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step-9-Deny-Connections\"><\/span>Step 9: Deny Connections<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>As mentioned earlier in <strong>Step 3<\/strong>, the default policy for incoming connections is set to &#8216;deny&#8217;. However, sometimes you may need to deny specific connections based on the source IP address or specific port.<\/p>\n<p>The deny rule is very useful if you have an attack on your server from a specific IP address and your ports 80 and 443 are open. In this case, you can block that IP address using the following example. Of course, don&#8217;t forget to change the IP address 24.25.26.27 with the actual IP address that you want to block:<\/p>\n<pre>sudo ufw deny from 24.25.26.27<\/pre>\n<p>This will block the IP address from accessing all of your open ports. However, if you want to block the IP address from being able to access a particular port, you can use the next example:<\/p>\n<pre>sudo ufw deny from 24.25.26.27 to any port 80\r\nsudo ufw deny from 24.25.26.27 to any port 443<\/pre>\n<p>As you can notice, creating deny rules is similar to the rules for allowing.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step-10-Delete-UFW-Rules\"><\/span>Step 10: Delete UFW Rules<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The importance of deleting UFW rules is as important as creating them. There are two different ways to remove a UFW rule. The first method is by using the rule number, and the second is by specifying the actual rule.<\/p>\n<p>If you want to delete the UFW rule with numbers, you will need to know the rule&#8217;s number. To list the rule numbers, you can use the command:<\/p>\n<pre>sudo ufw status numbered<\/pre>\n<pre>Output:\r\n\r\nStatus: active\r\n\r\n     To                         Action      From\r\n     --                         ------      ----\r\n[ 1] 80                         ALLOW IN    Anywhere\r\n[ 2] 443                        ALLOW IN    Anywhere\r\n[ 3] 22                         ALLOW IN    Anywhere\r\n[ 4] Anywhere                   ALLOW IN    206.207.208.209\r\n[ 5] 7022                       ALLOW IN    Anywhere\r\n[ 6] 8069                       ALLOW IN    Anywhere\r\n...<\/pre>\n<p>To remove the rule that is labeled as rule number 4, which allows connections from IP address 206.207.208.209, you can use the command:<\/p>\n<pre>sudo ufw delete 4<\/pre>\n<p>If you want to use the second method, which is to remove a rule by specifying the actual rule. Let&#8217;s say you want to close the port 8069 for example &#8211; in that case you would use the following command:<\/p>\n<pre>sudo ufw delete allow 8069<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step-11-Disable-or-Reset-UFW\"><\/span>Step 11: Disable or Reset UFW<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If for any reason you need to stop all UFW rules on your server, you can disable it by using the command:<\/p>\n<pre>sudo ufw disable<\/pre>\n<p>This will stop all rules that were currently active on your server. However, if you need to reactivate the firewall rules, you can simply enable it again.<\/p>\n<pre>sudo ufw enable<\/pre>\n<p>If for some reason you want to delete all of the rules and start with a fresh UFW, then you can use the following command:<\/p>\n<pre>sudo ufw reset<\/pre>\n<p>Please note that default policies will not change to their original settings if they have already been modified.<\/p>\n<p>In this article, we showed you how to install UFW and then use it to configure a firewall on Ubuntu 18.04. Now you can use the knowledge of this guide to start creating your own UFW firewall rules and protect your server.<\/p>\n<hr \/>\n<p><img decoding=\"async\" class=\"alignleft size-full wp-image-31349\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/firewall-setup-managed-support-ubuntu-vps.jpg\" alt=\"\" width=\"150\" height=\"75\" \/>Of course, if you are one of our <a href=\"https:\/\/www.rosehosting.com\/ubuntu-hosting.html\" target=\"_blank\" rel=\"noopener noreferrer\">Managed Ubuntu Hosting<\/a> customers, you don\u2019t have to configure your firewall with UFW on your server \u2013 simply ask our admins, sit back, and relax. Our admins will configure the firewall rules on your server for you immediately.<\/p>\n<p><strong><span style=\"color: #ff0000;\">PS.<\/span><\/strong> If you liked this post on how to configure a firewall with UFW on Ubuntu 18.04, please share it with your friends on the social networks using the share buttons below, or simply leave a comment in the comments section. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will show you how to install and configure UFW on an Ubuntu 18.04 VPS. First, we &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Configure a Firewall with UFW on Ubuntu 18.04\" class=\"read-more button\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#more-31323\" aria-label=\"Read more about How to Configure a Firewall with UFW on Ubuntu 18.04\">Read More<\/a><\/p>\n","protected":false},"author":4,"featured_media":31347,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1703,13,1698],"tags":[],"class_list":["post-31323","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-security","category-tutorials","category-ubuntu","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Configure a Firewall with UFW on Ubuntu 18.04 | RoseHosting<\/title>\n<meta name=\"description\" content=\"How to Configure a Firewall with UFW on Ubuntu 18.04 | RoseHosting\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Configure a Firewall with UFW on Ubuntu 18.04\" \/>\n<meta property=\"og:description\" content=\"How to Configure a Firewall with UFW on Ubuntu 18.04 | RoseHosting\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/\" \/>\n<meta property=\"og:site_name\" content=\"RoseHosting\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/RoseHosting\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/rosehosting.helpdesk\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-20T16:31:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-03T08:33:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/how-to-configure-ufw-on-ubuntu-18.04.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"742\" \/>\n\t<meta property=\"og:image:height\" content=\"372\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jeff Wilson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rosehosting\" \/>\n<meta name=\"twitter:site\" content=\"@rosehosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeff Wilson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/\"},\"author\":{\"name\":\"Jeff Wilson\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/person\\\/7ce77a842fa6a9a7f8efa186f2353713\"},\"headline\":\"How to Configure a Firewall with UFW on Ubuntu 18.04\",\"datePublished\":\"2019-07-20T16:31:27+00:00\",\"dateModified\":\"2022-06-03T08:33:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/\"},\"wordCount\":1636,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/how-to-configure-ufw-on-ubuntu-18.04.jpg\",\"articleSection\":[\"Security\",\"Tutorials\",\"Ubuntu\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/\",\"name\":\"How to Configure a Firewall with UFW on Ubuntu 18.04 | RoseHosting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/how-to-configure-ufw-on-ubuntu-18.04.jpg\",\"datePublished\":\"2019-07-20T16:31:27+00:00\",\"dateModified\":\"2022-06-03T08:33:38+00:00\",\"description\":\"How to Configure a Firewall with UFW on Ubuntu 18.04 | RoseHosting\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/how-to-configure-ufw-on-ubuntu-18.04.jpg\",\"contentUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/06\\\/how-to-configure-ufw-on-ubuntu-18.04.jpg\",\"width\":742,\"height\":372},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Configure a Firewall with UFW on Ubuntu 18.04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\",\"name\":\"RoseHosting.com\",\"description\":\"Premium Linux Tutorials Since 2001\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#organization\",\"name\":\"RoseHosting\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/android-chrome-192x192-1.png\",\"contentUrl\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/android-chrome-192x192-1.png\",\"width\":192,\"height\":192,\"caption\":\"RoseHosting\"},\"image\":{\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/RoseHosting\",\"https:\\\/\\\/x.com\\\/rosehosting\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/rosehosting\\\/\"],\"description\":\"RoseHosting is a leading Linux hosting provider, serving thousands of clients world-wide since 2001.\",\"email\":\"info@rosehosting.com\",\"telephone\":\"(314) 275-0414\",\"legalName\":\"Rose Web Services LLC\",\"foundingDate\":\"2001-04-02\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"11\",\"maxValue\":\"50\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/#\\\/schema\\\/person\\\/7ce77a842fa6a9a7f8efa186f2353713\",\"name\":\"Jeff Wilson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g\",\"caption\":\"Jeff Wilson\"},\"description\":\"An experienced Linux veteran with many years of experience. Helping other Linux admins with frequent Linux and business-related blog posts on the RoseHosting blog. Techie by choice. Loving nature and travel. Happily married and father of two lovely children.\",\"sameAs\":[\"https:\\\/\\\/www.rosehosting.com\",\"https:\\\/\\\/www.facebook.com\\\/rosehosting.helpdesk\"],\"url\":\"https:\\\/\\\/www.rosehosting.com\\\/blog\\\/author\\\/jwilson\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Configure a Firewall with UFW on Ubuntu 18.04 | RoseHosting","description":"How to Configure a Firewall with UFW on Ubuntu 18.04 | RoseHosting","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/","og_locale":"en_US","og_type":"article","og_title":"How to Configure a Firewall with UFW on Ubuntu 18.04","og_description":"How to Configure a Firewall with UFW on Ubuntu 18.04 | RoseHosting","og_url":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/","og_site_name":"RoseHosting","article_publisher":"https:\/\/www.facebook.com\/RoseHosting","article_author":"https:\/\/www.facebook.com\/rosehosting.helpdesk","article_published_time":"2019-07-20T16:31:27+00:00","article_modified_time":"2022-06-03T08:33:38+00:00","og_image":[{"width":742,"height":372,"url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/how-to-configure-ufw-on-ubuntu-18.04.jpg","type":"image\/jpeg"}],"author":"Jeff Wilson","twitter_card":"summary_large_image","twitter_creator":"@rosehosting","twitter_site":"@rosehosting","twitter_misc":{"Written by":"Jeff Wilson","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#article","isPartOf":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/"},"author":{"name":"Jeff Wilson","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/person\/7ce77a842fa6a9a7f8efa186f2353713"},"headline":"How to Configure a Firewall with UFW on Ubuntu 18.04","datePublished":"2019-07-20T16:31:27+00:00","dateModified":"2022-06-03T08:33:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/"},"wordCount":1636,"commentCount":0,"publisher":{"@id":"https:\/\/www.rosehosting.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#primaryimage"},"thumbnailUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/how-to-configure-ufw-on-ubuntu-18.04.jpg","articleSection":["Security","Tutorials","Ubuntu"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/","url":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/","name":"How to Configure a Firewall with UFW on Ubuntu 18.04 | RoseHosting","isPartOf":{"@id":"https:\/\/www.rosehosting.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#primaryimage"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#primaryimage"},"thumbnailUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/how-to-configure-ufw-on-ubuntu-18.04.jpg","datePublished":"2019-07-20T16:31:27+00:00","dateModified":"2022-06-03T08:33:38+00:00","description":"How to Configure a Firewall with UFW on Ubuntu 18.04 | RoseHosting","breadcrumb":{"@id":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#primaryimage","url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/how-to-configure-ufw-on-ubuntu-18.04.jpg","contentUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2019\/06\/how-to-configure-ufw-on-ubuntu-18.04.jpg","width":742,"height":372},{"@type":"BreadcrumbList","@id":"https:\/\/www.rosehosting.com\/blog\/how-to-configure-a-firewall-with-ufw-on-ubuntu-18-04\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.rosehosting.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Configure a Firewall with UFW on Ubuntu 18.04"}]},{"@type":"WebSite","@id":"https:\/\/www.rosehosting.com\/blog\/#website","url":"https:\/\/www.rosehosting.com\/blog\/","name":"RoseHosting.com","description":"Premium Linux Tutorials Since 2001","publisher":{"@id":"https:\/\/www.rosehosting.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.rosehosting.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.rosehosting.com\/blog\/#organization","name":"RoseHosting","url":"https:\/\/www.rosehosting.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/03\/android-chrome-192x192-1.png","contentUrl":"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2022\/03\/android-chrome-192x192-1.png","width":192,"height":192,"caption":"RoseHosting"},"image":{"@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/RoseHosting","https:\/\/x.com\/rosehosting","https:\/\/www.linkedin.com\/in\/rosehosting\/"],"description":"RoseHosting is a leading Linux hosting provider, serving thousands of clients world-wide since 2001.","email":"info@rosehosting.com","telephone":"(314) 275-0414","legalName":"Rose Web Services LLC","foundingDate":"2001-04-02","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"11","maxValue":"50"}},{"@type":"Person","@id":"https:\/\/www.rosehosting.com\/blog\/#\/schema\/person\/7ce77a842fa6a9a7f8efa186f2353713","name":"Jeff Wilson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0985fed6af04cc60703d2ecf27c65dfa373e0ca00eb21c0b03477e099ea3f99f?s=96&r=g","caption":"Jeff Wilson"},"description":"An experienced Linux veteran with many years of experience. Helping other Linux admins with frequent Linux and business-related blog posts on the RoseHosting blog. Techie by choice. Loving nature and travel. Happily married and father of two lovely children.","sameAs":["https:\/\/www.rosehosting.com","https:\/\/www.facebook.com\/rosehosting.helpdesk"],"url":"https:\/\/www.rosehosting.com\/blog\/author\/jwilson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/31323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/comments?post=31323"}],"version-history":[{"count":1,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/31323\/revisions"}],"predecessor-version":[{"id":41713,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/posts\/31323\/revisions\/41713"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/media\/31347"}],"wp:attachment":[{"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/media?parent=31323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/categories?post=31323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rosehosting.com\/blog\/wp-json\/wp\/v2\/tags?post=31323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}