{"id":773,"date":"2013-08-07T00:09:02","date_gmt":"2013-08-06T22:09:02","guid":{"rendered":"https:\/\/marc.storck.lu\/blog\/?p=773"},"modified":"2013-08-11T20:43:10","modified_gmt":"2013-08-11T18:43:10","slug":"basic-paranoid-iptables-firewall-for-an-amprnet-gateway","status":"publish","type":"post","link":"https:\/\/marc.storck.lu\/blog\/2013\/08\/basic-paranoid-iptables-firewall-for-an-amprnet-gateway\/","title":{"rendered":"Basic paranoid iptables firewall for an AMPRnet gateway"},"content":{"rendered":"<p>I have been asked a couple of times to provide a starting point for a firewall based on iptables for AMPRnet gateways based on Linux. I&#8217;ll try to accomplish this here.<\/p>\n<p>I&#8217;m assuming your Linux gateway uses the following interfaces:<\/p>\n<ul>\n<li>eth0 : connected to the Internet, has a public static IP address (<span style=\"text-decoration: underline; color: #ff0000;\"><strong>this post does NOT cover AMPRnet gateways behind NAT or within DMZ<\/strong><\/span>)<\/li>\n<li>eth1 : connected to your local AMPRnet LAN, has a static 44net IP address<\/li>\n<li>tunl0 : the IPIP tunnel interface<\/li>\n<\/ul>\n<p>The following script will allow to receive IPIP, RIPv2 and Management traffic. It will also allow connection to be initiated from the gateway or the LAN by employing a stateful firewall:<\/p>\n<p><!--more--><\/p>\n<p>(<span style=\"text-decoration: underline; color: #ff0000;\"><strong>ATTENTION<\/strong><\/span>: you will most probably lose connectivity to your gateway if you apply these rules remotely)<\/p>\n<blockquote><p>### Drop everything by default<br \/>\niptables -P INPUT DROP<br \/>\niptables -P OUTPUT DROP<br \/>\niptables -P FORWARD DROP<\/p>\n<p>### Allow traffic on loopback interface<br \/>\niptables -A INPUT -i lo -j ACCEPT<br \/>\niptables -A OUTPUT -o lo -j ACCEPT<\/p>\n<p>### ICMP is important and must work<br \/>\niptables -A INPUT -p icmp -j ACCEPT<br \/>\niptables -A FORWARD -p icmp -j ACCEPT<br \/>\niptables -A OUTPUT -p icmp -j ACCEPT<\/p>\n<p>### Allow remote management via SSH<br \/>\n### repeat for every subnet or IP address you want to allow<br \/>\niptables -A INPUT -p tcp &#8211;dport 22 -s 192.0.2.0\/24 -j ACCEPT<\/p>\n<p>### allow inbound IPIP packets (from everywhere)<br \/>\niptables -A INPUT -i eth0 -p 4 -j ACCEPT<\/p>\n<p>### allow inbound RIPv2 messages<br \/>\niptables -A INPUT -i tunl0 -s 44.0.0.1 -p udp &#8211;port 520 -j ACCEPT<\/p>\n<p>### allow inbound packets related to outbound packets (answers to request initiated locally)<br \/>\niptables -A INPUT -i eth0 -p udp\u00a0-m conntrack &#8211;ctstate ESTABLISHED,RELATED -j ACCEPT<br \/>\niptables -A INPUT -i eth0 -p tcp -m conntrack &#8211;ctstate ESTABLISHED,RELATED -j ACCEPT<\/p>\n<p>### allow outbound IPIP packets (to everywhere)<br \/>\niptables -A OUTPUT -o eth0 -p 4 -j ACCEPT<\/p>\n<p>### allow outbound connections from the local gateway<br \/>\niptables -A OUTPUT -o eth0 -p udp -j ACCEPT<br \/>\niptables -A OUTPUT -o eth0 -p tcp -j ACCEPT<\/p>\n<p>### allow traffic from LAN to outside (BCP38 applied)<br \/>\niptables -A FORWARD -i eth1 -s 44.256.0.0\/24 -p udp -j ACCEPT<br \/>\niptables -A FORWARD -i eth1 -s 44.256.0.0\/24\u00a0-p tcp -j ACCEPT<\/p>\n<p>### allow packets related to outbound packets (answers to request initiated locally) to be forwarded<br \/>\niptables -A FORWARD -i tunl0 -p udp\u00a0-m conntrack &#8211;ctstate ESTABLISHED,RELATED -j ACCEPT<br \/>\niptables -A FORWARD -i tunl0 -p tcp -m conntrack &#8211;ctstate ESTABLISHED,RELATED -j ACCEPT<\/p><\/blockquote>\n<p><span style=\"color: #3366ff;\"><strong>MODIFICATIONS<\/strong><\/span> to do by you:<\/p>\n<ul>\n<li>replace 192.0.2.0\/24 by the subnet or IP from where you want to connect to your gateway to manage it.<\/li>\n<li>replace 44.256.0.0\/24 by your AMPRnet subnet.<\/li>\n<\/ul>\n<p><span style=\"color: #339966;\"><strong>TODO:<\/strong><\/span><\/p>\n<ul>\n<li>Add more rules to allow specific services (please provide your ideas\/wishes)<\/li>\n<li>Allow more protocols from LAN to outside<\/li>\n<\/ul>\n<p><strong><span style=\"color: #ffcc00;\">UPDATES:<\/span><\/strong><\/p>\n<ul>\n<li>\u00a0Tried to make it clear that this post does NOT (yet) cover AMPRnet gateways behind NAT.<\/li>\n<li>Corrected typo &#8211;port instead of &#8211;dport.<\/li>\n<li>Allow traffic on loopback interface.<\/li>\n<li>Allow ICMP everywhere.<\/li>\n<li>Corrected last pair of rules where I accidentally had -i eth0 instead of -i tunl0<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I have been asked a couple of times to provide a starting point for a firewall based on iptables for AMPRnet gateways based on Linux. I&#8217;ll try to accomplish this here. I&#8217;m assuming your Linux gateway uses the following interfaces: eth0 : connected to the Internet, has a public static IP address (this post does &hellip; <a href=\"https:\/\/marc.storck.lu\/blog\/2013\/08\/basic-paranoid-iptables-firewall-for-an-amprnet-gateway\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Basic paranoid iptables firewall for an AMPRnet gateway&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,52],"tags":[58,59,9],"class_list":["post-773","post","type-post","status-publish","format-standard","hentry","category-hobbies","category-interests","tag-amprnet","tag-ham-radio","tag-linux"],"_links":{"self":[{"href":"https:\/\/marc.storck.lu\/blog\/wp-json\/wp\/v2\/posts\/773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marc.storck.lu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/marc.storck.lu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/marc.storck.lu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/marc.storck.lu\/blog\/wp-json\/wp\/v2\/comments?post=773"}],"version-history":[{"count":7,"href":"https:\/\/marc.storck.lu\/blog\/wp-json\/wp\/v2\/posts\/773\/revisions"}],"predecessor-version":[{"id":781,"href":"https:\/\/marc.storck.lu\/blog\/wp-json\/wp\/v2\/posts\/773\/revisions\/781"}],"wp:attachment":[{"href":"https:\/\/marc.storck.lu\/blog\/wp-json\/wp\/v2\/media?parent=773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marc.storck.lu\/blog\/wp-json\/wp\/v2\/categories?post=773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marc.storck.lu\/blog\/wp-json\/wp\/v2\/tags?post=773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}