<?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>Pario TechnoBlob &#187; IP masquerading</title>
	<atom:link href="http://pario.no/tag/ip-masquerading/feed/" rel="self" type="application/rss+xml" />
	<link>http://pario.no</link>
	<description>A cronological documentation test project, nothing serious, really!</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:17:58 +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>ufw and IP masquerading</title>
		<link>http://pario.no/2009/05/24/ufw-and-ip-masquerading/</link>
		<comments>http://pario.no/2009/05/24/ufw-and-ip-masquerading/#comments</comments>
		<pubDate>Sat, 23 May 2009 22:45:53 +0000</pubDate>
		<dc:creator>Hans-Henry Jakobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[8.10]]></category>
		<category><![CDATA[9.04]]></category>
		<category><![CDATA[IP masquerading]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ufw]]></category>

		<guid isPermaLink="false">http://pario.no/?p=1059</guid>
		<description><![CDATA[I&#8217;ve just upgraded my home server from Ubuntu 8.10 to 9.04 and experienced that my ufw firewall (iptables) would not route traffic from my local network to the Internet. My IP masquerading was not working anymore and since I had not documented the process when I set it up I had to search the Ubuntu [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just upgraded my home server from Ubuntu 8.10 to 9.04 and experienced that my ufw firewall (iptables) would not route traffic from my local network to the Internet. My IP masquerading was not working anymore and since I had not documented the process when I set it up I had to search the Ubuntu pages to find the solution and came up with this.</p>
<blockquote><p>The purpose of IP Masquerading is to allow machines with private, non-routable IP addresses on your network to access the Internet through the machine doing the masquerading. Traffic from your private network destined for the Internet must be manipulated for replies to be routable back to the machine that made the request. To do this, the kernel must modify the <strong>source</strong> IP address of each packet so that replies will be routed back to it, rather than to the private IP address that made the request, which is impossible over the Internet. Linux uses <strong>Connection Tracking</strong> (conntrack) to keep track of which connections belong to which machines and reroute each return packet accordingly. Traffic leaving your private network is thus &#8220;masqueraded&#8221; as having originated from your Ubuntu gateway machine. This process is referred to in Microsoft documentation as Internet Connection Sharing.</p>
<h4>ufw Masquerading</h4>
<p>IP Masquerading can be achieved using custom <strong>ufw</strong> rules. This is possible because the current back-end for <strong>ufw</strong> is <strong>iptables-restore</strong> with the rules files located in</p>
<pre>/etc/ufw/*.rules</pre>
<p>These files are a great place to add legacy iptables rules used without <strong>ufw</strong>, and rules that are more network gateway or bridge related.</p>
<p>The rules are split into two different files, rules that should be executed before <strong>ufw</strong> command line rules, and rules that are executed after <strong>ufw</strong> command line rules.</p>
<ul>
<li>First, packet forwarding needs to be enabled in <strong>ufw</strong>. Two configuration files will need to be adjusted, in <strong>/etc/default/ufw</strong> change the
<pre>DEFAULT_FORWARD_POLICY</pre>
<p>to “<strong>ACCEPT</strong>”:</p>
<pre>DEFAULT_FORWARD_POLICY="ACCEPT"</pre>
<p>Then edit <strong>/etc/ufw/sysctl.conf</strong> and uncomment:</p>
<pre>net.ipv4.ip_forward=1</pre>
<p>Similarly, for IPv6 forwarding uncomment:</p>
<pre>net.ipv6.conf.default.forwarding=1</pre>
</li>
<li>Now we will add rules to the <strong>/etc/ufw/before.rules</strong> file. The default rules only configure the <strong>filter</strong> table, and to enable masquerading the <strong>nat</strong> table will need to be configured.  Add the following to the top of the file just after the header comments:
<pre># nat Table rules
*nat
:POSTROUTING ACCEPT [0:0]

# Forward traffic from eth1 through eth0.
-A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE

# don't delete the 'COMMIT' line or these nat table rules won't be processed
COMMIT</pre>
<p>The comments are not strictly necessary, but it is considered good practice to document your configuration. Also, when modifying any of the <strong>rules</strong> files in <strong>/etc/ufw</strong>, make sure these lines are the last line for each table modified:</p>
<pre># don't delete the 'COMMIT' line or these rules won't be processed
COMMIT</pre>
<p>For each <strong>Table</strong> a corresponding <strong>COMMIT</strong> statement is required. In these examples only the <strong>nat</strong> and <strong>filter</strong> tables are shown, but you can also add rules for the <strong>raw</strong> and <strong>mangle</strong> tables.</p>
<table border="0" summary="Note">
<tbody>
<tr>
<td rowspan="2" width="25" align="center" valign="top"><img src="https://help.ubuntu.com/9.04/libs/admon/note.png" alt="[Note]" /></td>
<th align="left"></th>
</tr>
<tr>
<td align="left" valign="top">In the above example replace <strong>eth0</strong>, <strong>eth1</strong>, and <strong>192.168.0.0/24</strong> with the appropriate interfaces and IP range for your network.</td>
</tr>
</tbody>
</table>
</li>
<li>Finally, disable and re-enable <strong>ufw</strong> to apply the changes:
<pre>sudo ufw disable &amp;&amp; sudo ufw enable</pre>
</li>
</ul>
<p>IP Masquerading should now be enabled. You can also add any additional FORWARD rules to the <strong>/etc/ufw/before.rules</strong>. It is recommended that these additional rules be added to the <strong>ufw-before-forward</strong> chain.</p></blockquote>
<p>Source: <a href="https://help.ubuntu.com/9.04/serverguide/C/firewall.html">https://help.ubuntu.com/9.04/serverguide/C/firewall.html</a></p>
<script type="text/javascript">var wordpress_toolbar_urls = ["https:\/\/help.ubuntu.com\/9.04\/serverguide\/C\/firewall.html"];var wordpress_toolbar_url = "http://pario.no/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "n";var wordpress_toolbar_hash = "aHR0cDovL3BhcmlvLm5vLzIwMDkvMDUvMjQvdWZ3LWFuZC1pcC1tYXNxdWVyYWRpbmcvPHdwdGI%2BdWZ3IGFuZCBJUCBtYXNxdWVyYWRpbmc8d3B0Yj5odHRwOi8vcGFyaW8ubm88d3B0Yj5QYXJpbyBUZWNobm9CbG9i";</script>]]></content:encoded>
			<wfw:commentRss>http://pario.no/2009/05/24/ufw-and-ip-masquerading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

