{"id":234,"date":"2026-06-03T23:20:58","date_gmt":"2026-06-04T06:20:58","guid":{"rendered":"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/"},"modified":"2026-06-03T23:20:58","modified_gmt":"2026-06-04T06:20:58","slug":"how-to-configure-firewall-on-vps","status":"publish","type":"post","link":"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/","title":{"rendered":"How to Configure a Firewall on Your VPS (iptables &amp; UFW)"},"content":{"rendered":"<h2>Overview<\/h2>\n<p>Every VPS is exposed to the public internet the moment it&#8217;s provisioned. Without a firewall, any port your server happens to be listening on is reachable by anyone. That includes SSH, database ports, admin panels \u2014 all of it. A VPS firewall is your first line of defence, controlling exactly which traffic is allowed in and out.<\/p>\n<p>Linux gives you two main tools for this: <strong>iptables<\/strong>, the low-level kernel firewall, and <strong>UFW (Uncomplicated Firewall)<\/strong>, a frontend that makes iptables far more manageable. Most users on Ubuntu or Debian should start with UFW. If you&#8217;re on CentOS\/AlmaLinux\/Rocky Linux, you&#8217;ll likely be working with <code class=\"\" data-line=\"\">firewalld<\/code> or raw iptables. This guide covers both UFW and iptables so you can apply whichever fits your setup.<\/p>\n<p>If you&#8217;re running a <a href=\"https:\/\/www.hostandtech.com\/vps-ssd-servers\">VPS SSD Hosting<\/a> plan from Host &amp; Tech, your server comes without a preconfigured firewall by default on unmanaged plans \u2014 so this setup is on you. Don&#8217;t skip it.<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li>Root or sudo access to your Linux VPS<\/li>\n<li>SSH access confirmed and working before you start<\/li>\n<li>OS: Ubuntu 20.04\/22.04\/24.04, Debian 11\/12, CentOS 7\/8, AlmaLinux 8\/9, or Rocky Linux 8\/9<\/li>\n<li>Basic comfort with a terminal and text editor (<code class=\"\" data-line=\"\">nano<\/code> is fine)<\/li>\n<li>Your current IP address handy \u2014 you&#8217;ll need it to whitelist SSH access<\/li>\n<\/ul>\n<h2>Option A: Configure a Firewall Using UFW (Ubuntu\/Debian)<\/h2>\n<p>UFW ships with Ubuntu and most Debian-based systems. It&#8217;s the right tool for most VPS users who don&#8217;t need fine-grained packet filtering.<\/p>\n<h3>Step 1: Check UFW Status and Install If Needed<\/h3>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-1\"><code class=\"\" data-line=\"\">sudo ufw status\nsudo apt install ufw -y   # only if not already installed<\/code><\/pre>\n<\/div>\n<p>If UFW shows <code class=\"\" data-line=\"\">Status: inactive<\/code>, that&#8217;s expected \u2014 you haven&#8217;t enabled it yet.<\/p>\n<h3>Step 2: Set Default Policies<\/h3>\n<p>Before enabling UFW, set the defaults. This tells UFW to deny all incoming traffic and allow all outgoing traffic unless you explicitly say otherwise.<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-2\"><code class=\"\" data-line=\"\">sudo ufw default deny incoming\nsudo ufw default allow outgoing<\/code><\/pre>\n<\/div>\n<p>\u26a0 <strong>Warning:<\/strong> Do NOT run <code class=\"\" data-line=\"\">sudo ufw enable<\/code> yet. If you haven&#8217;t allowed SSH, you&#8217;ll lock yourself out immediately. Complete the next step first.<\/p>\n<h3>Step 3: Allow SSH<\/h3>\n<p>If you&#8217;re on the standard port 22:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-3\"><code class=\"\" data-line=\"\">sudo ufw allow 22\/tcp<\/code><\/pre>\n<\/div>\n<p>If you&#8217;ve already moved SSH to a custom port (e.g. 2222), use that instead:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-4\"><code class=\"\" data-line=\"\">sudo ufw allow 2222\/tcp<\/code><\/pre>\n<\/div>\n<p>\ud83d\udcdd <strong>Note:<\/strong> You can restrict SSH to your specific IP for tighter security: <code class=\"\" data-line=\"\">sudo ufw allow from 203.0.113.45 to any port 22<\/code>. Replace <code class=\"\" data-line=\"\">203.0.113.45<\/code> with your actual IP. If your ISP gives you a dynamic IP, be careful \u2014 you can lock yourself out after a reconnect.<\/p>\n<h3>Step 4: Allow Any Other Required Services<\/h3>\n<p>Add rules for whatever your server actually runs. Common examples:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-5\"><code class=\"\" data-line=\"\"># Web server\nsudo ufw allow 80\/tcp\nsudo ufw allow 443\/tcp\n\n# Mail server\nsudo ufw allow 25\/tcp\nsudo ufw allow 587\/tcp\nsudo ufw allow 993\/tcp\n\n# MySQL (only if remote connections needed \u2014 ideally leave this closed)\nsudo ufw allow from 203.0.113.50 to any port 3306<\/code><\/pre>\n<\/div>\n<p>I&#8217;d recommend keeping port 3306 (MySQL) and 5432 (PostgreSQL) closed to the public entirely. If your app runs on the same server, it connects via <code class=\"\" data-line=\"\">localhost<\/code> and doesn&#8217;t need a public firewall rule.<\/p>\n<h3>Step 5: Enable UFW<\/h3>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-6\"><code class=\"\" data-line=\"\">sudo ufw enable<\/code><\/pre>\n<\/div>\n<p>You&#8217;ll see a confirmation prompt. Type <code class=\"\" data-line=\"\">y<\/code> and press Enter. UFW is now active and will persist across reboots.<\/p>\n<h3>Step 6: Verify Your Rules<\/h3>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-7\"><code class=\"\" data-line=\"\">sudo ufw status verbose<\/code><\/pre>\n<\/div>\n<p>This shows every rule currently active, including direction and protocol. Check that SSH is listed before closing your terminal session.<\/p>\n<hr>\n<h2>Option B: Configure a Firewall Using iptables<\/h2>\n<p>iptables gives you more control but requires more care. If you&#8217;re on CentOS 7 or managing a server where UFW isn&#8217;t available, here&#8217;s a working baseline ruleset.<\/p>\n<h3>Step 1: View Current Rules<\/h3>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-8\"><code class=\"\" data-line=\"\">sudo iptables -L -v -n<\/code><\/pre>\n<\/div>\n<h3>Step 2: Flush Existing Rules (Clean Slate)<\/h3>\n<p>\u26a0 <strong>Warning:<\/strong> This wipes all existing iptables rules immediately. Only run this if you&#8217;re starting fresh and have console access as a backup in case SSH drops.<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-9\"><code class=\"\" data-line=\"\">sudo iptables -F\nsudo iptables -X\nsudo iptables -Z<\/code><\/pre>\n<\/div>\n<h3>Step 3: Set Default Policies and Core Rules<\/h3>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-10\"><code class=\"\" data-line=\"\"># Allow established sessions to continue\nsudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT\n\n# Allow loopback interface\nsudo iptables -A INPUT -i lo -j ACCEPT\n\n# Allow SSH\nsudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT\n\n# Allow HTTP and HTTPS\nsudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT\nsudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT\n\n# Drop everything else\nsudo iptables -P INPUT DROP\nsudo iptables -P FORWARD DROP\nsudo iptables -P OUTPUT ACCEPT<\/code><\/pre>\n<\/div>\n<p>The <code class=\"\" data-line=\"\">ESTABLISHED,RELATED<\/code> rule at the top is one beginners often miss. Without it, your server can initiate connections but can&#8217;t receive the responses \u2014 which breaks things like <code class=\"\" data-line=\"\">apt update<\/code> and outbound API calls.<\/p>\n<h3>Step 4: Save Rules So They Persist After Reboot<\/h3>\n<p>iptables rules are lost on reboot unless you save them. On Debian\/Ubuntu:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-11\"><code class=\"\" data-line=\"\">sudo apt install iptables-persistent -y\nsudo netfilter-persistent save<\/code><\/pre>\n<\/div>\n<p>On CentOS\/AlmaLinux\/Rocky Linux:<\/p>\n<div class=\"ht-code-snippet\"><button class=\"ht-code-snippet__copy\" type=\"button\" aria-label=\"Copy code\"><\/button><span class=\"ht-code-snippet__feedback\">Copied to clipboard<\/span><\/p>\n<pre class=\"ht-code-snippet__code\" id=\"code-block-12\"><code class=\"\" data-line=\"\">sudo service iptables save<\/code><\/pre>\n<\/div>\n<p>\ud83d\udcdd <strong>Note:<\/strong> On CentOS 7+, <code class=\"\" data-line=\"\">firewalld<\/code> is the default and conflicts with direct iptables management. Either use <code class=\"\" data-line=\"\">firewalld<\/code> exclusively or disable it first with <code class=\"\" data-line=\"\">sudo systemctl disable --now firewalld<\/code> before working with iptables directly.<\/p>\n<hr>\n<h2>Common Issues &amp; Troubleshooting<\/h2>\n<h3>Locked Out of SSH After Enabling UFW<\/h3>\n<p>You enabled UFW before adding an SSH rule. Your existing session may still be alive, but any new SSH connection will be refused. If you&#8217;re still connected, run <code class=\"\" data-line=\"\">sudo ufw allow 22\/tcp<\/code> immediately. If you&#8217;re fully locked out, use your VPS provider&#8217;s out-of-band console (at Host &amp; Tech this is available in the client portal under &#8220;VPS Console&#8221;) to regain access and fix the rules without needing SSH.<\/p>\n<h3>UFW Rules Exist But Traffic Is Still Blocked<\/h3>\n<p>UFW sits on top of iptables. If another tool \u2014 like Docker, <code class=\"\" data-line=\"\">fail2ban<\/code>, or a control panel like cPanel\/WHM \u2014 has injected its own iptables rules, those can override or conflict with UFW. Run <code class=\"\" data-line=\"\">sudo iptables -L -v -n<\/code> and look for DROP or REJECT rules appearing before your ACCEPT rules in the INPUT chain. Docker in particular inserts its own rules aggressively and can punch holes in your firewall you didn&#8217;t intend.<\/p>\n<h3>iptables Rules Lost After Reboot<\/h3>\n<p>You forgot to save them. iptables rules live in memory by default. Install <code class=\"\" data-line=\"\">iptables-persistent<\/code> on Debian\/Ubuntu systems and run <code class=\"\" data-line=\"\">sudo netfilter-persistent save<\/code>. On Red Hat-based systems, <code class=\"\" data-line=\"\">sudo service iptables save<\/code> writes rules to <code class=\"\" data-line=\"\">\/etc\/sysconfig\/iptables<\/code>.<\/p>\n<h3>Port Is Allowed in UFW But App Still Can&#8217;t Connect<\/h3>\n<p>The firewall isn&#8217;t always the issue. Check whether your application is actually listening on that port with <code class=\"\" data-line=\"\">sudo ss -tlnp | grep LISTEN<\/code>. If the port doesn&#8217;t appear, the app isn&#8217;t running or is bound to <code class=\"\" data-line=\"\">127.0.0.1<\/code> only (which means it&#8217;s intentionally refusing external connections). A firewall rule won&#8217;t fix a binding issue.<\/p>\n<h3>UFW Showing &#8220;ERROR: Could not load logging rules&#8221;<\/h3>\n<p>This usually appears on OpenVZ-based VPS containers where kernel modules for logging aren&#8217;t available. It&#8217;s mostly cosmetic \u2014 UFW&#8217;s filtering rules still apply. If you&#8217;re seeing this and need proper logging, you may need a KVM-based VPS, which has full kernel access. Host &amp; Tech VPS plans use KVM virtualisation, so this error is typically absent on our infrastructure.<\/p>\n<hr>\n<h2>FAQ<\/h2>\n<div class=\"ht-faq-section\">\n<h2>Frequently Asked Questions<\/h2>\n<div class=\"ht-faq-item\">\n<h3 class=\"ht-faq-question\">Should I use UFW or iptables on my VPS?<\/h3>\n<div class=\"ht-faq-answer\">\n<p>UFW is the better choice for most people. It&#8217;s easier to manage, less likely to result in a misconfiguration that locks you out, and perfectly capable for the vast majority of VPS use cases. Use iptables directly only if you need custom packet filtering, NAT rules, or are working in an environment where UFW isn&#8217;t available.<\/p>\n<\/div>\n<\/div>\n<div class=\"ht-faq-item\">\n<h3 class=\"ht-faq-question\">Does enabling a firewall affect my VPS performance?<\/h3>\n<div class=\"ht-faq-answer\">\n<p>In practice, no \u2014 not in any way you&#8217;d notice. Firewall rule evaluation happens at the kernel level and the overhead is negligible for typical VPS workloads. The only time firewall rules affect performance is with very high packet-per-second traffic on extremely busy servers, which is a dedicated server concern, not a standard VPS one.<\/p>\n<\/div>\n<\/div>\n<div class=\"ht-faq-item\">\n<h3 class=\"ht-faq-question\">How do I open a port in UFW?<\/h3>\n<div class=\"ht-faq-answer\">\n<p>Run <code class=\"\" data-line=\"\">sudo ufw allow PORT\/tcp<\/code>, replacing PORT with the port number you need. For example, <code class=\"\" data-line=\"\">sudo ufw allow 8080\/tcp<\/code> opens port 8080 for TCP traffic. Run <code class=\"\" data-line=\"\">sudo ufw status<\/code> afterwards to confirm the rule is active. You don&#8217;t need to restart UFW \u2014 rules take effect immediately.<\/p>\n<\/div>\n<\/div>\n<div class=\"ht-faq-item\">\n<h3 class=\"ht-faq-question\">Is a VPS-level firewall enough, or do I need something else?<\/h3>\n<div class=\"ht-faq-answer\">\n<p>A host-based firewall like UFW or iptables is essential, but it&#8217;s one layer. For a more complete setup, also consider a network-level firewall (some VPS providers offer this as a separate product), disabling unused services, keeping software updated, and using fail2ban to block brute-force SSH attempts. Security is layered, not a single switch.<\/p>\n<\/div>\n<\/div>\n<div class=\"ht-faq-item\">\n<h3 class=\"ht-faq-question\">Will my firewall rules survive a VPS reboot?<\/h3>\n<div class=\"ht-faq-answer\">\n<p>With UFW, yes \u2014 rules persist automatically once UFW is enabled. With raw iptables, you need to explicitly save your rules using <code class=\"\" data-line=\"\">netfilter-persistent save<\/code> on Debian\/Ubuntu or <code class=\"\" data-line=\"\">service iptables save<\/code> on CentOS\/AlmaLinux, otherwise they&#8217;re wiped on reboot. This is one of the most common mistakes when setting up iptables manually.<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>A misconfigured firewall is one of the fastest ways to either lock yourself out of your VPS or leave it wide open to attacks. This guide walks you through setting up a firewall using UFW or iptables on a Linux VPS, with real-world rules and common pitfalls covered.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","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":"default","ast-page-background-enabled":"default","ast-page-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":"","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-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":"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":""},"mobile":{"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":""}},"footnotes":""},"categories":[3],"tags":[313,689,688,75,21,76,686,687],"class_list":["post-234","post","type-post","status-publish","format-standard","hentry","category-vps","tag-firewall-rules","tag-how-to-configure-a-firewall-on-your-vps","tag-how-to-configure-a-firewall-on-your-vps-iptables-ufw","tag-iptables","tag-linux-security","tag-ufw","tag-vps-firewall","tag-vps-hardening"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Configure a Firewall on Your VPS (iptables &amp; UFW)<\/title>\n<meta name=\"description\" content=\"Learn how to configure a VPS firewall using iptables and UFW. Step-by-step setup, common mistakes, and troubleshooting for Linux VPS servers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/\" \/>\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 on Your VPS (iptables &amp; UFW)\" \/>\n<meta property=\"og:description\" content=\"Learn how to configure a VPS firewall using iptables and UFW. Step-by-step setup, common mistakes, and troubleshooting for Linux VPS servers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/\" \/>\n<meta property=\"og:site_name\" content=\"Host And Tech knowledge base\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/stshostandtech\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-04T06:20:58+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@stshostandtech\" \/>\n<meta name=\"twitter:site\" content=\"@stshostandtech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/vps\\\/how-to-configure-firewall-on-vps\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/vps\\\/how-to-configure-firewall-on-vps\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/person\\\/b6fa79c48ddaba71af32e395c5b017ee\"},\"headline\":\"How to Configure a Firewall on Your VPS (iptables &amp; UFW)\",\"datePublished\":\"2026-06-04T06:20:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/vps\\\/how-to-configure-firewall-on-vps\\\/\"},\"wordCount\":1288,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#organization\"},\"keywords\":[\"firewall rules\",\"How to Configure a Firewall on Your VPS\",\"How to Configure a Firewall on Your VPS (iptables &amp; UFW)\",\"iptables\",\"Linux security\",\"ufw\",\"VPS firewall\",\"VPS hardening\"],\"articleSection\":[\"VPS Hosting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/hostandtech.com\\\/kb\\\/vps\\\/how-to-configure-firewall-on-vps\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/vps\\\/how-to-configure-firewall-on-vps\\\/\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/vps\\\/how-to-configure-firewall-on-vps\\\/\",\"name\":\"How to Configure a Firewall on Your VPS (iptables & UFW)\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#website\"},\"datePublished\":\"2026-06-04T06:20:58+00:00\",\"description\":\"Learn how to configure a VPS firewall using iptables and UFW. Step-by-step setup, common mistakes, and troubleshooting for Linux VPS servers.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/vps\\\/how-to-configure-firewall-on-vps\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/hostandtech.com\\\/kb\\\/vps\\\/how-to-configure-firewall-on-vps\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/vps\\\/how-to-configure-firewall-on-vps\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Configure a Firewall on Your VPS (iptables &amp; UFW)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/\",\"name\":\"Host And Tech knowledge base\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#organization\",\"name\":\"Host And Tech knowledge base\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/wp-content\\\/uploads\\\/2026\\\/05\\\/logo-dark.png\",\"contentUrl\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/wp-content\\\/uploads\\\/2026\\\/05\\\/logo-dark.png\",\"width\":1134,\"height\":395,\"caption\":\"Host And Tech knowledge base\"},\"image\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/stshostandtech\",\"https:\\\/\\\/x.com\\\/stshostandtech\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/person\\\/b6fa79c48ddaba71af32e395c5b017ee\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/hostandtech.com\\\/kb\"],\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/author\\\/admin_fjj7qydm\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Configure a Firewall on Your VPS (iptables & UFW)","description":"Learn how to configure a VPS firewall using iptables and UFW. Step-by-step setup, common mistakes, and troubleshooting for Linux VPS servers.","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:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/","og_locale":"en_US","og_type":"article","og_title":"How to Configure a Firewall on Your VPS (iptables & UFW)","og_description":"Learn how to configure a VPS firewall using iptables and UFW. Step-by-step setup, common mistakes, and troubleshooting for Linux VPS servers.","og_url":"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/","og_site_name":"Host And Tech knowledge base","article_publisher":"https:\/\/www.facebook.com\/stshostandtech","article_published_time":"2026-06-04T06:20:58+00:00","author":"admin","twitter_card":"summary_large_image","twitter_creator":"@stshostandtech","twitter_site":"@stshostandtech","twitter_misc":{"Written by":"admin","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/#article","isPartOf":{"@id":"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/"},"author":{"name":"admin","@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/person\/b6fa79c48ddaba71af32e395c5b017ee"},"headline":"How to Configure a Firewall on Your VPS (iptables &amp; UFW)","datePublished":"2026-06-04T06:20:58+00:00","mainEntityOfPage":{"@id":"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/"},"wordCount":1288,"commentCount":0,"publisher":{"@id":"https:\/\/hostandtech.com\/kb\/#organization"},"keywords":["firewall rules","How to Configure a Firewall on Your VPS","How to Configure a Firewall on Your VPS (iptables &amp; UFW)","iptables","Linux security","ufw","VPS firewall","VPS hardening"],"articleSection":["VPS Hosting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/","url":"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/","name":"How to Configure a Firewall on Your VPS (iptables & UFW)","isPartOf":{"@id":"https:\/\/hostandtech.com\/kb\/#website"},"datePublished":"2026-06-04T06:20:58+00:00","description":"Learn how to configure a VPS firewall using iptables and UFW. Step-by-step setup, common mistakes, and troubleshooting for Linux VPS servers.","breadcrumb":{"@id":"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/hostandtech.com\/kb\/vps\/how-to-configure-firewall-on-vps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/hostandtech.com\/kb\/"},{"@type":"ListItem","position":2,"name":"How to Configure a Firewall on Your VPS (iptables &amp; UFW)"}]},{"@type":"WebSite","@id":"https:\/\/hostandtech.com\/kb\/#website","url":"https:\/\/hostandtech.com\/kb\/","name":"Host And Tech knowledge base","description":"","publisher":{"@id":"https:\/\/hostandtech.com\/kb\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/hostandtech.com\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/hostandtech.com\/kb\/#organization","name":"Host And Tech knowledge base","url":"https:\/\/hostandtech.com\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/hostandtech.com\/kb\/wp-content\/uploads\/2026\/05\/logo-dark.png","contentUrl":"https:\/\/hostandtech.com\/kb\/wp-content\/uploads\/2026\/05\/logo-dark.png","width":1134,"height":395,"caption":"Host And Tech knowledge base"},"image":{"@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/stshostandtech","https:\/\/x.com\/stshostandtech"]},{"@type":"Person","@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/person\/b6fa79c48ddaba71af32e395c5b017ee","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/hostandtech.com\/kb"],"url":"https:\/\/hostandtech.com\/kb\/author\/admin_fjj7qydm\/"}]}},"_links":{"self":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/posts\/234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/comments?post=234"}],"version-history":[{"count":0,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/posts\/234\/revisions"}],"wp:attachment":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/media?parent=234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/categories?post=234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/tags?post=234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}