{"id":573,"date":"2016-04-25T12:20:02","date_gmt":"2016-04-25T11:20:02","guid":{"rendered":"http:\/\/www.haxed.me.uk\/?p=573"},"modified":"2016-04-25T12:20:02","modified_gmt":"2016-04-25T11:20:02","slug":"configuring-strict-linux-firewall-using-iptables","status":"publish","type":"post","link":"https:\/\/haxed.me.uk\/index.php\/2016\/04\/25\/configuring-strict-linux-firewall-using-iptables\/","title":{"rendered":"Configuring very very strict Linux Firewall using iptables"},"content":{"rendered":"<p>So, you want to configure a very very secure Linux Firewall using iptables? no probs. Here is how to do it;<\/p>\n<pre>\r\n#!\/bin\/sh\r\n# My system IP\/set ip address of server\r\nSERVER_IP=\"2.2.2.2\"\r\n\r\n# Flushing all rules\r\niptables -F\r\niptables -X\r\n\r\n# Setting default filter policy\r\niptables -P INPUT DROP\r\niptables -P OUTPUT DROP\r\niptables -P FORWARD DROP\r\n\r\n# Allow ALL traffic on loopback\r\niptables -A INPUT -i lo -j ACCEPT\r\niptables -A OUTPUT -o lo -j ACCEPT\r\n \r\n# Allow INCOMING CONNECTIONS ON SSH PORT 22\r\niptables -A INPUT -p tcp -s 0\/0 -d $SERVER_IP --sport 513:65535 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT\r\niptables -A OUTPUT -p tcp -s $SERVER_IP -d 0\/0 --sport 22 --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT\r\n# DROP ALL TRAFFIC COMING IN AND GOING OUT\r\n\r\niptables -A INPUT -j DROP\r\niptables -A OUTPUT -j DROP\r\n<\/pre>\n<p>This above configuration locks down everything apart from SSH.<\/p>\n<p>But, most customers want to configure access from their client&#8217;s IP address only. I.e. they don&#8217;t want SSH to accept connections from any IP address. Only from the client on for example 1.1.1.1. Here&#8217;s how to do that:<\/p>\n<pre>\r\n# Allow incoming ssh only from IP 1.1.1.1\r\niptables -A INPUT -p tcp -s 1.1.1.1 -d $SERVER_IP --sport 513:65535 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT\r\niptables -A OUTPUT -p tcp -s $SERVER_IP -d 1.1.1.1 --sport 22 --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT\r\n<\/pre>\n<p>Credit goes to; http:\/\/www.cyberciti.biz\/tips\/linux-iptables-4-block-all-incoming-traffic-but-allow-ssh.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, you want to configure a very very secure Linux Firewall using iptables? no probs. Here is how to do it; #!\/bin\/sh # My system IP\/set ip address of server SERVER_IP=&#8221;2.2.2.2&#8243; # Flushing all rules iptables -F iptables -X # &hellip; <a href=\"https:\/\/haxed.me.uk\/index.php\/2016\/04\/25\/configuring-strict-linux-firewall-using-iptables\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,31,9,7,3],"tags":[],"class_list":["post-573","post","type-post","status-publish","format-standard","hentry","category-cloud","category-iptables","category-linux","category-management-tools","category-security"],"_links":{"self":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=573"}],"version-history":[{"count":1,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/573\/revisions"}],"predecessor-version":[{"id":574,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/573\/revisions\/574"}],"wp:attachment":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}