Introduction to OpenBSD
Unix Workstation

Shamim Mohamed

This is a quick tutorial on how to set up an OpenBSD 3.1 system. The first part covers setting up a firewall, NAT proxy, time and DHCP server on a system connected to the Internet via broadband like DSL or cable. The second part covers things that would be installed on a desktop machine: graphical window managers etc.

The reader is not expected to be a Unix expert (why would a Unix expert need this how-to?) -- if you don't understand something, or something looks intimidating, read on and come back to it. If something still doesn't make sense, let me know.

I don't cover what I consider "advanced" usage such as tracking -CURRENT or CVS snapshots. If you want to do that, I assume you know which FAQs to read!

Copyright © 2001-2002 Shamim Mohamed

This document may be freely reproduced and redistributed under the terms of the GNU Free Documentation License Version 1.1; with the invariant section being this entire document, with no Front-Cover Texts and no Back-Cover Texts.

In other words, if you want to copy this document in its entirety, feel free to do so; if you wish to modify it (as in providing a translation, or taking sections to include in other documents) please send me email. Needless to say, documents that this document links to will have their own copyrights.


I have a shell script that sets up everything mentioned here. This is still experimental but if you try it, please let me know how it goes. Save this file to disk and run it by typing "sh". (Doesn't handle PPPoE [the beast].)

There is a new section called Tips and Stuff where I put things I've found or written that are useful sysadmin tools.


Why OpenBSD? It's simple and secure. Your firewall machine should not have lots of things installed on it; therefore no exotic hardware, graphical desktops, X11 servers etc. -- put those on your desktop machine. A simpler system is more robust and more secure; this machine only offers SMTP (email), ssh, ping/traceroute and optionally HTTP (web) to the outside world. And since it's running Unix, you can log in to it -- securely -- using ssh from anywhere on the Internet and make any changes you need to. (N.B.: never use telnet to connect to a machine over the Internet! Anyone can eavesdrop and grab important information like passwords. Only use ssh, which encrypts all communication so that eavesdroppers don't get any information. And verify those key fingerprints or you leave yourself open to a man-in-the-middle attack. For information do a web search for public key cryptosystems; a good place to start is OpenSSH.)

The utility and security of having this kind of machine: a firewall protects your data and systems from the Big, Bad Internet. When the bad guys are out to vandalise machines on the Internet, MS-Windows machines of various kinds are prime targets because they suck. Er, I mean, Windows is really hard to secure. (Not that an incompetently run Unix machine is any better, of course.) When you dialled in on the phone, your machine was on the 'net for brief periods; with DSL or cable it's vulnerable all the time.

This document also describes how to set up an OpenBSD system as a Unix workstation. We will go over setting up X11 (the window system) etc. I assume that you will be using a different machine as your workstation. Important: Unix systems can be set up in various ways; I do things a certain way and that's what this document will cover. Other people (wizards and newbies alike) may do things differently. In case it matters, I've been using Unix since 1982, have been a sysadmin on-and-off since 1986 (VAX/BSD, SunOS 4.x, Solaris 2.x, HP/UX, AT&T 3B5 SVR6 etc.) I've been a C programmer since the early 80s. Today I design and implement back-end network servers on Solaris.

This tutorial assumes that you have some familiarity with using Unix: what filenames look like, how to copy and edit files etc. There's a decent Unix tutorial on the web. The most important command to remember is man (short for "manual") -- if I say something like "read the documentation for foobar it means you should type man foobar. One other piece of Unix argot: if you hear someone write select(2) it indicates that the manual for select is in section 2, i.e. you would read the manpage by typing man 2 select. You should also read the OpenBSD documentation: particularly the OpenBSD FAQ. Bookmark that link right now.

NAT (Network Address Translation) allows you to connect lots of PCs up to one network connection. When any of the machines inside the firewall wants to make a connection to some server out there on the internet, the firewall/NAT box intercepts that request, and sends the request off as though it came from the firewall/NAT machine. When the reply arrives, it is sent off to the machine that made the connection. Neither the server nor the machines on the inside know that all this is going on.

Aside: NAT is also called PAT, for "Port Address Translation." Also, read this interesting article by HRH Prince Philip, Duke of Edinburgh, on setting up PAT and DHCP on Cisco routers. The whole site features many celebrities offering helpful tips on various network issues.

Even if you don't want plan on having more than one PC at home, NAT is useful, because it allows the machine running your firewall to be different from your main workstation. You probably want to install fancy hardware and software on your machine; but every additional package installed on a firewall makes it more vulnerable.

Network Address Translation (NAT)

Note: if you only have one machine on the "inside", you don't need an ethernet hub; use a crossover cable to connect the two machines directly. This also has the advantage that you can get a full-duplex connection between the machines (a hub only allows a half-duplex connection).

Note: you can buy little NAT/DHCP boxes from various manufacturers for about $150, but where's the fun in that? Besides, who knows how strong the security is on those things. With OpenBSD you know you're getting the best.

Building the machine

The machine itself: I prefer to build these machines up from individual components rather than buying a pre-made box. That way I can get name-brand supported components, and it works out slightly cheaper since I don't have to get exotic video cards, sound cards, CD-ROM drives etc. (Not to mention a Fisher-Price operating system that you will be required to pay for.)

Can you build a PC? Well, no one showed me how, but I've managed to put together about 10 or so systems, so it can't be that hard. If you've assembed anything with screwdrivers etc. you'll be fine. There are numerous sites on the web that walk you through building a PC. Go do a Google search and read those. I especially like the one at Acme Labs by Jef Poskanzer. There's also an excellent motherboard finder at Acme.

Caveat: specific recommendations will be outdated as soon as I write them! I like to use AMD CPUs because I believe Intel is evil and as far as possible I'd like to not buy their products. I'd get the current not-top-of-the-line CPU i.e. the one that costs about $50 and a compatible motherboard that costs in the range of $70. I stay away from integrated components because they're usually garbage. (For a server that I don't use directly I might get integrated video.) Spend about $30-50 on RAM, $30 on ethernet, $60 on an IDE disk, $30 for a case (with power supply). I usually find the best prices on components at Directron and CompuVest (warning: uses Java). These have both been non-sleazy (everything was as described in their catalog and shipping was prompt) in all my dealings with them -- but let me know if you find any evidence of sleaziness.

All these components add up to around $300 -- and that's brand-new stuff. If you have any old components lying around, they will be fine. You don't need a keyboard, mouse or monitor when the system is up and running -- all maintenance on it can be done over the network. (While you're installing the OS on the machine you will need to hook up a keyboard, monitor and CD-ROM drive to it, of course.)

While installing the system, I plug in a spare CD-ROM drive, keyboard and monitor. Change the BIOS settings so that the machine will boot without a keyboard etc. Boot off the OpenBSD 3.1 CD and install the system. All the hardware should be recognised without any problems. (The installation guide booklet that comes with the CDs is excellent.)

The easiest way to install OpenBSD is to buy the distribution on CDs. Although you can install it via the network, buying the CD will help make sure that the OpenBSD project will continue to improve and better the system. If you can afford an outlay of US$40, please buy the CDs from the OpenBSD ordering site.

When you're installing OpenBSD, the installer program will ask you for disklabel information (partitions). On a Unix system, a group of files organised together is called a filesystem. The disk is partitioned into various pieces each of which will hold one filesystem. This is the filesystem breakup and partition sizes I'd use for a 12GB disk (if your disk is bigger, you can just increase the size of /var (for web files) or /home (for your personal files) -- the system will be more than happy with these sizes for /, /tmp and /usr):

/dev/wd0a      100M     /
/dev/wd0d      400M     /tmp
/dev/wd0e      4GB      /var
/dev/wd0g      2GB      /usr
/dev/wd0h      5GB      /home    

(The convention is that a is always /, b is swap and c is the whole disk.) Your web files will live in /var, and your other files in /home.

This is all overkill; /usr only needs about 600M or so. Say pad it to 1GB. A 2GB disk would be plenty for the system, but if the cheapest disk you can get is 13GB....

Note for Unix newcomers: the disk is named /dev/wd0, and in this case it has 5 partitions with names /dev/wd0a, /dev/wd0d, /dev/wd0e, /dev/wd0g and /dev/wd0h. And the different partitions don't get different "drive letters" as in some primitive operating systems; once the system is installed, it looks to the user that there is just one bunch of files; Unix will figure out the right thing to do. After the system has been installed and you've booted off the hard disk, log in and (this is important!) type man afterboot; it will remind of some things that you need to do to complete the installation -- pick passwords, create user accounts, check network settings etc. Also, man hier will introduce you to the way the system is organised -- which files live where. In fact, let me say that again:

After the first normal boot of the system, be sure to read these manpages:
$  man afterboot
$  man hier      

Also run dmesg(8) to learn more about your hardware and the driver names that OpenBSD uses for them.

Which packages to install? A good starting point would be to accept the defaults. For a desktop system (workstation), you will want all the X11 packages also. I install everything.

There! And make sure you keep reading the manpages -- OpenBSD manpages are a thing of beauty, complete, up-to-date and informative. And also read the OpenBSD FAQ on the web -- much of this information is also found there.

Configuring the network

For my outside connection I have DSL and a static IP number (from Speakeasy -- I recommend them over PacBell etc. -- I'm so happy I switched). Other DSL options are PPPoE that PacBell likes to set people up with, or DHCP which is what you usually get over cable. A completely bogus DSL installation is the USB device they try to foist on customers with Windows. Danger, Will Robinson! They stink; they're unsupported on any free O/S, and even on Windows they work about half the time.

In *BSD the network cards are named according to the driver used. For the Lite-On (DEC Tulip) cards, the driver is called dc, and the Intel EtherExpress Pro is fxp; so my two ethernet cards are dc0 and fxp0. (If you had two cards that both used the dc driver, they would be dc0 and dc1.) For the inside network I use the "private" (non-routable) IP numbers 192.168.1.* which will make the inward-facing network card The OpenBSD initialization asks you for IP numbers for the two cards. Enter the appropriate ones - the IP number your ISP gave you for dc0, and for fxp0. For PPPoE, the outside interface is tun0 and it will figure out its own IP address. If you're supposed use DHCP on your DSL or cable connection, type in dhcp.

It is important to remember which network will be the outside and which the inside. If the two cards are identical, the easiest way is to look at the MAC number. Every ethernet card ever made has a unique ID called its MAC number. This will be printed on the card, usually as a sticker. When the kernel boots up, it will print the MAC numbers of each card it finds:

fxp0 at pci0 dev 9 function 0 "Intel 82557" rev 0x0c: irq 11, address 00:02:b3:a0:3a:50
dc0 at pci0 dev 10 function 0 "Lite-On PNIC" rev 0x20: irq 10 address 00:a0:cc:55:ab:1c 

So the card that has a MAC number ending ab1c is dc0; the other is fxp0. (If the two network cards you have are different types, as in this case, there's no problem, of course. The kernel bootup messages is still be useful to tell you what names the system is using for them.)

(There's some rule about where the cards are plugged in so which one gets number 0 and which no. 1, but I can never remember that.)


The beast! PPPoE is a pain in the ass but ISPs like it because it makes things simpler for them -- they don't have to maintain lists of IP numbers. Also, they can run a crappy service and keep dropping the connection and that's ok, you're expected to reconnect. It's the Micros**t philosophy of "make something really crappy and expect people to just re-start the whole system a couple of times a day." It's a pain in the ass for us because its MTU is 1492 instead of 1500 which used to require changes on every machine inside the network -- but now thanks to the "mssfixup" flag we don't have to any more.

The files you will need to change for PPPoE all live in /etc/ppp/.

Configure system files

To set up the system, the files you will be editing are:/etc/rc.conf, /etc/myname, /etc/mygate, /etc/pf.conf, /etc/nat.conf, /etc/*.conf, /etc/hostname.interface, /var/named/*.

Edit /etc/rc.conf. On my servers I run SMTP, Apache, and ssh. In other words, from the outside it handles email, web acess and secure shell for remote logins. For convenience, on the inside I have a private name server (DNS) and NTP server for accurate time. To get sendmail, NTP, httpd, and NAT to work, these are the lines to change:

sendmail_flags="-bd -q30m"      # for normal use: "-bd -q30m"
named_flags=""                  # for normal use: ""
ntpdate_flags="" # for normal use: NTP server; run before ntpd starts
httpd_flags=""                  # for normal use: "" (or "-DSSL" after reading ssl(8))
dhcpd_flags=-q                  # for normal use: "-q"
pf=YES                          # Packet filter / NAT
ntpd=YES                        # run ntpd if it exists       
pf_rules=/etc/pf.conf           # Packet filter rules file
nat_rules=/etc/nat.conf         # NAT rules file    

Make sure that /etc/sysctl.conf has this line in it:

net.inet.ip.forwarding=1        # 1=Permit forwarding (routing) of packets    

Get the names of NTP servers close to where you are and put that name in the ntpdate value. Here's a list of public NTP servers.

Update ssh

Warning: ssh in OpenBSD 3.1 has a bug!

Upgrading openssh to 3.4 is strongly recommended. See the OpenSSH for OpenBSD page for details. In brief, you will download and execute the following steps (as root):

# cd /usr/src/usr.bin
# tar xvfz .../openssh-3.4.tgz
# cd ssh
# make obj
# make cleandir
# make depend
# make
# make install
# cp ssh_config sshd_config /etc/ssh
# mkdir /var/empty      

Using vipw(8) you will add this line to your password file:

sshd:*:27:27::0:0:sshd privsep:/var/empty:/sbin/nologin      

Then add this line to /etc/group:


NAT and firewall rules

OpenBSD 3.1 has a new packet filter -- 2.9 used ipf but 3.x has a re-written from scratch one called pf. The details are not important; pf config files are much simpler. I decided that my outside interface would be dc0, and the inside one fxp0. (If you're using PPPoE, the outside interface will be tun0.) Firewall rules (they tell the gateway what kind of network traffic should be allowed into the internal network) live in /etc/pf.conf; NAT configuration is in /etc/nat.conf.

Here's a sample /etc/pf.conf -- very little is accessible from the outside, but machines on the inside can go out with no restrictions. In your files you'd replace dc0 and fxp0 with the names of your outward- and inward-facing ethernet cards, respectively.

# IP packet filtering rules (firewall)
# Shamim Mohamed 3/2002

# See pf.conf(5) for syntax and examples

# If you change this file, run
#    pfctl -R /etc/pf.conf
# to update kernel tables (also run "pfctl -e" if pf was not running)

# Network interfaces
internal = "fxp0"
external = "dc0"

# Services visible from the outside -- remove any you're not using
services = "{ ssh, http, https, smtp }"

# You shouldn't need to change anything below this line

# Non-routable IP numbers
nonroutable = "{,,,,,,,,, }"

# All rules are "quick" so go strictly top to bottom

# Fix fragmented packets
scrub in all

# Don't bug loopback
pass out quick on lo0 from any to any
pass in quick on lo0 from any to any

# Don't bother the inside interface either
pass out quick on $internal from any to any
pass in quick on $internal from any to any

# First, we deal with bogus packets.

# Block any inherently bad packets coming in from the outside world.
# These include ICMP redirect packets and IP fragments so short the
# filtering rules won't be able to examine the whole UDP/TCP header.
block in log quick on $external inet proto icmp from any to any icmp-type redir

# Block any IP spoofing atempts.  (Packets "from" non-routable
# addresses shouldn't be coming in from the outside).
block in quick on $external from $nonroutable to any

# Don't allow non-routable packets to leave our network
block out quick on $external from any to $nonroutable


# Now the normal filtering rules

# ICMP: allow incoming ping and traceroute only
pass in quick on $external inet proto icmp from any to any icmp-type { \
    echorep, echoreq, timex, unreach }
block in log quick on $external inet proto icmp from any to any

# TCP: Allow ssh, smtp, http and https incoming. Only match
# SYN packets, and allow the state table to handle the rest of the
# connection.
pass in quick on $external inet proto tcp from any to any port $services flags S/SA keep state

# Of course we need to allow packets coming in as replies to our
# connections so we keep state. Strictly speaking, with packets
# coming from our network we don't have to only match SYN, but
# what the hell.
pass out quick on $external inet proto tcp  from any to any flags S/SA keep state
pass out quick on $external inet proto udp  all keep state
pass out quick on $external inet proto icmp from any to any keep state

# End of rules. Block everything to all ports, all protocols and return
# RST (TCP) or ICMP/port-unreachable (UDP).
block return-rst in log quick on $external inet proto tcp from any to any
block return-icmp in log quick on $external inet proto udp from any to any
block in quick on $external all

# End of file

Read the pf documentation and understand these rules.

This is the NAT config /etc/nat.conf -- this allows machines on the inside network to transparently make connections to the outside world:

# NAT rules
# Shamim Mohamed 3/2002

# See nat.conf(5) for syntax and examples

# replace dc0 with external interface name, with internal
# network (if different)

# nat: packets going out through dc0 with source address will
# get translated as coming from (or whatever the external IP no.
# is). State is created for such packets, and incoming packets will be
# redirected to the internal address.

nat on dc0 from to any -> dc0

# End of file

The system should already have setup /etc/hostname.dc0 and /etc/hostname.fxp0 (or whatever your network device names are) for you. Each file will have the IP number and netmask. This is what these files would look like:

$ cat /etc/hostname.fxp0
inet NONE 
$ cat /etc/hostname.dc0
inet NONE    

(The $ is the prompt; cat types a file out to the output.) If you're using DHCP, the outside interface's hostname file will say dhcp.

Other important files are /etc/myname -- your hostname -- and /etc/mygate -- your default gateway to the outside world (your ISP told you what this should be -- it's usually the same as your IP number except that the last number is replaced with a 1 or 254.)


If you have PPPoE (you unfortunate soul!) things are different. You shouldn't have /etc/mygate; and the file describing the outside interface, /etc/hostname.dc0 in my example, will only have one word in it: up. This tells the system to bring up the interface at boot time, but to do nothing else -- pppoe will do the rest.

The main file is /etc/ppp/ppp.conf and this is what it should look like:

 set log Phase Chat LCP IPCP CCP tun command
 set redial 15 0
 set reconnect 15 10000

 set device "!/usr/sbin/pppoe -i dc0"
 disable acfcomp protocomp
 deny acfcomp
 set mtu 1492
 set speed sync
 enable lqr
 set lqrperiod 5
 set cd 5
 set dial
 set login
 set timeout 0
 set authname login
 set authkey password
 enable dns
 enable mssfixup    

Use your login name and password where indicated. The "set device" line tells ppp which physical device to use to talk to the outside world. You also have to tell the system to start PPPoE at boot time. That can be done with this little snippet of shell script:

echo -n "Trying to establish PPPoE DSL"; ppp -ddial pppoe
for i in 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0; do
    sleep 5
    echo -n.$i"
    if /usr/local/sbin/adsl-status>/dev/null; then

Where adsl-status is a little shell-script that tests to see whether the PPP link has come up properly:

IP=$(/sbin/ifconfig tun0 | awk '/netmask/{print $2}')
if [ -z "$IP" ]; then
   echo "ADSL link is down."
   exit 1
   echo "ADSL is up, IP address $IP"
   exit 0

Now the question is: where should we put the little loop that tries to get ppp going? The right place to put all these is in /etc/rc.local. However this has the drawback that the outside network hasn't been initialised while the rest of the system is coming up, which causes some scary-looking error messages from NAT to be printed at boot time. So I do something a little un-kosher: I put the ppp initialisation in /etc/netstart right at the end:

echo -n ' ADSL... '; ; ppp -ddial pppoe 
for i in 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0; do
    sleep 5
    echo -n.$i"
    if /usr/local/sbin/adsl-status>/dev/null; then

Now remember that each time the PPP link goes up or down, the IPF and NAT rules must be re-done. The files /etc/ppp/ppp.linkup and /etc/ppp/linkdown are scripts that get run by ppp. Here's /etc/ppp/ppp.linkup:

 ! sh -c "/sbin/route del default"
 ! sh -c "/sbin/route add default HISADDR -mtu 1492"
 ! sh -c "/sbin/pfctl -F all -R /etc/pf.conf -N /etc/nat.conf -e"
 ! sh -c "/usr/local/sbin/ntpd -p /var/run/"    

And this is /etc/ppp/linkdown:

 ! sh -c "/sbin/pfctl -F all -d"    

Configuring email

Sendmail should have been setup automatically since you edited /etc/rc.conf but I've occasionally had to make one change in /etc/mail/    

(If you don't own a domain, or plan on having it point to your DSL machine, you don't need sendmail.)

You should have a normal user account that you're going to use (never log in as root! Always use su or sudo). Administrative email should be forwarded to you; if your normal username is zippy edit /etc/mail/aliases and make sure you make the appropriate lines look like this:

# Well-known aliases -- these should be filled in!
root: zippy
manager: zippy
dumper: zippy      

One thing you should consider is being an email handler for friends. My DSL service goes down too often -- every few months. This is too unreliable for my tastes. What I do is collaborate with friends to accept and queue email for them, and they do the same for me. Example: for my domain the primary mail exchanger is, the OpenBSD firewall/gateway. A friend of mine has, and his email gateway is I set up a secondary mail exchanger in my domain records as If my DSL line goes down and someone out there wants to send email to me at, her machine will use instead and email will wait on that machine until my machine is back on the network. I want to perform the same service for my friend -- if is down, I want people to be able to send my machine the email destined for and (another friend's domain). This goes in the file /etc/mail/relay-domains on my gateway box:      

Now the machine will accept email for my friends' domains and as well as for itself and forward their messages on. If the machine it's trying to forward to is down, it will put them in the queue and keep re-trying for a while. (My friend at does similar things to his /etc/mail/relay-domains.)

Setting up DNS

You probably shouldn't be running the primary DNS server for your domain on your DSL box; DSL may not be reliable enough for that. Get someone else to do it for you for free, like

However, it is nice to have a local private DNS because lots of daemons (services that run in the background, like the web server) like to do reverse lookups of IP numbers, so we should have a DNS server for the private network. Also, this installation will give you a caching nameserver which should improve your browsing speed.

The files live in /var/named. Assuming your domain is called, edit named.boot and add these lines:

primary                 fake-domain.db
primary          fake-domain.rev
; your static IP number, reversed
primary      dsl.rev

; remember to add your ISP's nameservers here!

(Anything starting with a semicolon is a comment.) Here can be a real domain you have or a fake; and instead of use your static IP but reversed i.e. you would use that line if your IP number were And change the IP numbers on the forwarders line to the nameservers your ISP told you to use.

There are three files you need to create. The first is /var/named/namedb/fake-domain.db:

@       IN      SOA
                                14      ; Serial
                                10800   ; Refresh
                                3600    ; Retry
                                604800  ; Expire
                                86400 ) ; Minimum
        IN      NS
gateway IN      A
libelle IN      A
discus  IN      A
ventus  IN      A
wander  IN      A
brad    IN      A
jack    IN      A

; your static IP number
dsl     IN      A
www     IN      CNAME   dsl
mail    IN      CNAME   dsl      

In this network, there are six machines on the inside and those are their names and IP Number assignments. The OpenBSD gateway machine is named "gateway". Change these entries to names of the machines on your private network. You can give them any IP number that starts with 192.168.1. Of course if you have three machines on your network, there will only by three entries.)

This is the second file you need to create, /var/named/fake-domain.rev:

@       IN      SOA
                                14      ; Serial
                                10800   ; Refresh
                                3600    ; Retry
                                604800  ; Expire
                                86400 ) ; Minimum
        IN      NS
1       IN      PTR
2       IN      PTR
3       IN      PTR
4       IN      PTR
5       IN      PTR
12      IN      PTR
13      IN      PTR      

(Those trailing dots are important.) And here's the third, /var/named/namedb/dsl.rev:

@       IN      SOA
                                14      ; Serial
                                10800   ; Refresh
                                3600    ; Retry
                                604800  ; Expire
                                86400 ) ; Minimum
        IN      NS
        IN      PTR    


Yes, again more stupid special cases for PPPoE. For one thing, your IP address from the outside keeps changing so all the stuff about dsl.rev doesn't apply. However, more important: you don't know what your ISP's DNS servers are! And they could change which machines you're supposed to use each time you connect! What you have to do is: connect "by hand" one time, and see which DNS servers you got. After ppp.conf has been written, you can run ppp -ddial pppoe and pray. If all goes well, ifconfig tun0 should show you two lines:

$  /sbin/ifconfig tun0
tun0: flags=11<UP,POINTOPOINT> mtu 1492
        inet --> netmask 0xff000000      

That means everything worked. Now look at /etc/resolv.conf -- there should be one or more lines in there that say which nameservers should be used. Put these IP numbers in the forwarders line in /var/named/named.boot.

One other wrinkle: the /etc/resolv.conf that ppp makes for you doesn't know about your domain, or that you're running a nameserver on your machine. To get around these problems, I created another file /etc/resolv.conf-working:

lookup file bind

In /etc/ppp/ppp.linkup I tell it to overwrite the created resolv.conf with this one:

 ! sh -c "cp /etc/resolv.conf-working /etc/resolv.conf"      

(Add that to the end of the file that you've already created.) This allows all programs running on the machine to be able to use all the good things about a local caching nameserver -- things like being able to refer to internal hosts by short name etc.

Other machines on the internal network

Go to the other machines on your network (the ones inside your firewall) and set them up with the static IP numbers you assigned above, e.g. the machine wander gets an IP number of All the machines should use for the gateway and use for the DNS server. For more details on DNS, read the excellent O'Reilly book "DNS and BIND"; for more on setting up slightly more complex DNS servers than the one described here, go to the OpenBSD -- DNS site maintained by Samiuela LV Taufa.

Setting up DHCP

Above in the DNS setup all internal machines are assigned their own IP numbers. Running DHCP allows guest machines to hook up to the network without fuss. Depending on your comfort level with setting up your other machines, you might also prefer to use DHCP over assigning static IPs.This is what /etc/dhcpd.conf should look like:

#       $OpenBSD: dhcpd.conf,v 1.1 1998/08/19 04:25:45 form Exp $
# DHCP server options.
# See dhcpd.conf(5) and dhcpd(8) for more information.
# Network:    
# Domain name:          my.domain
# Name servers: and
# Default router:
# Addresses:   --
shared-network LOCAL-NET {
        option  domain-name "";
        option  domain-name-servers;
        subnet netmask {
                option routers;
This will allow up to 96 machines on your internal network, which should be more than sufficient. Create an empty temporary file for dhcpd to use:
# touch /var/db/dhcpd.leases    
If you make any changes to this file, run dhcpd fxp0 (or whatever your inside network is). (Or you can reboot the machine -- but that's the Windows way, in the Unix world we prefer to never reboot any machines.)

Install "ports"

"Ports" is a *BSD term for a tree of Makefiles for all the software out there that's not part of the standard install. I recommend this highly. It is on CD No. 3 of the OpenBSD 3.1 CD-ROM set as ports.tar.gz. Please read the Ports and Packages page on the OpenBSD web site. You install it by typing (as root)

# mount /dev/cd0a /mnt
# cd /usr
# tar xzf /mnt/ports.tar.gz    

Once you've done this, if you want to install a package, you cd to the appropriate directory and simply type make all install -- it will ftp the source from the appopriate site, handle all dependencies, apply any required patches, configure, build and install the tool.

How do you find the appropriate directory to go to? You can guess at where it might be (look around in /usr/ports to get an idea for the layout etc.). But remember: locate(1) is your friend.

If you have the disk space (about 500 MB), I strongly recommend that you install the source code to the system also. (The source is also on CD No. 3.)

# mount /dev/cd0a /mnt
# cd /usr/src
# tar xzf /mnt/src.tar.gz    

Getting time from the Internet

Set up NTP so that your machine will always have accurate time. Pick two servers from the public NTP server list and make sure /etc/ntp.conf looks like this:

server ntp.server.first
server ntp.server.second    

Since xntpd is not part of the standard install, you have to compile xntpd from source.

# cd /usr/ports/sysutils/xntpd
# make all install    

The tools will be installed into /usr/local/sbin/ntpd.

Run ntpdate -b server where you pick a server from the list -- this will perform a coarse adjustment of the system clock. The next time the machine reboots, it will sync your clock and record how much your clock drifts.

Setting up other hosts with NTP

On Unix hosts, use the appropriate NTP client; on Linux, it's xntpd. Set them up to use as the NTP server. On Windows, use AboutTime -- a free NTP client. In its configuration make sure it uses only SNTP as the protocol, with as the server. Put AboutTime in the Startup folder so it's started automatically.

For more details, go to Robert Mooney's OpenBSD NTP site.


Tips and Stuff

I have a useful shell script called pkg_install that's a front-end to pkg_add -- here's an example of it being used:
# pkg_install tex
These files match:
# pkg_install -n 4 texi
+ pkg_add -v
Trying to fetch
Extracting from FTP connection into /var/tmp/instmp.BVMJM29414
>>> ftp -o --

It has a list of all the pre-compiled packages that are available. You type in a string and it installs the package. If more than one name matches, it shows you their names. (It uses egrep(1) so you can use regular expressions.) Save it to /usr/local/bin. It handles dependencies by recursively installing them also.

New in this version is in -n flag. The script has a list of mirrors, and this option picks one of the mirrors. (Currently in progress: it needs bash, and it needs some error checking but it works.) Don't forget to edit the file -- read and choosea list of mirrors closest to you.

Setting up a CVS server

(This section is probably not of interest to most people; you only need this if you want to set up a cvs server so you can put files you're working on under source control. So it's a little terse too.)

The changes I made: added a user and group named cvs. All users of CVS should be in the cvs group. Create a directory for the repository: I put it in /var/cvsroot, you might put it in /home or wherever. This directory should be group writable (group cvs). Add a line to /etc/services:

      cvspserver	2401/tcp		# CVS pserver      
Add this line to /etc/inetd.conf:
      cvspserver	stream	tcp	nowait	root	/usr/bin/cvs cvs -f --allow-root=/var/cvsroot -T /var/tmp pserver      

The server uses /var/tmp as its temp directory instead of /tmp since my root partitions are small, but I always make /var large. Now run cvs init in the cvs repository and restart inetd. Voila! Import your directory of files from a client machine, using a pserver CVSROOT and cvs import.

When importing a large set of files, you might want to put a .cvswrappers file in the directory you're importing so CVS won't try to put RCS ID strings inside your JPEG files etc. The syntax is:

      *.jpg -k 'b'
      *.png -k 'b'
      *.tgz -k 'b'      
Coming soon: using ssh for CVS_RSH.

Setting up X11

You did select the packages xbase, xshare, xfont, and xserv when you installed OpenBSD, I hope? If not, never fear; you can install them directly off the CD:

# mount /dev/cd0a /mnt
# cd /
# tar xzvpf /mnt/3.1/i386/xbase31.tgz
# tar xzvpf /mnt/3.1/i386/xserv31.tgz
# tar xzvpf /mnt/3.1/i386/xshare31.tgz
# tar xzvpf /mnt/3.1/i386/xfont31.tgz      
etc. The X11 package for ix86 systems is called XFree86; visit their website for more information. Now run xf86cfg. (If the command is not found, you probably don't have /usr/X11R6/bin in your PATH environment variable.) Of course this is not something you can do over a network login; you have to be sitting at the machine, with a monitor, keyboard and mouse actually plugged in. You should have your video card and monitor specs available. Follow the instructions to setup XFree86. More information is on the Configuring XFree86 page on the Xfree86 site.

Installing a Desktop

Many people also install a desktop suite such as KDE or Gnome. I prefer KDE of the two. There is nothing special about KDE (or Gnome); it's just a set of packages to be installed. There are two versions of KDE available, KDE 2.2 and KDE 3.0. Decide which one you want to run, and install those packages. (KDE2 and KDE3 cannot co-exist on the same system.)

These are the KDE2 packages:

$ pkg_info -a | egrep kde
kdelibs-2.2.2      X11 toolkit, libraries
kdeartwork-2.2.2   X11 toolkit, additional artwork
kdegraphics-2.2.2  X11 toolkit, graphics applications
kdelibs-doc-2.2.2  X11 toolkit, libraries documentation
kdebase-2.2.2      X11 toolkit, basic applications
kdenetwork-2.2.2   X11 toolkit, network applications
kdetoys-2.2.2      some useless kde applications      
And for KDE3, the corresponding packages are:
There are lots of I18N packages also, kde-i18n-*-3.0.tgz.

Display managers xdm and kdm

You may want to run a display manager like xdm or kdm. (A display manager is the program that gives you a graphical login display instead of a plain text message.) The config file for kdm is /usr/local/share/config/kdm/kdmrc; the xdm config file lives in /etc/X11/xdm/xdm-config. Edit /etc/rc.conf and set xdm_flags to an empty string (in quotes) to make xdm run on startup. (If you installed KDE, it will be kdm that's started.) If you installed KDE3, add it to the list of available logins in kdmrc: in the [X-*-Greeter] section, look for the SessionTypes line and add "KDE3" to the list.

Setting up XDMCP

If you have an X-Terminal (like the Sun Ray, or the ones NCD used to make) or run eXceed on Windows platforms, you may want to allow X11 logins to your OpenBSD machine from eXceed or the X-Terminal. The protocol that allows this is called XDMCP; to enable it: if using xdm, edit /etc/X11/xdm/Xaccess and remove the '#' from the first column of this line:

#*                                      #any host can get a login window
Note: we don't allow any X11 or XDMCP messages to go across our firewall. Only hosts inside the firewall can get a login screen.

Also edit xdm-config and comment out this line by putting a '!' character in the first column:

DisplayManager.requestPort:     0      
If using kdm, edit /usr/local/share/config/kdm/kdmrc and look for the [Xdmcp] section. Uncomment lines so it looks like this:
# Whether KDM should listen to XDMCP requests. Default is true.
# The UDP port KDM should listen on for XDMCP requests. Don't change the 177.
(followed by other stuff.)


People like to do things like rip CDs to Ogg Vorbis or MP3 and listen to those files. I use grip as a front-end to rip music to Ogg Vorbis files, and xmms (package name xmms-vorbis) to listen to them. I use Gnu LilyPond and TeX/LaTeX (package teTeX_texmf) to typeset documents and music. The LaTeX files can be converted to HTML with latex2html. You can run Linux programs if you install the redhat_base, redhat_motif, and rpm packages. (The Linux version of Opera, the web browser, runs fine.)



(Coming soon.)


My thanks to Joe Sprankle, Alfred Bruell, David Hodnett, and Francisco for feedback and suggestions. Thanks also to the San Francisco OpenBSD Users Group for giving me a forum to publicise this document.

Thanks of course to the OpenBSD developers, for a fine OS!


Copyright © 2001-2002 Shamim Mohamed
Last modified: Sat Jul 23 13:08:04 PDT 2005
$Date: 2005/07/23 20:37:44 $