Skip to content

Independent notes on FreeBSD · published since 1999

The FreeBSD 'zine Features, news and community notes for FreeBSD

Issue 6 · July 2000

Reader written notes on FreeBSD, from the command line to the server room.

Open the current issue

January 1999 · Featured article

Firewalls

ipfw and natd

Gateways: Installing natd/ipfw, firewall, dual homed host

A gateway allows one computer to talk to an outside network and channel requests from other computers. If you have more than one computer, it makes sense to have one of them act as the gateway to your ISP. It allows all of your computers to share a single modem. It's easy and it's cheap.

You don't want to do this if you are running ppp. See the man pages for information on alias.

One of the best ways to create a gateway is by using ipfw and natd. ipfw is an Internet Packet Firewall. Even though you may not want a firewall, it's the best way to achieve a gateway.

Installation instructions

These instructions are taken directly from the FreeBSD Handbook. Please refer to that document for further information. This section assumes that the network card which is attached to your ISP is ed0. You should substitute your own interface if necessary.

1) You need FreeBSD version 2.2 or higher

Obtaining FreeBSD is not covered in this section. Please refer to the section of the FreeBSD Handbook.

2) Build a custom kernel

I highly recommend you read Configuring the FreeBSD Kernel section of the FreeBSD Handbook. Please pay special attention to the Building and Installing a Custom Kernel section. The rest of this section contains the highlights for those that know how to build a kernel.

Include these options in your new kernel:

 options IPFIREWALL options IPDIVERT 

If this is the first time you've created a new kernel, you may wish to reboot and install that new kernel. Make sure your kernel reboots safely with no error messages. If all you have done is the above changes, it should go very smoothly.

3) Create a gateway/firewall

Ensure your machine acts as a gateway and a firewall by including the following lines in /etc/rc.conf:

 gateway_enable=YES firewall_enable=YES 

4) Configure your interface

Make sure your network cards are already configured. Sorry, but I don't cover that here. If you're using ppp, make sure you start ppp before running natd.

5) Add natd to your services

Ensure the following line appears in /etc/services:

 natd 8668/divert # Network Address Translation socket 

6) Start natd

This can be added to /etc/rc.local:

 natd interface ed0 

7) Redirect the traffic to natd

You will need at least the following commands:

 /sbin/ipfw f flush /sbin/ipfw add divert natd all from any to any via ed0 /sbin/ipfw add pass all from any to any 

See for more information.

8) Reboot

In order for the changes you've made to take effect, you'll need to reboot. Things should run smoothly now.

If it doesn't work

If the above does not get things working for you, then . Perhaps my instructions are defective. I don't think so, but please tell me of any problems you had and what you did to correct them.

Dan

On the web

Further reading from the FreeBSD community and the projects named in this article.

Issue contents

Issue 1 · Jan 1999

Firewalls

IPFilter

By Dan Langille

IP Filter: An alternative firewall and NAT to ipfw/natd. I was having some problems with natd and ipfw. It was suggested by by Darren Reed that I...

Read the article

Issue 1 · Jan 1999

Consulting

Consulting with FreeBSD

By John Sconiers

In early 1997, a few friends and I began to venture into the world of consulting. We had experience consulting before, however setting out on our own...

Read the article

Issue 1 · Jan 1999

Apache

Web Server Installation and Configuration

By Jim Mock

Okay, so you've got a system, and you've installed FreeBSD on it, and now you want to make it a web server. The most common web server is Apache,...

Read the article