<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BigSmoke &#187; iptables</title>
	<atom:link href="http://blog.bigsmoke.us/tag/iptables/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.bigsmoke.us</link>
	<description>Smokes your problems, coughs fresh air.</description>
	<lastBuildDate>Sat, 04 Feb 2012 18:03:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Making a service available on more ports with iptables</title>
		<link>http://blog.bigsmoke.us/2010/12/23/making-a-service-available-on-more-ports-with-iptables</link>
		<comments>http://blog.bigsmoke.us/2010/12/23/making-a-service-available-on-more-ports-with-iptables#comments</comments>
		<pubDate>Thu, 23 Dec 2010 14:27:10 +0000</pubDate>
		<dc:creator>halfgaar</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[iptables]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=1777</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>If you need services to be availble on multiple ports, you can use:</p>
<p><pre class="php">iptables -t nat -A PREROUTING -i eth0 -p tcp --dport <span style="color: #cc66cc;">1000</span> -j REDIRECT --to-port <span style="color: #cc66cc;">25</span>  --match comment --comment <span style="color: #ff0000;">&quot;Explain.&quot;</span></pre></p>
<p>This makes port 1000 and 25 the same service.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2010/12/23/making-a-service-available-on-more-ports-with-iptables/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a port forwarded machine available from within the LAN</title>
		<link>http://blog.bigsmoke.us/2010/07/23/making-a-port-forwarded-machine-available-from-within-the-lan</link>
		<comments>http://blog.bigsmoke.us/2010/07/23/making-a-port-forwarded-machine-available-from-within-the-lan#comments</comments>
		<pubDate>Fri, 23 Jul 2010 11:33:08 +0000</pubDate>
		<dc:creator>halfgaar</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[netfilter]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=1521</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>
When you forward a port to an internal machine on the network, you still can&#8217;t access that host using your WAN-IP from within the LAN. <a href="http://www.frozentux.net/iptables-tutorial/iptables-tutorial.html#DNATTARGET">This article</a> explains it well. In short, it&#8217;s because the reply the machine your connecting to makes, goes to the LAN IP directly, and not back through the router. 
</p>

<p>
To fix it, we need to add a SNAT rule for that port forward as well. In the example that we want to forward port 80 to 10.50.0.4 on our 10.50.0.0/16 LAN and 10.50.0.1 is our router, these two rules are necessary:
</p>

<pre>
iptables -t nat -A PREROUTING -d WANIP -p tcp --dport 80 -m comment --comment "Forward www to 10.50.0.4." -j DNAT --to-destination LANIP
iptables -t nat -A POSTROUTING -p tcp --source 10.50.0.0/16 --dest 10.50.0.4 --dport 80 -j SNAT --to-source 10.50.0.1 --match comment --comment "Allow our LAN to access port 80 from the WAN side as well."
</pre>

<p>
Normally when forwarding, I would not use -d WANIP, but &#8211;in-interface eth0, but that won&#8217;t work here, because the LAN requests are not on eth0.
</p>

<p>
Also, the &#8211;source in the second rule is not strictly necessery, but if you don&#8217;t specify this rule, it will also match incoming requests for the internet, which is ugly, especially if you have logging rules.
</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2010/07/23/making-a-port-forwarded-machine-available-from-within-the-lan/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving and loading iptables rules on Debian</title>
		<link>http://blog.bigsmoke.us/2010/02/03/saving-and-loading-iptables-rules-on-debian</link>
		<comments>http://blog.bigsmoke.us/2010/02/03/saving-and-loading-iptables-rules-on-debian#comments</comments>
		<pubDate>Wed, 03 Feb 2010 12:36:53 +0000</pubDate>
		<dc:creator>halfgaar</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[iptables]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=1188</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>
For some reason, Debian can&#8217;t do &#8220;/etc/init.d/iptables save&#8221;. So, we have to fix something ourselves. I used <a href="http://www.debian-administration.org/articles/445">this article</a> as source, which also has some useful comments. Apparently, the iptables initscript used to exist&#8230;
</p>

<p>
To save, type:
</p>

<pre class="php">iptables-save &gt; /etc/iptables.rules</pre>

<p>
Make /etc/network/if-pre-up.d/iptables:
</p>

<pre class="php"><span style="color: #808080; font-style: italic;">#!/bin/sh</span>
iptables-restore &lt; /etc/iptables.rules</pre>

<p>
Don&#8217;t forget to make it executable:
</p>

<pre class="bash">chmod +x /etc/network/if-pre-up.d/iptables</pre>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2010/02/03/saving-and-loading-iptables-rules-on-debian/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convenient iptables rules</title>
		<link>http://blog.bigsmoke.us/2010/01/04/convenient-iptables-rules</link>
		<comments>http://blog.bigsmoke.us/2010/01/04/convenient-iptables-rules#comments</comments>
		<pubDate>Mon, 04 Jan 2010 10:16:56 +0000</pubDate>
		<dc:creator>halfgaar</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[iptables]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=980</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>
Here are some convenient iptables rules.
</p>

<p>
This first list is for not allowing anything in, accept packets that come back from outgoing connections, complicated related traffic like FTP, everything from the localhost, ICMP (ping and stuff) and SSH. It also sets the default policy to DROP. This you would use on a machine connected directly to the internet.
</p>

<pre class="php">iptables -A INPUT --match state --state RELATED,ESTABLISHED -j ACCEPT --match comment --comment <span style="color: #ff0000;">&quot;Accept traffic from outgoing connections and stuff like FTP.&quot;</span>
iptables -A INPUT -p icmp -j ACCEPT --match comment --comment <span style="color: #ff0000;">&quot;Allow ICMP&quot;</span>
iptables -A INPUT -p tcp --dport <span style="color: #cc66cc;">22</span> -j ACCEPT --match comment --comment <span style="color: #ff0000;">&quot;Allow SSH&quot;</span>
iptables -A INPUT --in-interface lo -j ACCEPT --match comment --comment <span style="color: #ff0000;">&quot;Allow everything on the localhost&quot;</span>
iptables -P INPUT DROP</pre>

Here are some rules to allow certain MAC addresses to access everything. Simplifies things on a LAN (even though it&#8217;s not attacker-proof, it keeps unwanted people out of my SMB and stuff):

<pre class="php">iptables -A INPUT --match mac --mac-source xx:xx:xx:xx:xx:xx --match comment --comment <span style="color: #ff0000;">&quot;Allow everything from [computer]&quot;</span> -j ACCEPT</pre>

<p>
Besides computers you want to grant full access to a machine, don&#8217;t forget to include the MACs  of the router and the machine&#8217;s own ethernet interface.
</p>

<p>
When the machine acts as a masquerading SNAT server, use this to forward ports to LAN hosts (be sure to have the &#8211;to after the -j):
</p>

<pre class="php">iptables -t nat -A PREROUTING --in-interface eth0 -p tcp --dport <span style="color: #cc66cc;">80</span> -j DNAT --to <span style="color: #cc66cc;">10.0</span><span style="color: #cc66cc;">.0</span><span style="color: #cc66cc;">.1</span>:<span style="color: #cc66cc;">22</span> --match comment --comment <span style="color: #ff0000;">&quot;forwards incoming port 80 to port 22 on 10.0.0.1&quot;</span></pre>

<p>
To allow everything for a samba server:
</p>

<pre class="php">iptables -A INPUT -p tcp --dport <span style="color: #cc66cc;">139</span> -m comment --comment <span style="color: #ff0000;">&quot;Allow Netbios-ssn&quot;</span> -j ACCEPT 
iptables -A INPUT -p tcp --dport <span style="color: #cc66cc;">445</span> -m comment --comment <span style="color: #ff0000;">&quot;Allow microsoft-ds&quot;</span> -j ACCEPT 
iptables -A INPUT -p udp --dport <span style="color: #cc66cc;">137</span> -m comment --comment <span style="color: #ff0000;">&quot;Allow netbios-ns&quot;</span> -j ACCEPT 
iptables -A INPUT -p udp --dport <span style="color: #cc66cc;">138</span> -m comment --comment <span style="color: #ff0000;">&quot;Allow netbios-dgm&quot;</span> -j ACCEPT</pre>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2010/01/04/convenient-iptables-rules/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iptables rule to block access to our IMAP server</title>
		<link>http://blog.bigsmoke.us/2009/12/21/iptables-rule-to-block-access-to-our-imap-server</link>
		<comments>http://blog.bigsmoke.us/2009/12/21/iptables-rule-to-block-access-to-our-imap-server#comments</comments>
		<pubDate>Mon, 21 Dec 2009 13:53:03 +0000</pubDate>
		<dc:creator>halfgaar</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[iptables]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=943</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>
When migrating to Zimbra, I don&#8217;t want people to fiddle with their mail when I&#8217;m doing it, so I disable IMAP access from anything but the virtual machine instance in which Zimbra is running. I do that with this:
</p>

<pre class="php">iptables -A INPUT ! -s <span style="color: #cc66cc;">192.168</span><span style="color: #cc66cc;">.1</span><span style="color: #cc66cc;">.106</span> -p tcp --dport <span style="color: #cc66cc;">143</span> -j REJECT</pre>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2009/12/21/iptables-rule-to-block-access-to-our-imap-server/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

