<?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>Andryan's Random Notes &#187; Netfilter</title>
	<atom:link href="http://blog.nirkabel.org/category/netfilter/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nirkabel.org</link>
	<description>This blog is here to stay</description>
	<lastBuildDate>Thu, 01 Jul 2010 17:28:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>iptables mangle and NAT notes, etc.</title>
		<link>http://blog.nirkabel.org/2010/06/05/iptables-mangle-and-nat-notes/</link>
		<comments>http://blog.nirkabel.org/2010/06/05/iptables-mangle-and-nat-notes/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 17:55:08 +0000</pubDate>
		<dc:creator>Andryan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MikroTik]]></category>
		<category><![CDATA[Netfilter]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[RouterOS]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://andryan.wordpress.com/2007/05/31/iptables-mangle-and-nat-notes/</guid>
		<description><![CDATA[PREROUTING in nat table: DNAT, REDIRECT POSTROUTING in nat table: SNAT/MASQUERADE PREROUTING in mangle table: alter routing (e.g. source-based routing) FORWARD in mangle table: traffic shaping for tc (flowid) In MikroTik RouterOS, /ip firewall nat: srcnat chain = PREROUTING dstnat chain = POSTROUTING /ip firewall mangle: prerouting chain = global-in forward chain = global-out (support [...]]]></description>
			<content:encoded><![CDATA[<p>PREROUTING in nat table: DNAT, REDIRECT<br />
POSTROUTING in nat table: SNAT/MASQUERADE</p>
<p>PREROUTING in mangle table: alter routing (e.g. source-based routing)<br />
FORWARD in mangle table: traffic shaping for tc (flowid)</p>
<p>In MikroTik RouterOS, /ip firewall nat:<br />
srcnat chain = PREROUTING<br />
dstnat chain = POSTROUTING</p>
<p>/ip firewall mangle:<br />
prerouting chain = global-in<br />
forward chain = global-out (support NAT traffic shaping, higher load on router)</p>
<p>Update: I used to think that global-in literally means global input, while global-out literally means global output.  Apparently I was mistaken.  The parent queues MUST be matched to the right parent, either global-in, global-out, global-total, or one of the network interfaces depending on the mangle rules.  Top-most queue parent (global-in, global-out, global-total) doesn&#8217;t decide whether it&#8217;s up/down.  The mangle rules do the direction decision trick, whether a packet is incoming/download or outgoing/upload.  This makes perfect sense now! (doh)  I kept wondering why half of my queues (download queues&#8217; top-most parent was global-in) weren&#8217;t working, when all my mangle rules were in forward chain.  Obviously they wouldn&#8217;t, because global-in marks both direction in prerouting chain.</p>
<p>This didn&#8217;t make sense until I read the URL listed below under References.  Silly me!  Assumption is the root of most, if not all, problems indeed.</p>
<p>References:<br />
<a href="http://wiki.ispadmin.eu/index.php/Documentation/Mikrotik_guide#.22Global-in.22_vs._.22global-out.22_setup" target="_blank">http://wiki.ispadmin.eu/index.php/Documentation/Mikrotik_guide#.22Global-in.22_vs._.22global-out.22_setup </a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nirkabel.org/2010/06/05/iptables-mangle-and-nat-notes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iptables port forwarding rules for BattleNET games</title>
		<link>http://blog.nirkabel.org/2007/05/22/iptables-port-forwarding-rules-for-battlenet-games/</link>
		<comments>http://blog.nirkabel.org/2007/05/22/iptables-port-forwarding-rules-for-battlenet-games/#comments</comments>
		<pubDate>Tue, 22 May 2007 04:14:50 +0000</pubDate>
		<dc:creator>Andryan</dc:creator>
				<category><![CDATA[FTP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Netfilter]]></category>
		<category><![CDATA[Plesk]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://andryan.wordpress.com/2007/05/22/battlenet-games-iptables-rules/</guid>
		<description><![CDATA[This script will create port forwarding rules on port 36xxx to 192.168.1.xxx:36xxx.]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.nirkabel.org/wp-content/uploads/2007/05/script.txt" target="_blank">This script</a> will create port forwarding rules on port 36xxx to 192.168.1.xxx:36xxx.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nirkabel.org/2007/05/22/iptables-port-forwarding-rules-for-battlenet-games/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ipt_account HOWTO for Fedora Core 6</title>
		<link>http://blog.nirkabel.org/2007/03/18/ipt_account-howto-for-fedora-core-6/</link>
		<comments>http://blog.nirkabel.org/2007/03/18/ipt_account-howto-for-fedora-core-6/#comments</comments>
		<pubDate>Sun, 18 Mar 2007 18:44:27 +0000</pubDate>
		<dc:creator>Andryan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Netfilter]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://andryan.wordpress.com/2007/03/18/ipt_account-howto-for-fedora-core-6/</guid>
		<description><![CDATA[For the last few days I have been looking for a bandwidth monitoring tool that is more efficient, accurate, and complete than IPFM. I found so many bandwidth monitoring tools (bandwidthd, ipband, darkstat, and a few others) on Google but couldn&#8217;t find one that fits what I want. In fact, IPFM suits me better than [...]]]></description>
			<content:encoded><![CDATA[<p align="left">For the last few days I have been looking for a bandwidth monitoring tool that is more efficient, accurate, and complete than <a href="http://robert.cheramy.net/ipfm/" target="_blank" title="IP Flow Meter">IPFM</a>. I found so many bandwidth monitoring tools (bandwidthd, ipband, darkstat, and a few others) on Google but couldn&#8217;t find one that fits what I want. In fact, IPFM suits me better than the others.</p>
<p align="left">While I was reading iptables&#8217; man page, I accidentally came across &#8216;account&#8217; under &#8216;MATCH EXTENSIONS&#8217;. After reading the brief description and example, I got excited! This iptables match extension provides exactly what I need! With the flexibility of iptables&#8217; rules plus the account match extension, this has to be the best solution for my new bandwidth monitoring system. There is one problem though. Fedora Core doesn&#8217;t have it. <img src='http://blog.nirkabel.org/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p align="left">With some experience I got from installing <a href="http://www.ipp2p.org/" target="_blank" title="ipp2p">ipp2p</a> by hand, I started trying to make this iptables match extension work on my Fedora Core 6 server. First, I used Google to locate <a href="http://www.svn.barbara.eu.org/ipt_account/" target="_blank" title="ipt_account's website">ipt_account&#8217;s website</a>. Then I used Google to search for some install guides on ipt_account but couldn&#8217;t find any, so I went through its website and found <a href="http://www.svn.barbara.eu.org/ipt_account/wiki/Installation" target="_blank" title="ipt_account installation">something</a>.</p>
<p align="left">Since I have prepared my system with kernel &amp; iptables source tree, rpmbuild, etc. (basically everything required to build ipp2p modules), I will not go over the &#8220;ingredients&#8221; again. Sorry!</p>
<p align="left">Download the <a href="http://www.svn.barbara.eu.org/ipt_account/attachment/wiki/Patches/ipt_account-0.1.21-kernel-2.6.19.patch?format=raw" target="_blank">kernel</a> and <a href="http://www.svn.barbara.eu.org/ipt_account/attachment/wiki/Patches/ipt_account-iptables-1.3.5.patch?format=raw">iptables</a> patches from <a href="http://www.svn.barbara.eu.org/ipt_account/wiki/Patches" target="_blank" title="Patches for ipt_account">this page</a>. Patch the kernel tree:</p>
<ul>
<li> cd /usr/src/redhat/BUILD/kernel-2.6.19/linux-2.6.19.i386/</li>
<li> patch -p1 &lt; path_to_kernel_patch</li>
</ul>
<p align="left">You should see the following:</p>
<blockquote><p>patching file include/linux/netfilter_ipv4/ipt_account.h<br />
patching file net/ipv4/netfilter/ipt_account.c<br />
patching file net/ipv4/netfilter/Kconfig<br />
patching file net/ipv4/netfilter/Makefile</p></blockquote>
<p align="left">OK, now the kernel tree is patched. Now do <strong>make oldconfig</strong>.  You will be asked:</p>
<blockquote><p>account match support (IP_NF_MATCH_ACCOUNT) [N/m/?] (NEW)</p></blockquote>
<p align="left">Since this will be a kernel module, hit <strong>m</strong>. Once the process has finished, do <strong>make scripts/kconfig/</strong> (if you haven&#8217;t previously during ipp2p module build process). Create a temporary directory somewhere (e.g. /tmp/ipt). Copy /usr/src/redhat/BUILD/kernel-2.6.19/linux-2.6.19.i386/net/ipv4/netfilter/ipt_account.c into that directory and create a file named <em>Makefile</em>. Paste the following into <em>Makefile</em>:</p>
<p align="left">obj-m := ipt_account.o<br />
KDIR := /usr/src/redhat/BUILD/kernel-2.6.19/linux-2.6.19.i386/<br />
PWD := $(shell pwd)<br />
default:<br />
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules</p>
<p align="left">Make sure that there is a tab before $(MAKE). Save the file and execute <strong>make</strong>. If the compile process goes well, there will be a file named <em>ipt_account.ko</em> in the directory. Load the module by using <strong>insmod</strong>. Check <strong>lsmod</strong> to see the newly loaded module.</p>
<p align="left">If you have got this far, that means your kernel now supports ipt_account. Now we will add ipt_account extension for iptables. To see if your iptables has ipt_account support, do <strong>iptables -m account</strong>. If it prints out something like &#8220;Couldn&#8217;t load match `account&#8217;: &#8230;&#8221;, that means there is no iptables account extension yet.</p>
<p align="left">Let&#8217;s patch iptables source tree:</p>
<ul>
<li>cd /usr/src/redhat/BUILD/iptables-1.3.5</li>
<li>patch -p1 &lt; path_to_iptables_patch</li>
</ul>
<p align="left">Expect the following:</p>
<blockquote><p>patching file extensions/libipt_account.c</p></blockquote>
<p align="left">Open extensions/Makefile, on line 8, add <em>account</em> before <em>ah</em>. Then compile the ipt_account&#8217;s extension:</p>
<p align="left">cc -O2 -Wall -Wunused -I/usr/src/redhat/BUILD/kernel-2.6.19/linux-2.6.19.i386/include -Iinclude/ -DIPTABLES_VERSION=\&#8221;1.3.5\&#8221;  -fPIC -o extensions/libipt_account_sh.o -c extensions/libipt_account.c<br />
cc -shared  -o extensions/libipt_account.so extensions/libipt_account_sh.o</p>
<p align="left">Copy extensions/libipt_account.so to /lib/iptables and verify the extension: <strong>iptables -m account</strong>. That&#8217;s it! Pretty easy, eh? <img src='http://blog.nirkabel.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p align="left">Read <a href="http://www.svn.barbara.eu.org/ipt_account/wiki/Usage" target="_blank">this page</a> to test the new iptables account match extension. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nirkabel.org/2007/03/18/ipt_account-howto-for-fedora-core-6/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ipp2p HOWTO for Fedora Core 6</title>
		<link>http://blog.nirkabel.org/2007/01/23/ipp2p-howto-for-fedora-core-6/</link>
		<comments>http://blog.nirkabel.org/2007/01/23/ipp2p-howto-for-fedora-core-6/#comments</comments>
		<pubDate>Tue, 23 Jan 2007 18:34:07 +0000</pubDate>
		<dc:creator>Andryan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Netfilter]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://andryan.wordpress.com/2007/01/23/ipp2p-howto-for-fedora-core-6/</guid>
		<description><![CDATA[While this post is titled &#8220;for Fedora Core 6&#8243;, it may be applicable to previous versions of Fedora Core. I tested this on Fedora Core 4 too, but some steps are different. Note: This guide uses iptables-1.3.5-1.2.1 and kernel-2.6.19-1.2895.fc6. First, grab ipp2p-0.8.2.tar.gz or the latest version if there&#8217;s any. Extract the tarball and make sure [...]]]></description>
			<content:encoded><![CDATA[<p align="left">While this post is titled &#8220;for Fedora Core 6&#8243;, it <strong>may</strong> be applicable to previous versions of Fedora Core. I tested this on Fedora Core 4 too, but some steps are different.<br />
Note: This guide uses iptables-1.3.5-1.2.1 and kernel-2.6.19-1.2895.fc6.</p>
<p align="left">First, grab <a href="http://ipp2p.org/downloads/ipp2p-0.8.2.tar.gz">ipp2p-0.8.2.tar.gz</a> or the latest version if there&#8217;s any. Extract the tarball and make sure you have <em>iptables</em> and the currently installed kernel&#8217;s SRPMs installed. To proceed, I recommend <em>rpm-build</em> to be installed (simply use <em>yum</em> to install, i.e. <strong>yum install rpm-build</strong>). Next, install both SRPMs using the following command: <strong>rpm -ivh file.rpm</strong>. If you get &#8220;error: cannot create %sourcedir /usr/src/redhat/SOURCES&#8221; message, you can create the required directory: <strong>mkdir -p /usr/src/redhat</strong>. Also, <em>rpm-build</em>ing the kernel source requires <em>redhat-rpm-config</em> and <em>unifdef</em> to be installed.<br />
Now that the &#8220;ingredients&#8221; are ready, let&#8217;s start doing the fun part..</p>
<p align="left">Go to /usr/src/redhat/SPECS and do <strong>rpmbuild -bp iptables.spec</strong>, this will prepare the iptables&#8217; source tree to match with the currently installed iptables binaries&#8217; source. Do the same for the kernel, <strong>rpmbuild -bp kernel-2.6.spec</strong>. The newly patched source tree can be found inside /usr/src/redhat/BUILD directory.</p>
<p align="left">Grab <em>symvers-2.6.19-1.2895.fc6.gz</em> from /boot, <em>gunzip</em> and rename it as Module.symvers, then move it to the kernel&#8217;s source directory (/usr/src/redhat/BUILD/kernel-2.6.19/linux-2.6.19-i386). Go into that directory, make sure that existing kernel config (.config) exists, then do: <strong>make scripts/kconfig/</strong>.<br />
Note: If you can&#8217;t find symvers file in /boot, install kernel-devel package and you will find Module.symvers in /usr/src/kernels/&lt;kernel-version&gt;/.</p>
<p align="left">Next, return to the ipp2p source directory and do two modifications.</p>
<p>Add:</p>
<blockquote><p>KERNEL_SRC=/usr/src/redhat/BUILD/kernel-2.6.19/linux-2.6.19.i386</p></blockquote>
<p align="left">before</p>
<blockquote><p>KERNEL_SRC ?= $(firstword $(wildcard &#8230;</p></blockquote>
<p align="left">Add:</p>
<blockquote><p>IPTABLES_SRC = /usr/src/redhat/BUILD/iptables-1.3.5</p></blockquote>
<p align="left">before</p>
<blockquote><p>ifeq ($(IPTABLES_SRC),)</p></blockquote>
<p align="left">Save the changes and do <strong>make</strong>.</p>
<p align="left">If it compiles successfully, then ipt_ipp2p.ko and libipt_ipp2p.so should be in the directory now.<br />
Copy libipt_ipp2p.so to /lib/iptables. To verify whether this iptables module works, do <strong>iptables -m ipp2p -h</strong>.<br />
In case you get the following: iptables v1.3.8: Couldn&#8217;t load match `ipp2p&#8217;, don&#8217;t worry. Have a look at <a href="http://mailman.ds9a.nl/pipermail/lartc/2006q4/019899.html" target="_blank">this solution</a> and simply recompile the modules.</p>
<p align="left"> There are two ways to load the ipp2p kernel module, <strong>insmod ipt_ipp2p.ko</strong> or copy <em>ipt_ipp2p.ko</em> to /lib/modules/2.6.19-1.2895.fc6/kernel/net/ipv4/netfilter and do <strong>depmod -a</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nirkabel.org/2007/01/23/ipp2p-howto-for-fedora-core-6/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>
