<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://townx.org" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>townx - Simple firewall for Ubuntu using iptables - Comments</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables</link>
 <description>Comments for &quot;Simple firewall for Ubuntu using iptables&quot;</description>
 <language>en</language>
<item>
 <title>Thanks. That does look like</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-38531</link>
 <description>&lt;p&gt;Thanks. That does look like an improvement. Like I said in the post, I&#039;m not really an iptables expert!&lt;/p&gt;</description>
 <pubDate>Tue, 21 Oct 2008 13:26:59 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 38531 at http://townx.org</guid>
</item>
<item>
 <title>Ooops! Forgot the LocalHost...</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-38525</link>
 <description>&lt;p&gt;&lt;code&gt;iptables -A INPUT -i lo -j ACCEPT&lt;/code&gt;&lt;/p&gt;</description>
 <pubDate>Sun, 19 Oct 2008 18:03:15 -0500</pubDate>
 <dc:creator>Lifenstein</dc:creator>
 <guid isPermaLink="false">comment 38525 at http://townx.org</guid>
</item>
<item>
 <title>Simpler Alternative (?)</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-38524</link>
 <description>&lt;p&gt;For a personal home computer (running no services for the outside world),  here is a simpler version :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;#!/bin/bash&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;############################################################&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;#---- Script to setup a simple firewall using iptables -----&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;###&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;# * Blocks all incoming connections, except those opened by&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;#   me, or related to already open connections&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;# * Blocks all forward requests&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;# * Allows all outgoing connections&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;###&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;############################################################&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# Clearing all previous rules&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;iptables -F&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;# Setting Default Policies&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;iptables -P INPUT DROP&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;iptables -P OUTPUT ACCEPT&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;iptables -P FORWARD DROP&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;# Allowing already-established and related-incoming connections&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT&lt;/code&gt;&lt;/p&gt;</description>
 <pubDate>Sun, 19 Oct 2008 17:48:21 -0500</pubDate>
 <dc:creator>Lifenstein</dc:creator>
 <guid isPermaLink="false">comment 38524 at http://townx.org</guid>
</item>
<item>
 <title>Only if you&#039;re running a web</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-38371</link>
 <description>&lt;p&gt;Only if you&#039;re running a web server :)&lt;/p&gt;</description>
 <pubDate>Sat, 02 Aug 2008 15:40:41 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 38371 at http://townx.org</guid>
</item>
<item>
 <title>firewall</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-38131</link>
 <description>&lt;p&gt;Hi,&lt;br /&gt;
Great script - I&#039;ve used it as the starter for my setup.&lt;/p&gt;

&lt;p&gt;ShieldsUP notes that your script shows ports 0 and 1 as closed rather than in stealth mode, and also doesn&#039;t drop &lt;span class=&quot;caps&quot;&gt;ICMP &lt;/span&gt;packets - meaning that if the machines are directly attached to the internet via ppp, or with an &lt;span class=&quot;caps&quot;&gt;ADSL &lt;/span&gt;modem with no firewall, then they can be discovered.&lt;/p&gt;

&lt;p&gt;Also your script doesn&#039;t handle dialup connections.&lt;/p&gt;

&lt;p&gt;The following changes mitigates against these:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;drop everything else on ppp&lt;br /&gt;
iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-i ppp+ -p udp -j &lt;span class=&quot;caps&quot;&gt;DROP&lt;/span&gt;&lt;br /&gt;
iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-i ppp+ -p tcp -m tcp --syn -j &lt;span class=&quot;caps&quot;&gt;DROP&lt;/span&gt;&lt;br /&gt;
iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-i ppp+ -p icmp -j &lt;span class=&quot;caps&quot;&gt;DROP&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Explcitly deal with port 0&lt;br /&gt;
iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-j &lt;span class=&quot;caps&quot;&gt;DROP &lt;/span&gt;-p tcp --sport 0&lt;br /&gt;
iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-j &lt;span class=&quot;caps&quot;&gt;DROP &lt;/span&gt;-p udp --sport 0&lt;br /&gt;
iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-j &lt;span class=&quot;caps&quot;&gt;DROP &lt;/span&gt;-p tcp --dport 0&lt;br /&gt;
iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-j &lt;span class=&quot;caps&quot;&gt;DROP &lt;/span&gt;-p udp --dport 0&lt;/li&gt;
&lt;li&gt;Explcitly deal with port 1&lt;br /&gt;
iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-j &lt;span class=&quot;caps&quot;&gt;DROP &lt;/span&gt;-p tcp --sport 1&lt;br /&gt;
iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-j &lt;span class=&quot;caps&quot;&gt;DROP &lt;/span&gt;-p udp --sport 1&lt;br /&gt;
iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-j &lt;span class=&quot;caps&quot;&gt;DROP &lt;/span&gt;-p tcp --dport 1&lt;br /&gt;
iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-j &lt;span class=&quot;caps&quot;&gt;DROP &lt;/span&gt;-p udp --dport 1&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;regards&lt;/p&gt;

&lt;p&gt;Colin&lt;/p&gt;</description>
 <pubDate>Thu, 08 May 2008 03:01:53 -0500</pubDate>
 <dc:creator>Guest</dc:creator>
 <guid isPermaLink="false">comment 38131 at http://townx.org</guid>
</item>
<item>
 <title>Thx ;)</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-38122</link>
 <description>&lt;p&gt;thanks!though  iptables -A &lt;span class=&quot;caps&quot;&gt;INPUT &lt;/span&gt;-p tcp -s 0/0 --dport 80 -j &lt;span class=&quot;caps&quot;&gt;ACCEPT &lt;/span&gt;is needed!&lt;/p&gt;</description>
 <pubDate>Wed, 30 Apr 2008 18:18:12 -0500</pubDate>
 <dc:creator>Prakash</dc:creator>
 <guid isPermaLink="false">comment 38122 at http://townx.org</guid>
</item>
<item>
 <title>What, the ports became</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-14521</link>
 <description>&lt;p&gt;What, the ports became unavailable? Or the services stopped running? When you stopped the firewall? If you set it up as above, stopping the firewall shouldn&#039;t touch other services, and should definitely not block them.&lt;/p&gt;</description>
 <pubDate>Sun, 18 Nov 2007 18:07:54 -0600</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 14521 at http://townx.org</guid>
</item>
<item>
 <title>shit</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-14520</link>
 <description>&lt;p&gt;when i typed /etc/init.d/firewall stop ssh, apache gone away .. :(&lt;br /&gt;
why ?&lt;/p&gt;</description>
 <pubDate>Sun, 18 Nov 2007 11:09:12 -0600</pubDate>
 <dc:creator>alex rose</dc:creator>
 <guid isPermaLink="false">comment 14520 at http://townx.org</guid>
</item>
<item>
 <title>Thanks for that, Roy. I&#039;ve</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-14403</link>
 <description>&lt;p&gt;Thanks for that, Roy. I&#039;ve used some of the &lt;span class=&quot;caps&quot;&gt;GUI&lt;/span&gt;s before, but the simple ones can&#039;t cope with the scenario outlined in the article. While fwbuilder probably could, I like the simplicity of my script, and have used it succesfully without touching it for about 3 years. I&#039;m very happy with it.&lt;/p&gt;</description>
 <pubDate>Tue, 02 Oct 2007 13:20:28 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 14403 at http://townx.org</guid>
</item>
<item>
 <title>Great, glad it was helpful.</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-14402</link>
 <description>&lt;p&gt;Great, glad it was helpful.&lt;/p&gt;</description>
 <pubDate>Tue, 02 Oct 2007 13:19:19 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 14402 at http://townx.org</guid>
</item>
<item>
 <title>short and sweet, works as</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-14401</link>
 <description>&lt;p&gt;short and sweet, works as advertised! happy customer here. &lt;/p&gt;</description>
 <pubDate>Mon, 01 Oct 2007 22:57:55 -0500</pubDate>
 <dc:creator>Reid</dc:creator>
 <guid isPermaLink="false">comment 14401 at http://townx.org</guid>
</item>
<item>
 <title>iptables</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-14374</link>
 <description>&lt;p&gt;One of the most impressive tools for building iptables firewalls is fwbuilder at &lt;a href=&quot;http://www.fwbuilder.org&quot; title=&quot;www.fwbuilder.org&quot;&gt;www.fwbuilder.org&lt;/a&gt;.&lt;br /&gt;
This fantastic &lt;span class=&quot;caps&quot;&gt;GUI &lt;/span&gt;app writes the iptables for you in a way that is easy to read.&lt;/p&gt;

&lt;p&gt;Really good for heavy weight firewalling.&lt;/p&gt;

&lt;p&gt;Roy.&lt;/p&gt;</description>
 <pubDate>Fri, 14 Sep 2007 15:20:42 -0500</pubDate>
 <dc:creator>Guest</dc:creator>
 <guid isPermaLink="false">comment 14374 at http://townx.org</guid>
</item>
<item>
 <title>Thanks Michael. Glad to be</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-14336</link>
 <description>&lt;p&gt;Thanks Michael. Glad to be of service.&lt;/p&gt;</description>
 <pubDate>Thu, 06 Sep 2007 09:30:35 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 14336 at http://townx.org</guid>
</item>
<item>
 <title>So simple!</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-14325</link>
 <description>&lt;p&gt;I&#039;ve fooled with iptables off and on for a few years now.  Never quite getting all the pieces right.  Thanks for bringing it back down to Earth with a simple as pie approach to setting the rules and integrating with start up.  It was good to learn a thing or two about update-rc.d.  That was an interesting tool I hadn&#039;t seen before.&lt;/p&gt;

&lt;p&gt;One note:  Add your input accept rules (like port 80 for &lt;span class=&quot;caps&quot;&gt;HTTP BEFORE &lt;/span&gt;you drop everything else).  Took me a couple minutes to figure that one out, but otherwise, all else was smooth sailing.&lt;/p&gt;

&lt;p&gt;--Michael&lt;/p&gt;</description>
 <pubDate>Sun, 26 Aug 2007 21:42:07 -0500</pubDate>
 <dc:creator>Michael</dc:creator>
 <guid isPermaLink="false">comment 14325 at http://townx.org</guid>
</item>
<item>
 <title>Very helpful.  Thanks for</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comment-14220</link>
 <description>&lt;p&gt;Very helpful.  Thanks for posting.&lt;/p&gt;</description>
 <pubDate>Thu, 21 Jun 2007 00:05:29 -0500</pubDate>
 <dc:creator>Guest</dc:creator>
 <guid isPermaLink="false">comment 14220 at http://townx.org</guid>
</item>
<item>
 <title>Simple firewall for Ubuntu using iptables</title>
 <link>http://townx.org/simple_firewall_for_ubuntu_using_iptables</link>
 <description>&lt;p&gt;Linux&#039;s built-in firewall iptables is very useful, but pretty hard to configure. I used to use lokkit, but this caused problems when moving between different networks. I was also having problems with the network configuration tools in Ubuntu, which work but aren&#039;t automatic enough for me. And I wanted to be able to switch the firewall and the network configuration simultaneously.&lt;/p&gt;

&lt;p&gt;In the end, I bit the bullet and worked out how to write a simple iptables script. Here it is:&lt;/p&gt;



&lt;pre&gt;
#!/bin/bash
# flush all chains
iptables -F
# set the default policy for each of the pre-defined chains
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
# allow establishment of connections initialised by my outgoing packets
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# drop everything else
iptables -A INPUT -i eth+ -p udp -j DROP
iptables -A INPUT -i eth+ -p tcp -m tcp --syn -j DROP
# accept anything on localhost
iptables -A INPUT -i lo -j ACCEPT
&lt;/pre&gt;



&lt;p&gt;I have network interfaces on eth0 and eth1, so this script has rules which cover both; if your interfaces have different names, you will need to edit the rules to cover that. This drops everything incoming, except for connections which were initially established by my outgoing packets (thanks Luke! - see comments); which means it&#039;s no good for servers.&lt;/p&gt;

&lt;p&gt;I put this script in /opt/scripts/iptables.script and made it executable. Once you run it, you can find out whether it has worked by displaying your current iptables rules with:&lt;/p&gt;



&lt;pre&gt;
sudo iptables -L -v
&lt;/pre&gt;



&lt;p&gt;I then created a simple init script to start/stop the firewall (in /etc/init.d/firewall):&lt;/p&gt;



&lt;pre&gt;#!/bin/bash
if [[ $1 == start ]] ; then
  sudo /opt/scripts/iptables.script
else
  sudo iptables -F
fi
&lt;/pre&gt;



&lt;p&gt;Then I symlinked this into my /etc/rc.* directories using the update-rc.d tool, so the firewall starts before the network comes up:&lt;/p&gt;



&lt;pre&gt;
update-rc.d firewall start 20 2 3 4 5 . stop 99 0 1 6 .
&lt;/pre&gt;



&lt;p&gt;I find having this script helps me a lot. I have it integrated with a start/stop script with my network, so I can easily switch network and firewall configuration from the command line.&lt;/p&gt;</description>
 <comments>http://townx.org/simple_firewall_for_ubuntu_using_iptables#comments</comments>
 <category domain="http://townx.org/howtos">howtos</category>
 <pubDate>Wed, 05 Apr 2006 09:36:10 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">259 at http://townx.org</guid>
</item>
</channel>
</rss>
