<?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>A Million Monkeys &#187; port forward</title>
	<atom:link href="http://www.monkeedev.co.uk/blog/tag/port-forward/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.monkeedev.co.uk/blog</link>
	<description>Surviving life as a sysadmin.</description>
	<lastBuildDate>Mon, 16 May 2011 09:49:18 +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>Simple port forwarding using iptables</title>
		<link>http://www.monkeedev.co.uk/blog/2009/04/03/simple-port-forwarding-using-iptables/</link>
		<comments>http://www.monkeedev.co.uk/blog/2009/04/03/simple-port-forwarding-using-iptables/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 14:04:39 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[port forward]]></category>

		<guid isPermaLink="false">http://www.monkeedev.co.uk/blog/?p=115</guid>
		<description><![CDATA[I&#8217;m posting this mainly because I forget the exact syntax, but it might be useful for others. This applies to all services on all ports, but for this example I&#8217;ll use the standard IMAP port. For example, if I have a mail server (listening for IMAP connections on port 143) which isn&#8217;t accessible from outside [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m posting this mainly because I forget the exact syntax, but it might be useful for others.</p>
<p>This applies to all services on all ports, but for this example I&#8217;ll use the standard IMAP port. For example, if I have a mail server (listening for IMAP connections on port 143) which isn&#8217;t accessible from outside it&#8217;s LAN, but I have another server on the LAN which is accessible from outside &#8211; I could forward the port on the open server to give myself access to the mail server.</p>
<p>Here&#8217;s the example setup:<br />
Mail server: 10.1.0.2, listening on port 143 which isn&#8217;t accessible from outside.<br />
Other server 10.1.0.3, accessible from outside.</p>
<p>By running these 2 commands, I can forward all requests to 10.1.0.3:143 to 10.1.0.2:143 and connect to the IMAP server from anywhere:</p>
<blockquote><p>iptables -t nat -I PREROUTING 1 -i eth0 -p tcp &#8211;dport 143 -j DNAT &#8211;to-destination 10.1.0.2:143<br />
iptables -t nat -I POSTROUTING 1 -o eth0 -p tcp -d 10.1.0.2 &#8211;dport 143 -j SNAT &#8211;to-source 10.1.0.3</p></blockquote>
<p>For this to work, you will need to have IP forwarding enabled, which can be done temporarily (which will reset on reboot), or permanently:</p>
<blockquote><p>echo 1 &gt; /proc/sys/net/ipv4/ip_forward<br />
(temporary)</p>
<p>vim /etc/sysctl.conf<br />
// uncomment the line &#8216;net.ipv4.ip_forward=1&#8242;<br />
(permanent)</p></blockquote>
<p>Now if you telnet to 10.1.0.3:143, the connection should be forwarded to 10.1.0.2:143</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.monkeedev.co.uk%2Fblog%2F2009%2F04%2F03%2Fsimple-port-forwarding-using-iptables%2F&amp;title=Simple+port+forwarding+using+iptables" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.monkeedev.co.uk/blog/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.monkeedev.co.uk%2Fblog%2F2009%2F04%2F03%2Fsimple-port-forwarding-using-iptables%2F&amp;title=Simple+port+forwarding+using+iptables" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.monkeedev.co.uk/blog/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.monkeedev.co.uk%2Fblog%2F2009%2F04%2F03%2Fsimple-port-forwarding-using-iptables%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.monkeedev.co.uk/blog/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.monkeedev.co.uk%2Fblog%2F2009%2F04%2F03%2Fsimple-port-forwarding-using-iptables%2F&amp;title=Simple+port+forwarding+using+iptables" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.monkeedev.co.uk/blog/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.monkeedev.co.uk%2Fblog%2F2009%2F04%2F03%2Fsimple-port-forwarding-using-iptables%2F&amp;title=Simple+port+forwarding+using+iptables" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.monkeedev.co.uk/blog/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.monkeedev.co.uk%2Fblog%2F2009%2F04%2F03%2Fsimple-port-forwarding-using-iptables%2F&amp;title=Simple+port+forwarding+using+iptables" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.monkeedev.co.uk/blog/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.monkeedev.co.uk%2Fblog%2F2009%2F04%2F03%2Fsimple-port-forwarding-using-iptables%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.monkeedev.co.uk/blog/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Simple+port+forwarding+using+iptables+@+http%3A%2F%2Fwww.monkeedev.co.uk%2Fblog%2F2009%2F04%2F03%2Fsimple-port-forwarding-using-iptables%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.monkeedev.co.uk/blog/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.monkeedev.co.uk/blog/2009/04/03/simple-port-forwarding-using-iptables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

