<?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>Dambar Raj Paudel</title>
	<atom:link href="http://drpaudel.com.np/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://drpaudel.com.np</link>
	<description>Computer Network Researcher</description>
	<lastBuildDate>Sun, 08 Aug 2010 00:21:25 +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>Routing</title>
		<link>http://drpaudel.com.np/?p=155</link>
		<comments>http://drpaudel.com.np/?p=155#comments</comments>
		<pubDate>Sun, 08 Aug 2010 00:19:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[ICT Blog]]></category>
		<category><![CDATA[Networking FreeBSD]]></category>

		<guid isPermaLink="false">http://localhost/drpaudel.com.np/?p=155</guid>
		<description><![CDATA[routing]]></description>
			<content:encoded><![CDATA[<p>routing</p>
]]></content:encoded>
			<wfw:commentRss>http://drpaudel.com.np/?feed=rss2&amp;p=155</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NAT in FreeBSD</title>
		<link>http://drpaudel.com.np/?p=73</link>
		<comments>http://drpaudel.com.np/?p=73#comments</comments>
		<pubDate>Tue, 03 Aug 2010 02:12:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Home Page]]></category>

		<guid isPermaLink="false">http://localhost/bishnu/?p=73</guid>
		<description><![CDATA[Network Address Translation (NAT) IP Filter Step 1: Install Kernel Note: If there is not a /usr/src/sys directory on your system, then the kernel source has not been installed. The easiest way to do this is by running sysinstall as &#8230; <a href="http://drpaudel.com.np/?p=73">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Network Address Translation (NAT)</strong><br />
<strong>IP Filter</strong><br />
<em><strong>Step 1: Install Kernel</strong></em></p>
<div style="border: 1px solid #666666;"><strong>Note:</strong> If there is <em>not</em> a /usr/src/sys directory on your system,  then the kernel source has not been installed. The easiest way to do this is by  running sysinstall as root, choosing Configure, then Distributions, then src,  then base and sys. If you have an aversion to <strong>sysinstall</strong> and you have  access to an “official” FreeBSD CDROM, then you can also install the source  from the command line:</div>
<p><span id="more-73"></span>Step 2: Compile Kernel</p>
<div style="border: 1px solid #666666;">$ cd /sys/i386/conf<br />
$cp GENERIC IPFILTERKERNEL</div>
<p>Open the new kernel</p>
<div style="border: 1px solid #666666;">$vi IPFILTERKERNEL</div>
<p>Add following lines.</p>
<div style="border: 1px solid #666666;">options                IPFILTER<br />
options                IPFILTER_LOG<br />
options                IPFILER_DEFAULT_BLOCK<br />
options                IPSTEALTH<br />
options                TCP_DROP_SYNFIN　// If it does not work just comment out.<br />
ident      IPFILTERKERNEL</div>
<p>After writing those options in conf file as shown  above, you need to execute the following commands.</p>
<ul>
<li style="text-align: left;">config [Configuration Filename]  for example</li>
</ul>
<div style="border: 1px solid #666666;">$config IPFILTERKERNEL</div>
<ul>
<li>The kernel build directory will  be located in ../compile/IPFILTERKERNEL</li>
</ul>
<p>Now  change directory to IPFILTERKERNEL</p>
<ul>
<li>Execute the following commands</li>
</ul>
<div style="border: 1px solid #666666;">$make cleandepend &amp;&amp; make depend        # It will take time to make the kernel</div>
<ul>
<li>Make the kernel</li>
</ul>
<div style="border: 1px solid #666666;">$make<br />
$make install</div>
<ul>
<li>Reboot your system</li>
</ul>
<p>Step 3: Edit /etc/rc.conf File<br />
Enter the following line in rc.conf</p>
<div style="border: 1px solid #666666;">hostname=&#8221;Your full  Qualified FQDN &#8221;<br />
ifconfig_bge0=&#8221;DHCP&#8221; # connected to Internet and getting 10.16.96.175<br />
ifconfig_nge0=&#8221;inet 192.168.0.1/24&#8243; #  Interface Running for NAT<br />
gateway_enable=&#8221;YES&#8221;<br />
ipfilter_enable=&#8221;YES&#8221;<br />
ipfilter_rules=&#8221;/etc/ipf.rules&#8221;<br />
ipnat_enable=&#8221;YES&#8221;<br />
ipnat_rules=&#8221;/etc/ipnat.rules&#8221;<br />
ipmon_enable=&#8221;YES&#8221;<br />
tcp_drop_synfin=&#8221;YES&#8221;<br />
icmp_drop_redirect=&#8221;YES&#8221;<br />
icmp_log_redirect=&#8221;YES&#8221;<br />
keymap=&#8221;jp.106&#8243;<br />
sshd_enable=&#8221;YES&#8221;</div>
<p>Step4: Edit /etc/ipf.rules<br />
Create a IP Filter rule file.</p>
<div style="border: 1px solid #666666;">$ vi /etc/ipf.rules</div>
<p>Write rules as below. This is very simple rule.  More rule can be defined.</p>
<div style="border: 1px solid #666666;">pass in all<br />
pass out all</div>
<p>Step4: Edit  /etc/ipnat.rules</p>
<p>Write NAT rules as below. NAT rules can be added as  per need in new line.</p>
<div style="border: 1px solid #666666;">map bge0 192.168.0.0/24 -&gt; 10.16.96.175/32 portmap tcp/udp 49152:65535<br />
map bge0 192.168.0.0/24 -&gt; 10.16.96.175/32</div>
<p>Restart your system</p>
<div style="border: 1px solid #666666;">shutdown -r now</div>
<p><strong>IPFW ( FreeBSD IP Packet Filter)<br />
</strong></p>
<hr />
Ipfirewall (ipfw) is a FreeBSD IP packet filter and  traffic accounting facility. IPFW is included in the basic FreeBSD install as a  separate run time loadable module. The system will dynamically load the kernel  module when the rc.conf statement firewall_enable=&#8221;YES&#8221; is used.</p>
<ol>
<li>
<ol>
<li>
<ol>
<li>Step1. Install Kernel</li>
</ol>
</li>
</ol>
</li>
</ol>
<div style="border: 1px solid #666666;"><strong>Note:</strong> If there is <em>not</em> a /usr/src/sys directory on your system,  then the kernel source has not been installed. The easiest way to do this is by  running sysinstall as root, choosing Configure, then Distributions, then src,  then base and sys. If you have an aversion to <strong>sysinstall</strong> and you have  access to an official” FreeBSD CDROM, then you can also install the source  from the command line:</div>
<ol>
<li>
<ol>
<li>
<ol>
<li>Step 2: Compile Kernel</li>
</ol>
</li>
</ol>
</li>
</ol>
<p>Copy kernel to your new kernel file.</p>
<div style="border: 1px solid #666666;">$cd /sys/i386/conf<br />
$cp GENERIC MYKERNEL</div>
<p>Open the kernel file</p>
<div style="border: 1px solid #666666;">$vi MYKERNEL</div>
<p>Add following lines.</p>
<div style="border: 1px solid #666666;">options IPFIREWALL                                                  # required for IPFW<br />
options IPFIREWALL_VERBOSE                               # optional; logging<br />
options IPFIREWALL_VERBOSE_LIMIT=10             # optional; don&#8217;t get too many log entries<br />
options IPDIVERT                                                      # needed for natd</div>
<p>After writing those options in conf file as shown  above, you need to execute the following commands.</p>
<ol>
<li>config [Configuration Filename] for example</li>
</ol>
<div style="border: 1px solid #666666;">$config MYKERNEL</div>
<ol>
<li>The kernel build directory will  be located in ../compile/MYKERNEL</li>
</ol>
<p>Now  change directory to MYKERNEL</p>
<ol>
<li>Execute the following commands</li>
</ol>
<div style="border: 1px solid #666666;">$make clean depend &amp;&amp; make depend        # It will take time to make the kernel</div>
<ol>
<li>Make the kernel</li>
</ol>
<div style="border: 1px solid #666666;">$make<br />
$make install</div>
<ol>
<li>
<ol>
<li>
<ol>
<li>Enabling IPFW</li>
</ol>
</li>
</ol>
</li>
</ol>
<p>Open /etc/rc.conf file</p>
<div style="border: 1px solid #666666;">$ vi /etc/rc.conf</div>
<p>Add the following line  into this file:</p>
<div style="border: 1px solid #666666;">hostname=&#8221;Your full  Qualified FQDN &#8221;<br />
ifconfig_bge0=&#8221;DHCP&#8221; # connected to Internet and getting 10.16.96.175<br />
ifconfig_nge0=&#8221;inet 192.168.0.1/24&#8243; #  Interface Running for NAT<br />
firewall_enable=&#8221;YES&#8221;<br />
firewall_type=&#8221;OPEN&#8221;<br />
gateway_enable=&#8221;YES&#8221;<br />
natd_enable=&#8221;YES&#8221;<br />
natd_interface=&#8221;bge0<br />
firewall_script=&#8221;/etc/ipfw.rules&#8221;<br />
gkeymap=&#8221;jp.106&#8243;<br />
sshd_enable=&#8221;YES&#8221;</div>
<p>You need to place a firewall rules in a script  called /etc/ipfw.rules:</p>
<div style="border: 1px solid #666666;">$vi /etc/ipfw.rules</div>
<p>Add the following line  into this file:</p>
<div style="border: 1px solid #666666;">#!/bin/sh<br />
## Define Variable cmd for calling script ipfw<br />
cmd=&#8221;ipfw -q add&#8221;<br />
##Flush existing rules<br />
ipfw -q flush<br />
## Divert ip4 from outer Interface connected to Internet<br />
$cmd 10 divert natd ip4 from   any to any  via bge0<br />
## Rule Goes here<br />
$cmd 20 allow tcp from any to  any 21<br />
$cmd 30 allow tcp from any to any 22<br />
$cmd 40 allow tcp from any to any 23<br />
$cmd 50 deny tcp from  192.168.0.2 to any 80<br />
$cmd 60 allow tcp from any to  any 80<br />
$cmd 70 allow ip from any to any</div>
<p>Restart your system</p>
<div style="border: 1px solid #666666;">shutdown -r now</div>
<p>Now let&#8217;s see if natd is running:</p>
<div style="border: 1px solid #666666;">$ ps -auxw |grep nat</div>
<p>Recover old Kernel<br />
In case new kernel is not functioning well the  following step will drive you to recover old kernel.<br />
Restart your FreeBSD Machine</p>
<div style="border: 1px solid #666666;">shutdown -r now</div>
<p>Stop the normal booting process by press option 6  [Escape to loader prompt] in your keyboard.<br />
Enter the following command.</p>
<div style="border: 1px solid #666666;">unload<br />
load  /boot /kernel.old/kernel<br />
boot</div>
<p>Now  your previous kernel will be recovered.<br />
Check  your kernel version now</p>
<div style="border: 1px solid #666666;">$uname -a</div>
]]></content:encoded>
			<wfw:commentRss>http://drpaudel.com.np/?feed=rss2&amp;p=73</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
