<?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>iptables and more on Linux &#187; iptables</title>
	<atom:link href="http://iptables.gen.tr/category/iptables/feed/" rel="self" type="application/rss+xml" />
	<link>http://iptables.gen.tr</link>
	<description>networking, tools in Linux and more...</description>
	<lastBuildDate>Wed, 16 Jun 2010 15:37:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Introduction to iptables</title>
		<link>http://iptables.gen.tr/2009/12/introduction-to-iptables/</link>
		<comments>http://iptables.gen.tr/2009/12/introduction-to-iptables/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 23:14:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iptables]]></category>

		<guid isPermaLink="false">http://iptables.adadns.net/?p=10</guid>
		<description><![CDATA[Hi everyone,
This is the first entry of my blog on iptables. I will try to keep my writings around iptables however I have more to share other than iptables. Let&#8217;s start with a simple iptables example.
Network Topology

Assume that your office network has a linux router (e.g Linux Router1) and you have  2 PCs. You need [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone,</p>
<p>This is the first entry of my blog on iptables. I will try to keep my writings around iptables however I have more to share other than iptables. Let&#8217;s start with a simple iptables example.</p>
<p><strong>Network Topology</strong></p>
<p><a href="http://iptables.adadns.net/wp-content/uploads/2009/12/iptables_basic_small.png"><img class="alignnone size-full wp-image-4" title="iptables_basic_small" src="http://iptables.adadns.net/wp-content/uploads/2009/12/iptables_basic_small.png" alt="" width="533" height="308" /></a></p>
<p>Assume that your office network has a linux router (e.g <em><strong>Linux Router1</strong></em>) and you have  2 PCs. You need to share network connection in Linux with those 2 PCs. Our sample network has several things to mention before going further.  As you can also see from the topology we have the following networks:</p>
<p><strong>Internal network: </strong>192.168.200.0/24<br />
<strong>Internal network Gateway: </strong>192.168.200.1</p>
<p><span id="more-10"></span></p>
<p>This means you can have IP addresses in the range 192.168.200.1-192.168.200.254 in your internal network and all the clients are set to use 192.168.200.1 as default gateway. Now we will directly jump to the configuration of our <strong><em>Linux router1 </em></strong>.</p>
<h3><strong>Configuration of Linux router 1:</strong></h3>
<p><strong>1) Enable IP forwarding</strong></p>
<p>By default, your Linux distribution shouldn&#8217;t be allowing IP forwarding. First enable ip forwarding in order not to beat the air for hours.</p>
<p><span style="color: #008000;"><strong>#sysctl net.ipv4.ip_forward=1</strong></span></p>
<p><strong>2) Add iptables rules<br />
</strong></p>
<p>There are two ways to enable NAT (Network Address Translation) which will allow our internal clients to appear as if their source address is 172.16.1.2 which is the external IP address of  our Linux router.</p>
<p><strong>a) Static maping:</strong></p>
<p><strong><span style="color: #008000;">#iptables -t nat -A POSTROUTING -s 192.168.200.0/24 -o eth1 -j SNAT &#8211;to 172.16.1.2</span></strong></p>
<p><strong>b) Masquerading:</strong></p>
<p><strong><span style="color: #008000;">#iptables -t nat -A POSTROUTING -s 192.168.200.0/24 -o eth1 -j MASQUERADE</span></strong></p>
<p>Once you run any of these commands, you should be able to ping external sites from your internal PCs but why we have two different ways to do the same thing.  As you can see command in method B doesn&#8217;t contain any IP of our external interface by which you can also use this method for interfaces which receive their IPs via DHCP protocol.</p>
<p><strong>3)</strong><strong> Make the changes persistent</strong></p>
<ul>
<li>Open the file /etc/sysctl.conf and toggle the attribute &#8220;<strong>net.ipv4.ip_forward</strong>&#8221; into<strong> 1 </strong></li>
<li>Either add one of the command in step 2 into /etc/rc.local to have it run at every reboot which is the dirty way or if you use a redhat flavoured distribution, use the following commands:</li>
</ul>
<p><strong> #chkconfig iptables on<br />
#service iptables save</strong></p>
<p>After these configurations, any client in your internal network should be able to reach external networks.</p>
<p>For the time being, it is all about this simple example. I will add more complex scenarios later on.</p>
]]></content:encoded>
			<wfw:commentRss>http://iptables.gen.tr/2009/12/introduction-to-iptables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
