{"id":6138,"date":"2026-11-03T18:00:07","date_gmt":"2026-11-03T18:00:07","guid":{"rendered":"https:\/\/zynoo.com\/blog\/?p=6138"},"modified":"2026-11-05T19:46:36","modified_gmt":"2026-11-05T19:46:36","slug":"ubuntu-firewall-ufw","status":"publish","type":"post","link":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/","title":{"rendered":"Ubuntu Firewall: How to Set Up UFW on a VPS"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Configuring the <strong>Ubuntu firewall<\/strong> with UFW (Uncomplicated Firewall) helps protect your VPS by allowing essential connections and blocking unnecessary incoming traffic. The setup takes only a few commands, but their order matters: allow SSH <strong>before<\/strong> enabling the firewall, or you could lose remote access.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This tutorial shows how to install UFW, configure safe defaults, open website ports, activate the firewall, and manage rules afterward.<\/p>\n\n\n\n<h2 id=\"h-key-takeaways\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Key_Takeaways\"><\/span>Key Takeaways<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>UFW provides a simple command-line way to manage the Ubuntu firewall.<\/li>\n\n\n\n<li>Allow your actual SSH port before enabling UFW on a remote VPS.<\/li>\n\n\n\n<li>Deny unsolicited incoming traffic by default, then open only the ports your services need.<\/li>\n\n\n\n<li>Verify access from a second connection and review rules whenever you add or remove applications.<\/li>\n<\/ul>\n\n\n\n<h2 id=\"h-what-is-ufw-on-ubuntu\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Is_UFW_on_Ubuntu\"><\/span>What Is UFW on Ubuntu?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">UFW is a firewall configuration tool that manages rules for the Linux kernel&#8217;s packet-filtering system. Rather than writing low-level rules, you can allow or deny connections with commands such as <code>ufw allow<\/code> and <code>ufw delete<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a typical web-hosting VPS, you&#8217;ll allow SSH for administration and ports 80 and 443 for visitors. Database and internal application ports should generally remain inaccessible from the public internet.<\/p>\n\n\n\n<h2 id=\"h-before-you-configure-the-ubuntu-firewall\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Before_You_Configure_the_Ubuntu_Firewall\"><\/span>Before You Configure the Ubuntu Firewall<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll need an Ubuntu VPS with <code>sudo<\/code> access and a working SSH connection. If you&#8217;re new to remote administration, see ZYNOO&#8217;s <a href=\"https:\/\/zynoo.com\/blog\/ssh-commands\/\">SSH commands for beginners<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Keep your current SSH session open.<\/strong> Check that your VPS provider&#8217;s web or recovery console works. Provider-level network firewalls are separate from UFW and may also need appropriate rules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These instructions assume a fresh or inactive UFW configuration. If UFW is already active, inspect its rules and service requirements before changing the default policy.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/Ubuntu-VPS-firewall-configuration-using-UFW-1024x576.webp\" alt=\"Ubuntu VPS firewall configuration using UFW\" class=\"wp-image-6152\" srcset=\"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/Ubuntu-VPS-firewall-configuration-using-UFW-1024x576.webp 1024w, https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/Ubuntu-VPS-firewall-configuration-using-UFW-300x169.webp 300w, https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/Ubuntu-VPS-firewall-configuration-using-UFW-768x432.webp 768w, https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/Ubuntu-VPS-firewall-configuration-using-UFW-1536x864.webp 1536w, https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/Ubuntu-VPS-firewall-configuration-using-UFW.webp 1600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 id=\"h-step-1-check-and-install-ufw\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_1_Check_and_Install_UFW\"><\/span>Step 1: Check and Install UFW<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Check whether UFW is available:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw status<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Status: inactive<\/code> means it&#8217;s installed but not enforcing rules. If the command isn&#8217;t found, install it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install ufw<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Don&#8217;t enable the firewall yet.<\/p>\n\n\n\n<h2 id=\"h-step-2-allow-ssh-before-enabling-ufw\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_2_Allow_SSH_Before_Enabling_UFW\"><\/span>Step 2: Allow SSH Before Enabling UFW<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Find the TCP port where SSH is listening:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ss -ltnp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Compare the output with the port used by your SSH client. Port <strong>22<\/strong> is common, but VPS configurations can use another port.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If SSH uses port 22, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 22\/tcp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If SSH actually uses a custom port such as 2222, allow that port <em>instead<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 2222\/tcp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Port 2222 is an example, not an additional port everyone should open. Review your pending rules:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw show added<\/code><\/pre>\n\n\n\n<h2 id=\"h-step-3-set-default-rules-and-check-ipv6\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_3_Set_Default_Rules_and_Check_IPv6\"><\/span>Step 3: Set Default Rules and Check IPv6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use a default-deny policy for incoming connections while allowing the VPS to initiate outgoing connections:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw default deny incoming\nsudo ufw default allow outgoing<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If your VPS has public IPv6 connectivity, confirm UFW handles it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep '^IPV6=' \/etc\/default\/ufw<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The expected setting is <code>IPV6=yes<\/code>. If IPv6 is in use but this is set to <code>no<\/code>, edit <code>\/etc\/default\/ufw<\/code> to enable IPv6 handling <strong>before<\/strong> activating the firewall.<\/p>\n\n\n\n<h2 id=\"h-step-4-open-the-ports-your-website-needs\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_4_Open_the_Ports_Your_Website_Needs\"><\/span>Step 4: Open the Ports Your Website Needs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If the VPS hosts a public website, allow <a href=\"https:\/\/en.wikipedia.org\/wiki\/HTTP\">HTTP<\/a> and HTTPS before activating UFW:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 80\/tcp\nsudo ufw allow 443\/tcp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Common ports for an Ubuntu VPS are:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Service<\/th><th>Port<\/th><th>Protocol<\/th><\/tr><tr><td>SSH<\/td><td>22 (or your custom port)<\/td><td>TCP<\/td><\/tr><tr><td>HTTP<\/td><td>80<\/td><td>TCP<\/td><\/tr><tr><td>HTTPS<\/td><td>443<\/td><td>TCP<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For a public application on a different TCP port, the UFW allow-port syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow 8080\/tcp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Only run that example if your service needs external access on port 8080. For a UDP service, specify <code>\/udp<\/code> instead, such as <code>sudo ufw allow 51820\/udp<\/code> for a WireGuard endpoint configured on that port.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also check available application profiles:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw app list<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If <code>Nginx Full<\/code> is listed, inspect its ports with <code>sudo ufw app info 'Nginx Full'<\/code>. The command <code>sudo ufw allow 'Nginx Full'<\/code> can replace the two website-port rules above; you don&#8217;t need both approaches. Applications behind a <a href=\"https:\/\/zynoo.com\/blog\/nginx-reverse-proxy-ubuntu\/\">local Nginx reverse proxy<\/a> generally shouldn&#8217;t expose their backend port publicly.<\/p>\n\n\n\n<h2 id=\"h-step-5-enable-ufw-and-verify-the-firewall\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_5_Enable_UFW_and_Verify_the_Firewall\"><\/span>Step 5: Enable UFW and Verify the Firewall<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once SSH and any required service ports are allowed, enable UFW:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw enable<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It may warn that the operation could affect SSH. Proceed only after confirming your SSH rule and recovery access. Check the live rules:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw status verbose<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see <code>Status: active<\/code>, default policies, and your allowed ports. UFW also enables itself at boot.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Before closing your original SSH session, connect again from a second terminal.<\/strong> From your own computer, use <code>ssh -p 22 username@server-ip<\/code>, replacing the username, address, and port as needed. Test your website externally if you opened ports 80 and 443. An <code>ALLOW<\/code> rule alone doesn&#8217;t prove the service is reachable.<\/p>\n\n\n\n<h2 id=\"h-step-6-manage-restrict-and-delete-ufw-rules\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_6_Manage_Restrict_and_Delete_UFW_Rules\"><\/span>Step 6: Manage, Restrict, and Delete UFW Rules<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To list firewall rules with numbers:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw status numbered<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To delete an outdated allow rule, for example TCP port 8080:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw delete allow 8080\/tcp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also delete by rule number (<code>sudo ufw delete 3<\/code>), but check the current listing first: numbering can change, and deleting by number may remove only one of a matching IPv4\/IPv6 pair.<\/p>\n\n\n\n<h3 id=\"h-optional-restrict-ssh-to-your-ip\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Optional_Restrict_SSH_to_Your_IP\"><\/span>Optional: Restrict SSH to Your IP<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If your administrative IP is stable, you can restrict SSH to that address. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow from 203.0.113.10 to any port 22 proto tcp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace the example IP with your real public IP. Test a new login from that address, then remove the old blanket rule with <code>sudo ufw delete allow 22\/tcp<\/code>. <strong>Leaving the blanket rule in place would still allow everyone.<\/strong> Keep the original session and recovery console available throughout.<\/p>\n\n\n\n<h3 id=\"h-optional-rate-limit-ssh-attempts\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Optional_Rate-Limit_SSH_Attempts\"><\/span>Optional: Rate-Limit SSH Attempts<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Alternatively, if you need SSH accessible from changing IPs, replace the broad allow rule with a connection-rate limit:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw limit 22\/tcp\nsudo ufw delete allow 22\/tcp\nsudo ufw status numbered<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Only do this after confirming a working SSH connection and recovery access; use your actual SSH port instead of 22 if different. Test another login afterward. This is an <strong>alternative<\/strong> to IP-only access, not something to combine with it. Rate limiting doesn&#8217;t replace SSH key authentication.<\/p>\n\n\n\n<h2 id=\"h-step-7-check-logs-and-troubleshoot-access\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_7_Check_Logs_and_Troubleshoot_Access\"><\/span>Step 7: Check Logs and Troubleshoot Access<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Enable basic logging when you need to investigate blocked traffic:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw logging on\nsudo ufw status verbose<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">UFW logs may be available in the system journal or <code>\/var\/log\/ufw.log<\/code>, depending on your logging setup.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If SSH becomes unreachable, use your provider&#8217;s <strong>recovery console<\/strong> to inspect the active rules. As a temporary emergency measure, <code>sudo ufw disable<\/code> stops enforcement; correct the SSH rule and enable UFW again.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your website fails to load, check listening services with <code>sudo ss -ltnp<\/code>, UFW&#8217;s rules, and any provider firewall. Opening a port does not start the service behind it.<\/p>\n\n\n\n<h2 id=\"h-frequently-asked-questions\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1793901025290\"><strong class=\"schema-faq-question\">Does the Ubuntu firewall start automatically after a reboot?<\/strong> <p class=\"schema-faq-answer\">Yes. Once you run sudo ufw enable, UFW is enabled for subsequent boots. Check its configuration with sudo ufw status verbose.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1793901239112\"><strong class=\"schema-faq-question\">Do I need to restart Ubuntu after changing UFW rules?<\/strong> <p class=\"schema-faq-answer\">No. Rules added or removed through UFW take effect without rebooting the VPS. You can inspect the current configuration immediately.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1793901250570\"><strong class=\"schema-faq-question\">Does the UFW firewall protect Docker containers?<\/strong> <p class=\"schema-faq-answer\">Not necessarily. Docker-published ports can bypass ordinary UFW input rules because Docker configures its own networking rules. Review Docker&#8217;s firewall documentation before relying on UFW to restrict container access.<\/p> <\/div> <\/div>\n\n\n\n<h2 id=\"h-conclusion\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A secure <strong>Ubuntu firewall<\/strong> setup with UFW starts by allowing SSH, applying a default-deny incoming policy, and opening only the ports your applications need. After enabling UFW, verify access from a separate connection and remove obsolete rules as your VPS changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">UFW handles network access, not application-level abuse. For public Nginx websites, <a href=\"https:\/\/zynoo.com\/blog\/nginx-rate-limiting\/\">request rate limiting<\/a> is a useful additional safeguard.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Configuring the Ubuntu firewall with UFW (Uncomplicated Firewall) helps protect your VPS by allowing essential connections and blocking unnecessary incoming traffic. The setup takes only a few commands, but their order matters: allow SSH before enabling the firewall, or you could lose remote access. This tutorial shows how to install UFW, configure safe defaults, open [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":6153,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"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":"","ast-disable-related-posts":"","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":"","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":[499],"tags":[],"class_list":["post-6138","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v28.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Ubuntu Firewall: How to Set Up UFW on a VPS<\/title>\n<meta name=\"description\" content=\"Learn how to configure the Ubuntu firewall using UFW. Set up secure SSH access, allow ports, manage rules, and protect your VPS step by step.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ubuntu Firewall: How to Set Up UFW on a VPS\" \/>\n<meta property=\"og:description\" content=\"Learn how to configure the Ubuntu firewall using UFW. Set up secure SSH access, allow ports, manage rules, and protect your VPS step by step.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/\" \/>\n<meta property=\"og:site_name\" content=\"ZYNOO Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-03T18:00:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-05T19:46:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/ubuntu-firewall.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1672\" \/>\n\t<meta property=\"og:image:height\" content=\"941\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Adam Weller\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Adam Weller\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/\"},\"author\":{\"name\":\"Adam Weller\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/#\\\/schema\\\/person\\\/dc0f08d1e3da74e3d4ae21a072525738\"},\"headline\":\"Ubuntu Firewall: How to Set Up UFW on a VPS\",\"datePublished\":\"2026-11-03T18:00:07+00:00\",\"dateModified\":\"2026-11-05T19:46:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/\"},\"wordCount\":1098,\"publisher\":{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/ubuntu-firewall.webp\",\"articleSection\":[\"Linux Tutorials\"],\"inLanguage\":\"en-US\"},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/\",\"url\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/\",\"name\":\"Ubuntu Firewall: How to Set Up UFW on a VPS\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/ubuntu-firewall.webp\",\"datePublished\":\"2026-11-03T18:00:07+00:00\",\"dateModified\":\"2026-11-05T19:46:36+00:00\",\"description\":\"Learn how to configure the Ubuntu firewall using UFW. Set up secure SSH access, allow ports, manage rules, and protect your VPS step by step.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#faq-question-1793901025290\"},{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#faq-question-1793901239112\"},{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#faq-question-1793901250570\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#primaryimage\",\"url\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/ubuntu-firewall.webp\",\"contentUrl\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/ubuntu-firewall.webp\",\"width\":1672,\"height\":941,\"caption\":\"ubuntu firewall\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux Tutorials\",\"item\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/category\\\/linux-tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Ubuntu Firewall: How to Set Up UFW on a VPS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/\",\"name\":\"Zynoo Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/#organization\",\"name\":\"ZYNOO\",\"url\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/logo.png\",\"contentUrl\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/logo.png\",\"width\":149,\"height\":31,\"caption\":\"ZYNOO\"},\"image\":{\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/#\\\/schema\\\/person\\\/dc0f08d1e3da74e3d4ae21a072525738\",\"name\":\"Adam Weller\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/adam-weller-v2-96x96.jpg\",\"url\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/adam-weller-v2-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/adam-weller-v2-96x96.jpg\",\"caption\":\"Adam Weller\"},\"description\":\"Adam Weller covers web hosting, Linux and online projects for the ZYNOO blog.\",\"url\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/author\\\/adam-weller\\\/\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#faq-question-1793901025290\",\"position\":1,\"url\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#faq-question-1793901025290\",\"name\":\"Does the Ubuntu firewall start automatically after a reboot?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes. Once you run sudo ufw enable, UFW is enabled for subsequent boots. Check its configuration with sudo ufw status verbose.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#faq-question-1793901239112\",\"position\":2,\"url\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#faq-question-1793901239112\",\"name\":\"Do I need to restart Ubuntu after changing UFW rules?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. Rules added or removed through UFW take effect without rebooting the VPS. You can inspect the current configuration immediately.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#faq-question-1793901250570\",\"position\":3,\"url\":\"https:\\\/\\\/zynoo.com\\\/blog\\\/ubuntu-firewall-ufw\\\/#faq-question-1793901250570\",\"name\":\"Does the UFW firewall protect Docker containers?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Not necessarily. Docker-published ports can bypass ordinary UFW input rules because Docker configures its own networking rules. Review Docker's firewall documentation before relying on UFW to restrict container access.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Ubuntu Firewall: How to Set Up UFW on a VPS","description":"Learn how to configure the Ubuntu firewall using UFW. Set up secure SSH access, allow ports, manage rules, and protect your VPS step by step.","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:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/","og_locale":"en_US","og_type":"article","og_title":"Ubuntu Firewall: How to Set Up UFW on a VPS","og_description":"Learn how to configure the Ubuntu firewall using UFW. Set up secure SSH access, allow ports, manage rules, and protect your VPS step by step.","og_url":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/","og_site_name":"ZYNOO Blog","article_published_time":"2026-11-03T18:00:07+00:00","article_modified_time":"2026-11-05T19:46:36+00:00","og_image":[{"width":1672,"height":941,"url":"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/ubuntu-firewall.webp","type":"image\/webp"}],"author":"Adam Weller","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Adam Weller","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#article","isPartOf":{"@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/"},"author":{"name":"Adam Weller","@id":"https:\/\/zynoo.com\/blog\/#\/schema\/person\/dc0f08d1e3da74e3d4ae21a072525738"},"headline":"Ubuntu Firewall: How to Set Up UFW on a VPS","datePublished":"2026-11-03T18:00:07+00:00","dateModified":"2026-11-05T19:46:36+00:00","mainEntityOfPage":{"@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/"},"wordCount":1098,"publisher":{"@id":"https:\/\/zynoo.com\/blog\/#organization"},"image":{"@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#primaryimage"},"thumbnailUrl":"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/ubuntu-firewall.webp","articleSection":["Linux Tutorials"],"inLanguage":"en-US"},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/","url":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/","name":"Ubuntu Firewall: How to Set Up UFW on a VPS","isPartOf":{"@id":"https:\/\/zynoo.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#primaryimage"},"image":{"@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#primaryimage"},"thumbnailUrl":"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/ubuntu-firewall.webp","datePublished":"2026-11-03T18:00:07+00:00","dateModified":"2026-11-05T19:46:36+00:00","description":"Learn how to configure the Ubuntu firewall using UFW. Set up secure SSH access, allow ports, manage rules, and protect your VPS step by step.","breadcrumb":{"@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#faq-question-1793901025290"},{"@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#faq-question-1793901239112"},{"@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#faq-question-1793901250570"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#primaryimage","url":"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/ubuntu-firewall.webp","contentUrl":"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/ubuntu-firewall.webp","width":1672,"height":941,"caption":"ubuntu firewall"},{"@type":"BreadcrumbList","@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/zynoo.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Linux Tutorials","item":"https:\/\/zynoo.com\/blog\/category\/linux-tutorials\/"},{"@type":"ListItem","position":3,"name":"Ubuntu Firewall: How to Set Up UFW on a VPS"}]},{"@type":"WebSite","@id":"https:\/\/zynoo.com\/blog\/#website","url":"https:\/\/zynoo.com\/blog\/","name":"Zynoo Blog","description":"","publisher":{"@id":"https:\/\/zynoo.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/zynoo.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/zynoo.com\/blog\/#organization","name":"ZYNOO","url":"https:\/\/zynoo.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zynoo.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2025\/08\/logo.png","contentUrl":"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2025\/08\/logo.png","width":149,"height":31,"caption":"ZYNOO"},"image":{"@id":"https:\/\/zynoo.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/zynoo.com\/blog\/#\/schema\/person\/dc0f08d1e3da74e3d4ae21a072525738","name":"Adam Weller","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/adam-weller-v2-96x96.jpg","url":"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/adam-weller-v2-96x96.jpg","contentUrl":"https:\/\/zynoo.com\/blog\/wp-content\/uploads\/2026\/11\/adam-weller-v2-96x96.jpg","caption":"Adam Weller"},"description":"Adam Weller covers web hosting, Linux and online projects for the ZYNOO blog.","url":"https:\/\/zynoo.com\/blog\/author\/adam-weller\/"},{"@type":"Question","@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#faq-question-1793901025290","position":1,"url":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#faq-question-1793901025290","name":"Does the Ubuntu firewall start automatically after a reboot?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes. Once you run sudo ufw enable, UFW is enabled for subsequent boots. Check its configuration with sudo ufw status verbose.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#faq-question-1793901239112","position":2,"url":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#faq-question-1793901239112","name":"Do I need to restart Ubuntu after changing UFW rules?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"No. Rules added or removed through UFW take effect without rebooting the VPS. You can inspect the current configuration immediately.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#faq-question-1793901250570","position":3,"url":"https:\/\/zynoo.com\/blog\/ubuntu-firewall-ufw\/#faq-question-1793901250570","name":"Does the UFW firewall protect Docker containers?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Not necessarily. Docker-published ports can bypass ordinary UFW input rules because Docker configures its own networking rules. Review Docker's firewall documentation before relying on UFW to restrict container access.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/zynoo.com\/blog\/wp-json\/wp\/v2\/posts\/6138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zynoo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zynoo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zynoo.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/zynoo.com\/blog\/wp-json\/wp\/v2\/comments?post=6138"}],"version-history":[{"count":6,"href":"https:\/\/zynoo.com\/blog\/wp-json\/wp\/v2\/posts\/6138\/revisions"}],"predecessor-version":[{"id":6420,"href":"https:\/\/zynoo.com\/blog\/wp-json\/wp\/v2\/posts\/6138\/revisions\/6420"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zynoo.com\/blog\/wp-json\/wp\/v2\/media\/6153"}],"wp:attachment":[{"href":"https:\/\/zynoo.com\/blog\/wp-json\/wp\/v2\/media?parent=6138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zynoo.com\/blog\/wp-json\/wp\/v2\/categories?post=6138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zynoo.com\/blog\/wp-json\/wp\/v2\/tags?post=6138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}