{"id":5456,"date":"2024-09-28T23:08:20","date_gmt":"2024-09-28T17:38:20","guid":{"rendered":"https:\/\/www.veeble.org\/kb\/?p=5456"},"modified":"2025-04-08T16:00:34","modified_gmt":"2025-04-08T10:30:34","slug":"how-to-set-up-ufw-firewall-on-ubuntu","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/how-to-set-up-ufw-firewall-on-ubuntu\/","title":{"rendered":"How to Set Up UFW Firewall on Ubuntu"},"content":{"rendered":"\n<p>The <a href=\"https:\/\/help.ubuntu.com\/community\/UFW\" target=\"_blank\" rel=\"noopener\">Uncomplicated Firewall (UFW)<\/a> is a front-end for managing iptables on Ubuntu and other Linux distributions. It simplifies the process of configuring firewall rules, making it more accessible for users who may not be familiar with the intricacies of iptables. UFW provides an easy way to protect your <a href=\"https:\/\/www.veeble.org\/vps-hosting\/\" target=\"_blank\" rel=\"noopener\">VPS <\/a>from unauthorized access by controlling incoming and outgoing network traffic.<\/p>\n\n\n\n<p>In this article, we&#8217;ll guide you through the process of setting up and managing UFW on Ubuntu, ensuring your server is secure.<\/p>\n\n\n\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-6570c0da      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#prerequisites\" class=\"uagb-toc-link__trigger\">Prerequisites<\/a><li class=\"uagb-toc__list\"><a href=\"#1-install-ufw\" class=\"uagb-toc-link__trigger\">1. Install UFW<\/a><li class=\"uagb-toc__list\"><a href=\"#2-enabling-ufw\" class=\"uagb-toc-link__trigger\">2. Enabling UFW<\/a><li class=\"uagb-toc__list\"><a href=\"#3-configure-basic-rules\" class=\"uagb-toc-link__trigger\">3. Configure Basic Rules<\/a><li class=\"uagb-toc__list\"><a href=\"#conclusion\" class=\"uagb-toc-link__trigger\">Conclusion<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#optimize-nodejs-performance-with-veebles-high-speed-hosting\" class=\"uagb-toc-link__trigger\">Optimize Node.js Performance with Veeble&#039;s High-Speed Hosting<\/a><\/ul><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h2>\n\n\n<ul class=\"wp-block-list\">\n<li>Ubuntu 18.04 or later.<\/li>\n\n\n\n<li>A user with sudo privileges.<\/li>\n\n\n\n<li>SSH access to the server<\/li>\n<\/ul>\n\n\n<h2 class=\"wp-block-heading\" id=\"1-install-ufw\">1. Install UFW<\/h2>\n\n\n<p>  UFW is installed by default on most Ubuntu installations, but you can verify its status. <\/p>\n\n\n\n<p>If UFW is not installed, you can install it using:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt update<br>sudo apt install ufw<\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"2-enabling-ufw\">2. Enabling UFW<\/h2>\n\n\n<p>Once you\u2019ve verified UFW is installed, you can enable it. It\u2019s good practice to allow SSH connections before enabling UFW to avoid being locked out, especially if you\u2019re connected remotely.<\/p>\n\n\n\n<p>To allow SSH connection<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow ssh<\/code><\/pre>\n\n\n\n<p>Now, enable UFW.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw enable<\/code><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"3-configure-basic-rules\">3. Configure Basic Rules<\/h2>\n\n\n<p>With UFW enabled, you can begin setting rules to control traffic. By default, UFW denies all incoming connections and allows outgoing connections. You can verify the default rules by running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw default allow outgoing<br>sudo ufw default deny incoming<\/code><\/pre>\n\n\n\n<p><strong>Allowing HTTP and HTTPS Traffic<\/strong><\/p>\n\n\n\n<p>If you\u2019re running a web server, you\u2019ll likely want to allow HTTP (port 80) and HTTPS (port 443) traffic:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo ufw allow http<br>sudo ufw allow https<\/pre>\n\n\n\n<p><strong>Allowing Specific Ports<\/strong><\/p>\n\n\n\n<p>You can also allow or deny specific ports. For instance, to allow traffic on port 8080:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 8080<\/code><\/pre>\n\n\n\n<p><strong>Denying Specific Ports<\/strong><\/p>\n\n\n\n<p>If you want to deny traffic on a specific port, you can use the following syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw deny 8080<\/code><\/pre>\n\n\n\n<p><strong>Deleting Rules<\/strong><\/p>\n\n\n\n<p>If you need to remove a rule, you can use:<\/p>\n\n\n\n<p><strong>ufw delete allow 8080<\/strong><\/p>\n\n\n\n<p>This will remove the rule allowing traffic on port 8080.<\/p>\n\n\n\n<p><strong>Checking UFW Status and Rules<\/strong><\/p>\n\n\n\n<p>After configuring UFW, it\u2019s essential to check the status and verify that the firewall rules are active. Use the following command:<\/p>\n\n\n\n<p>sudo ufw status<\/p>\n\n\n\n<p><strong>Disable UFW<\/strong><\/p>\n\n\n\n<p>If at any point you want to disable UFW, you can do so with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ufw disable<\/code><\/pre>\n\n\n\n<p>This will stop UFW and remove all firewall rules, reverting to the default configuration.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n<p>Setting up UFW on Ubuntu is an effective way to enhance your server&#8217;s security. By following these steps, you can configure UFW to control traffic, ensuring only authorized connections are allowed. This firewall is flexible and can be adjusted based on the specific requirements of your server environment.<\/p>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-a33f967c wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Optimize Node.js Performance with Veeble&#8217;s High-Speed Hosting<\/h3><p class=\"uagb-cta__desc\">Boost your app&#8217;s speed with SSD storage and load balancing. Global data centers mean low latency and high performance.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/nodejs-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">Explore Node.js Plans<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-ast-global-color-8-color has-text-color has-link-color wp-elements-f1ccfa660b17e669f6068cafb32dc4c4\"><strong>Also Read:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-veeble-hosting wp-block-embed-veeble-hosting\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/www.veeble.org\/kb\/how-to-prevent-brute-force-attacks-on-your-linux-vps\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-veeble-hosting wp-block-embed-veeble-hosting\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/www.veeble.org\/kb\/15-basic-server-hardening-measures-for-linux\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>The Uncomplicated Firewall (UFW) is a front-end for managing iptables on Ubuntu and other Linux distributions. It simplifies the process of configuring firewall rules, [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":6230,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[9],"tags":[],"class_list":["post-5456","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-firewallsecurity"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/09\/How-to-Set-Up-UFW-Firewall-on-ubuntu.jpg",2240,1260,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/09\/How-to-Set-Up-UFW-Firewall-on-ubuntu-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/09\/How-to-Set-Up-UFW-Firewall-on-ubuntu-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/09\/How-to-Set-Up-UFW-Firewall-on-ubuntu-768x432.jpg",768,432,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/09\/How-to-Set-Up-UFW-Firewall-on-ubuntu-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/09\/How-to-Set-Up-UFW-Firewall-on-ubuntu-1536x864.jpg",1536,864,true],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/09\/How-to-Set-Up-UFW-Firewall-on-ubuntu-2048x1152.jpg",2048,1152,true]},"uagb_author_info":{"display_name":"Nayana Nair","author_link":"https:\/\/www.veeble.com\/kb\/author\/nayana\/"},"uagb_comment_info":0,"uagb_excerpt":"The Uncomplicated Firewall (UFW) is a front-end for managing iptables on Ubuntu and other Linux distributions. It simplifies the process of configuring firewall rules, [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/5456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=5456"}],"version-history":[{"count":5,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/5456\/revisions"}],"predecessor-version":[{"id":8512,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/5456\/revisions\/8512"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/6230"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=5456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=5456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=5456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}