Setting up a FreeBSD gateway

Reko Turja reko.turja at
Wed Jan 4 12:57:34 PST 2006

----- Original Message ----- 
From: "Brian Bobowski" <bbobowski at>
To: "FreeBSD User Questions List" <freebsd-questions at>
Sent: Wednesday, January 04, 2006 7:44 PM
Subject: Setting up a FreeBSD gateway

> However, I don't know how to set up DNS. Specifically, I want to 
> either pass all DNS requests through the gateway, or have the gateway 
> run a local DNS that queries my ISP's DNS in turn. Can anyone point me 
> to some steps on how to set that up?

If you're going to use BIND (which I recommend and which is included in 
the system) check at least the following parameters in named.conf:

- set this to your internal IP
- if you dont want to fetch every single record from the official DNS's 
and want to utilize your providers DNS cache, set this variable to point 
on your ISP's DNS servers.
as you're going to have your own domain records set up be sure this is 
commented out.

Basically BIND with this kind of configuration will forward queries to 
master or forwarder servers unless it has the master record itself or 
there is cached record, which is still valid.

defining the localhost:
 If the machine names are set up right in your fbsd installation, 
easiest is to use the make-localhost in the /etc/namedb directory.

Then you forward zone file for your "domain" as well as reverse zones 
for the ip-ranges in use. My files are:

master/ file:

$TTL 3600
@               IN      SOA (
; we define authority as well as the base domain (first and
; the administrative contact - as bind has other uses for "." the mail
; address is notes with dot between domain and username.
                                        2005111301      ;serial
; good idea is to use the shown date notation, and ALWAYS bump the 
serial whatever
;you do to the zone files)
                                        86400           ;refresh 24h
                                        7200            ;retry 2h
                                        192200          ;expire 2d
                                        86400)          ;minimum 24h

                IN      NS
; we define name servers for the zone only one is usually needed for 
"private" dns use.
                IN      MX  5
; I define mail handler server just in case...
moria           IN      A
rivendell       IN      A
lorien          IN      A
muppet          IN      A
;and then add my workstations

As the main forward zone is now set up, we need the reverse zones as 

My reverse zone for above setup is (master/
$TTL 1d
@               IN      SOA (
                                        2005111301      ;serial
                                        1d              ;refresh
                                        2h              ;retry
                                        20d             ;expire
                                        2h )            ;neg cache

                IN      NS

1               IN      PTR
10              IN      PTR
11              IN      PTR
20              IN      PTR

With BIND the dots after the names are important, otherwise the names 
end up as which usually isn't what you want :)

After the zones are set up you can add them to named.conf as follows:

zone "" {
        type master;
        file "master/";

zone "" {
        type master;
        file "master/";

In the above note the naming of reverse zone. To get correct resolution 
of reverse names you need to name your zone with similar formatting.

Hope this helps a bit (although I recommend getting Bind handbook 
8available from ISC as pdf, or some of the "basic" BSD books like Greg 
Lehey's, Or Michael Lucas's books on Freebsd - both have a good chapter 
on DNS setup with BIND. Of course nothing beats the O'Reilly Cricket 


More information about the freebsd-questions mailing list