Setting up IPNAT on FreeBSD 4.0

This document will explain how to set up IPNAT on FreeBSD 4.0. NAT is the translation of internal addresses to external addresses. This is commonly done on a gateway machine such as a dial-up box (or DSL and Cable) at home where you have more than one computer. This allows all of your boxes to share a single connection to your ISP. There are many different configurations you can use to set up an internal network with IPNAT. This doc will explain how to use two network cards in a single FreeBSD machine, one hub, and a DSL/CABLE modem. If you want basic directions on how to set up ipnat with one network card, go to this page.


                    |       FreeBSD Box     |
                    |                       |
                    |  NIC 1         NIC 2  |
                    |  +---+         +---+  |
                    |  |xl0|         |xl1|  |
                    +--/   \---------/   \--+
                         ^             v
    +---------+          |             |                 +--------+
--> |DSL/CABLE| ---------+             |        +--------| Host A |
    |  modem  |                        |        |        +--------+
    +---------+                        |        |
                                    +-----+     |
+----------------------------+      |     |     |        +--------+
| NIC 1 (xl0) -  |      |     |     |   +----| Host B |
| NIC 2 (xl1) -  |      |     =-----+   |    +--------+
+----------------------------+      | HUB |         |
| Host A      - |      |     =---------+
| Host B      - |      |     |              +--------+
| Host C      - |      |     =--------------| Host C +
+----------------------------+      |     |              +--------+

Any IP within is solely for internal networks. That is why it is used here. The following will work just as well:

It is assumed that your FreeBSD machine already boots up with your first network card (in this case xl0) running with an IP address from from your ISP.

Step 1 - Enable ipnat in kernel:

You must add the following line to your kernel:

     options         IPFILTER                #kernel ipfilter support
(WHAT!? You don't know how to compile a kernel? Okay, go here.)

And add the following to /etc/rc.conf:

Step 2 - Configure ipnat:

Create the file '/etc/ipnat.conf' with the following:

map xl0 -> portmap tcp/udp 10000:60000
map xl0 ->

Of course change the to the IP offered to you by your ISP.

Step 3 - Configure Start-Up Scripts:
Create the file '/usr/local/etc/rc.d/' with the following:

/sbin/ifconfig xl1 down
/sbin/ifconfig xl1 inet netmask 0xffffff00 broadcast
/sbin/ifconfig xl1 up 
[ -x /sbin/ipnat ] && /sbin/ipnat -CF -f /etc/ipnat.conf && ipf -y && echo -n 'ipnat'

And change the permissions so root can execute it. (ie chmod 750).

Step 4 - Shutdown - Setup Hardware - Bootup - Confirm:
Now, shutdown the box, setup the hardware as described in the layout above, and turn the box back on.

Once the machine has booted up, run "ifconfig -a". You should get something like this:

xl0: flags=8843 mtu 1500
	inet netmask 0xfffff800 broadcast
	ether 00:10:4b:68:87:32 
	media: autoselect (10baseT/UTP) status: active
	supported media: autoselect 100baseTX  100baseTX 10baseT/UTP  10baseT/UTP 100baseTX 
xl1: flags=8843 mtu 1500
        inet netmask 0xffffff00 broadcast
	ether 00:e0:29:6e:13:7f 
	media: autoselect (none) status: active
	supported media: autoselect 100baseTX  100baseTX 10baseT/UTP  10baseT/UTP 100baseTX 

The important part you should be looking at is the lines starting with "inet".

Step 5 - Setting up the other hosts:
The computers that you connect to the hub should have the following network configuration:

IP:      192.168.5.x where 254>x>1 
DNS:     Should be offered by your ISP.

This is what I got to work for me. If you are still having problems, or you have questions about this doc, just let me know.

[ sys admin/programming | home | e-mail | viperstrike ]