{"id":4222,"date":"2018-03-09T18:00:47","date_gmt":"2018-03-09T18:00:47","guid":{"rendered":"https:\/\/geekdecoder.com\/?p=4222"},"modified":"2018-03-09T18:00:47","modified_gmt":"2018-03-09T18:00:47","slug":"how-to-whitelist-or-block-ips-in-your-firewall-on-linux-iptables-firewalld-ufw","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2018\/03\/09\/how-to-whitelist-or-block-ips-in-your-firewall-on-linux-iptables-firewalld-ufw\/","title":{"rendered":"How to Whitelist or Block IPs in your Firewall on Linux &#8211; iptables, firewalld, ufw"},"content":{"rendered":"<p>Knowing how to Whitelist and Blacklist IPs in your firewall can be very important when you want to allow or deny connection to your server, based on an IP address. Below we will cover how to allow and deny connections from IPs in IP Tables, Firewalld, and UFW.<\/p>\n<p>IPTables:<br \/>\nAllowing or Denying connections from IPs in IP Tables is quite simple. To accept the connection, or whitelist the IP, you would use the following command (where 1.1.1.1 is the IP you want to allow through the Firewall):<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# sudo iptables -A INPUT -s 1.1.1.1 -j ACCEPT\n<\/pre>\n<p>Denying the IP is very similar, just changing ACCEPT to DROP:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# sudo iptables -A INPUT -s 1.1.1.1 -j DROP\n<\/pre>\n<p>You can also change DROP or REJECT if you want your server to respond back to the request with a Rejection instead of just dropping the traffic all together.<\/p>\n<p>Firewalld:<br \/>\nTo whitelist IPs on Firewall-CMD, we&#8217;ll want to use the &#8211;add-source flag. We can whitelist an IP or an IP Subnets via the following commands:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# firewall-cmd --permanent --zone=public --add-source=1.1.1.1\n<\/pre>\n<p>Range:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# firewall-cmd --permanent --zone=public --add-source=1.1.0.0\/16\n<\/pre>\n<p>Blocking an IP is a bit difficult, as it requires a more complex command. The command that you would want to use to block traffic from an IP would be:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# firewall-cmd --permanent --add-rich-rule=&quot;rule family=ipv4 source address=1.1.1.1 reject&quot;\n<\/pre>\n<p>Range:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# firewall-cmd --permanent --add-rich-rule=&quot;rule family=ipv4 source address=1.1.0.0\/16 reject&quot;\n<\/pre>\n<p>We can also view all of the whitelisted IPs in our zone via:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# firewall-cmd --permanent --zone=public --list-sources\n<\/pre>\n<p>UFW:<br \/>\nAllowing and blocking IPs in UFW is very simple and straight forward. We can allow connections from a specific IP via the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# sudo ufw allow from 22.33.44.55\n<\/pre>\n<p>Blocking and IP is just as simple, with the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# sudo ufw deny from 22.33.44.55\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Knowing how to Whitelist and Blacklist IPs in your firewall can be very important when you want to allow or deny connection to your server, based on an IP address. Below we will cover how to allow and deny connections from IPs in IP Tables, Firewalld, and UFW. IPTables: Allowing or Denying connections from IPs &#8230; <a title=\"How to Whitelist or Block IPs in your Firewall on Linux &#8211; iptables, firewalld, ufw\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2018\/03\/09\/how-to-whitelist-or-block-ips-in-your-firewall-on-linux-iptables-firewalld-ufw\/\" aria-label=\"Read more about How to Whitelist or Block IPs in your Firewall on Linux &#8211; iptables, firewalld, ufw\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,52],"tags":[],"class_list":["post-4222","post","type-post","status-publish","format-standard","hentry","category-administration","category-iptables"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/4222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=4222"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/4222\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=4222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=4222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=4222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}