{"id":1548,"date":"2026-01-01T21:15:33","date_gmt":"2026-01-01T21:15:33","guid":{"rendered":"https:\/\/b2bhostingclub.com\/blog\/?p=1548"},"modified":"2026-02-04T14:14:37","modified_gmt":"2026-02-04T14:14:37","slug":"how-to-configure-a-linux-vps-firewall-with-iptables","status":"publish","type":"post","link":"https:\/\/b2bhostingclub.com\/blog\/how-to-configure-a-linux-vps-firewall-with-iptables\/","title":{"rendered":"How to Configure a Linux VPS Firewall with IPTables"},"content":{"rendered":"<div class=\"d-title pt-10 pb-0\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-left d-text-left d-title-inner\">\n<h2 id=\"introduction\" class=\"col col-md-10 d-h2 d-color-black  core-title\">Introduction<\/h2>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Securing your Linux VPS with a firewall is an important step to protect it from unauthorized access and attacks. IPTables is the built-in Linux firewall solution that allows you to filter incoming and outgoing traffic. This article will walk you through step-by-step how to configure an IPTables firewall on your Linux VPS.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">In this article, we will show you how to configure a Linux VPS firewall using IPTables. IPTables is a powerful firewall utility that is included with most Linux distributions. It can be used to create a variety of firewall rules, including rules that allow or deny traffic based on source and destination IP addresses, port numbers, and protocols.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-title pt-10 pb-0\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-left d-text-left d-title-inner\">\n<h2 id=\"requirements\" class=\"col col-md-10 d-h2 d-color-black  core-title\">Requirements<\/h2>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">A\u00a0<a class=\"d-color-primary\" title=\"Linux VPS Hosting\" href=\"https:\/\/b2bhostingclub.com\/linux-vps.php\">Linux VPS<\/a> from B2BHOSTINGCLUB<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Administrative access (root\/sudo) to your server via SSH<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-title pt-10 pb-0\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-left d-text-left d-title-inner\">\n<h2 id=\"understanding-iptables\" class=\"col col-md-10 d-h2 d-color-black  core-title\">Understanding IPTables<\/h2>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Before configuring IPTables rules, it&#8217;s important to understand some basics about how it works. IPTables manages the tables in the Linux kernel that contain the firewall rules. There are three main tables:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\"><b>INPUT<\/b>\u00a0&#8211; Rules that apply to inbound traffic destined for the VPS itself.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\"><b>OUTPUT<\/b>\u00a0&#8211; Rules that apply to outbound traffic leaving from the VPS.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\"><b>FORWARD<\/b>\u00a0&#8211; Rules that apply to traffic that is routed through the VPS but not destined for it.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Within each table, there are built-in chains that contain the actual rules:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\"><b>PREROUTING<\/b>\u00a0&#8211; Rules that apply before the routing process.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\"><b>INPUT<\/b>\u00a0&#8211; Rules for inbound traffic.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\"><b>FORWARD<\/b>\u00a0&#8211; Rules for forwarded traffic.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\"><b>OUTPUT<\/b>\u00a0&#8211; Rules for outbound traffic.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\"><b>POSTROUTING<\/b>\u00a0&#8211; Rules that apply after the routing process.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Each rule contains three main parts:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\"><b>A chain<\/b>\u00a0&#8211; Which table and chain the rule applies to.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\"><b>A filter<\/b>\u00a0&#8211; Whether to ACCEPT, DROP or REJECT the packets.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\"><b>Match criteria<\/b>\u00a0&#8211; Which packets the rule applies to based on things like protocols, ports, source\/destination IPs, etc.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-title\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-left d-text-left d-title-inner\">\n<h2 id=\"configuring-a-linux-vps-firewall-with-iptables\" class=\"col col-md-10 d-h2 d-color-black  core-title\">Configuring a Linux VPS Firewall with IPTables<\/h2>\n<div class=\"col col-md-10 d-color-black  d-fs-normal d-fw-500\">With this understanding, we can now start configuring rules to lock down our VPS firewall.<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 1) Install and Enable IPTables<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">On most Linux distributions, IPTables comes pre-installed. However, we&#8217;ll first ensure it&#8217;s installed and enabled. We can install IPTables using:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo apt install iptables  # For Debian\/Ubuntu\r\nsudo yum install iptables  # For CentOS\/Red Hat<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Then we can enable the IPTables service to start on boot with:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo systemctl enable iptables<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">And start the service now with:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo systemctl start iptables<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 2) Flush Existing Rules<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Before adding our own rules, we&#8217;ll flush any existing rules that may be present with:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo iptables -F<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">This will flush all rules from all chains to ensure we have a clean slate.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 3) Allow localhost Traffic<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Next, we&#8217;ll add rules to allow traffic to and from localhost (our VPS itself). This is needed for applications to communicate internally. We&#8217;ll add these rules:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo iptables -A INPUT -i lo -j ACCEPT\r\nsudo iptables -A OUTPUT -o lo -j ACCEPT<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">This will accept all input and output traffic on the lo interface (localhost).<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 4) Block INVALID Packets<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">We&#8217;ll add rules to drop any INVALID packets that may be used in DoS attacks or fingerprinting. These packets are very unlikely to be legitimate.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo iptables -A INPUT -m conntrack --ctstate INVALID -j DROP\r\nsudo iptables -A FORWARD -m conntrack --ctstate INVALID -j DROP\r\nsudo iptables -A OUTPUT -m conntrack --ctstate INVALID -j DROP<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 5) Allow Established Connections<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Now we&#8217;ll allow incoming connections that are in response to existing outbound connections from our VPS.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">This is needed for things like allowing HTTP responses for outgoing HTTP requests.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT\r\nsudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 6) Drop All Other Inbound Traffic by Default<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Now by default, we&#8217;ll drop all other inbound traffic not covered by our rules so far:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo iptables -P INPUT DROP<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">This will deny all other input traffic until we specifically allow it.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 7) Allow Specific Inbound Ports<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Next, we&#8217;ll allow incoming connections to specific ports that we want to expose to the internet.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">For example, if we want to allow inbound HTTP, HTTPs and SSH, we&#8217;ll add:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT\r\nsudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT\r\nsudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">You&#8217;ll want to replace these with the ports that your applications require.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 8) Log Dropped Packets<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">It&#8217;s a good idea to log any packets that get dropped by our rules. We can do this with:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo iptables -A INPUT -j LOG --log-prefix \"INPUT dropped: \" --log-level info\r\nsudo iptables -A FORWARD -j LOG --log-prefix \"FORWARD dropped: \" --log-level info\r\nsudo iptables -A OUTPUT -j LOG --log-prefix \"OUTPUT dropped: \" --log-level info<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">This will log information about dropped packets to \/var\/log\/syslog or \/var\/log\/messages.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 9) Allow All Outbound Traffic by Default<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">We want to allow all outbound traffic by default, so we specify the default policy for the OUTPUT chain:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo iptables -P OUTPUT ACCEPT<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 10) Control traffic by IP address<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Use the following command to accept traffic from a specific IP address.<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\"># sudo iptables -A INPUT -s your_IP_address_to_authorise -j ACCEPT\r\n$ sudo iptables -A INPUT -s 192.168.1.0\/24 -j ACCEPT<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Replace the IP address in the command with the IP address you want to authorise. You can also block traffic from an IP address:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\"># sudo iptables -A INPUT -s your_IP_address_to_block -j DROP\r\nsudo iptables -A INPUT -s 192.168.1.0\/24 -j DROP<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Replace the IP address in the command with the IP address you want to block. You can reject traffic from an IP address range with the following command:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\"># sudo iptables -A INPUT -m iprange --src-range your_start_IP_address-your_end_IP_address -j REJECT\r\nsudo iptables -A INPUT -m iprange --src-range 192.168.122.2-192.168.122.34 -j REJECT\r\nsudo iptables -A INPUT -m iprange --dest-range 8.8.8.2-8.8.8.22 -j DROP<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">The iptables options we used in the examples work as follows:<br \/>\n<b>-m<\/b>: Matches the specified option.<br \/>\n<b>-iprange<\/b>: Instructs the system to wait for a range of IP addresses instead of one.<br \/>\n<b>&#8211;src-range<\/b>: Identifies the source IP address range.<br \/>\n<b>&#8211;dest-range<\/b>: Identifies the destination IP address range.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 11) Delete a rule<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">A more precise method is to delete the line number of a rule. First, list all rules by entering the following:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo iptables -L --line-numbers<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<div class=\"d-text-start\"><img decoding=\"async\" class=\"d-img d-lazy-img\" src=\"https:\/\/images.cloudclusters.io\/0cb0f74d4d82411c96b500d0d781324d\/3956417483.png\" alt=\"iptables with line-numbers\" width=\"960\" \/><\/div>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Locate the line for the firewall rule you want to remove and run this command:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo iptables -D INPUT Number<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Replace Number with the rule line number you want to delete.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 12) List the IPTables Rules<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">You can now test your firewall rules by using the iptables command to list the rules. To do this, run the following command:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo iptables -L<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">This will list all of the firewall rules that are currently in effect.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col col-md-12  d-color-black d-fs-20 d-fw-600 d-lineheight-24 core-title\">Step 13) Save the IPTables Rules<\/div>\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">When the system is restarted, iptables does not keep the rules you created. Whenever you configure iptables on Linux, any changes you make apply only until the next reboot. So we save our IPTables rules so they persist across reboots. We can save the rules to directory \/etc\/iptables\/ with:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\"># Ubuntu\r\nsudo iptables-save &gt; \/etc\/iptables\/rules.v4\r\nsudo ip6tables-save &gt; \/etc\/iptables\/rules.v6\r\n\r\n# CentOS\r\nsudo iptables-save &gt; \/etc\/sysconfig\/iptables\r\nsudo ip6tables-save &gt; \/etc\/sysconfig\/ip6tables<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Then we can load these rules on boot with:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\"># Ubuntu\r\nsudo sh -c \"iptables-restore &lt; \/etc\/iptables\/rules.v4\"\r\nsudo sh -c \"ip6tables-restore &lt; \/etc\/iptables\/rules.v6\"<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">Another method, to save rules to Ubuntu-based systems, type:<\/p>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<pre class=\"d-fs-normal d-lineheight-26 mb-0\">sudo -s iptables-save -c<\/pre>\n<\/div>\n<\/div>\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">The next time your system boots, iptables will automatically reload the firewall rules.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-title pt-10 pb-0\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-left d-text-left d-title-inner\">\n<h2 id=\"conclusion\" class=\"col col-md-10 d-h2 d-color-black  core-title\">Conclusion<\/h2>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"d-paragraph-card\">\n<div class=\"container\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters pt-4 pb-1\">\n<div class=\"col\">\n<div class=\"row row-cols-1  justify-content-start d-text-start d-title-inner no-gutters\">\n<div class=\"col\">\n<p class=\"mb-0\">You should now have a functioning Linux VPS firewall with IPTables that allows necessary traffic while blocking unwanted connections. Be sure to update your rules as your system and network requirements change. Hope this step-by-step guide helps you configure and secure your Linux VPS with IPTables! Let me know if you have any other questions.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Securing your Linux VPS with a firewall is an important step to protect it from unauthorized access and attacks. IPTables is the built-in Linux firewall solution that allows you to filter incoming and outgoing traffic. This article will walk you through step-by-step how to configure an IPTables firewall on your Linux VPS. In this [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":1549,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1548","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-hosting"],"_links":{"self":[{"href":"https:\/\/b2bhostingclub.com\/blog\/wp-json\/wp\/v2\/posts\/1548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/b2bhostingclub.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/b2bhostingclub.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/b2bhostingclub.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/b2bhostingclub.com\/blog\/wp-json\/wp\/v2\/comments?post=1548"}],"version-history":[{"count":1,"href":"https:\/\/b2bhostingclub.com\/blog\/wp-json\/wp\/v2\/posts\/1548\/revisions"}],"predecessor-version":[{"id":1550,"href":"https:\/\/b2bhostingclub.com\/blog\/wp-json\/wp\/v2\/posts\/1548\/revisions\/1550"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/b2bhostingclub.com\/blog\/wp-json\/wp\/v2\/media\/1549"}],"wp:attachment":[{"href":"https:\/\/b2bhostingclub.com\/blog\/wp-json\/wp\/v2\/media?parent=1548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/b2bhostingclub.com\/blog\/wp-json\/wp\/v2\/categories?post=1548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/b2bhostingclub.com\/blog\/wp-json\/wp\/v2\/tags?post=1548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}