Home OpenBSD OpenBSD: Install DHCP Server

OpenBSD: Install DHCP Server

by Kliment Andreev
0 comment
Reading Time: 2 minutes

One of my computers running OpenBSD 3.7 that was a DNS, DHCP, NTP and proxy server recently crashed (HDD failure). I have another DNS server running on a different machine and I didn’t much care about NTP and proxy. But, DHCP server was playing an important role. I lost connection on all of my computers because the wireless router was using pass-through DHCP from the OpenBSD machine. I configured the laptops to use static IPs for a day until I bought a new HDD and reinstalled OpenBSD 4.2
First, I edited /etc/rc.conf and replaced dhcpd_flags=”NO” with dhcpd_flags=””. Then, I used ifconfig to check the name of the ethernet adapter. In my case it is xl0.

NOTE: Highlighted numbers are what you type. The rest is the response from the computer.

ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33208
        groups: lo
        inet 127.0.0.1 netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
xl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        lladdr 00:08:74:22:25:3c
        groups: egress
        media: Ethernet autoselect (100baseTX full-duplex)
        status: active
        inet 192.168.1.7 netmask 0xffffff00 broadcast 192.168.1.255
        inet6 fe80::208:74ff:fe22:253c%xl0 prefixlen 64 scopeid 0x1
enc0: flags=0<> mtu 1536

I edited /etc/dhcpd.interfaces and added xl0 at the very end, so it looked like this.

# $OpenBSD: dhcpd.interfaces,v 1.1 1998/08/19 04:25:45 form Exp $
#
# List of network interfaces served by dhcpd(8).
#
# ep0
# ed0 le0
# de1
xl0

xl0 is the listener interface. You can have multiple interfaces. Since I have only one network card, xl0 is the only option.

DHCP server stores its leases in a file /var/db/dhcpd.leases. This file is not there, so we have to create it first.

touch /var/db/dhcpd.leases

The last part involves you to modify the configuration file, where you can specify the scope and other parameters of the DHCP server. I made a copy of the original file, in case something goes wrong.

cp /etc/dhcpd.conf /etc/dhcpd.conf.orig

Then I edited /etc/dhcpd.conf to suit my needs. This is the simplest working configuration.

shared-network LOCAL-NET {
option domain-name "your-domain-here";
option domain-name-servers 192.168.1.2, 192.168.1.8;
        subnet 192.168.1.0 netmask 255.255.255.0 {
        option routers 192.168.1.1;
        range 192.168.1.50 192.168.1.254;
        }
}
  • option domain-name “your-domain-here” means I have used your-domain-here as DNS name. So, your DHCP client host will have this value as suffix.
  • Next parameter, option domain-name-servers 192.168.1.2, 192.168.1.8; is the address or addresses of your DNS servers that will be assigned to the computer that will lease an IP.
  • The line after that tells the DHCP server what’s the network class and subnet. My network is 192.168.1.0/24, /24 is 255.255.255.0, /16 is 255.255.0.0 etc….
  • The gateway assigned (option routers) in my case is 192.168.1.1.
  • And I also choose the scope of my DHCP to be from 192.168.1.50 to 192.168.1.254.

Now, I can start the server by using:

dhcpd

If everything is OK, you’ll get the prompt back. Let’s verify that DHCP server is working.

ps -waux | grep dhcpd
_dhcp 8667 0.0 0.1 672 768 ?? Is 3:54AM 0:00.00 dhcpd</pre>

I went back to my Windows laptop and verified that everything is OK.

C:\Documents and Settings\klimenta\ipconfig /all
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix .  : your-domain-here
Description . . . . . . . . . . . : Intel(R) PRO/100 VM Network Connection
Physical Address. . . . . . . . . : 00-08-02-E4-34-0D
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.1.50
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
DHCP Server . . . . . . . . . . . : 192.168.1.7
DNS Servers . . . . . . . . . . . : 192.168.1.2
                                    192.168.1.8
Lease Obtained. . . . . . . . . . : Thursday, December 01, 2011 8:36:04 AM
Lease Expires . . . . . . . . . . : Thursday, December 01, 2011 8:36:04 PM</pre>

And I can verify on the DHCP server that it leased an IP.

tail /var/db/dhcpd.leases
# All times in this file are in UTC (GMT), not your local timezone.
# The format of this file is documented in the dhcpd.leases(5) manual page.
lease 192.168.1.50 {
        starts 6 2011/12/01 08:36:04;
        ends 6 2011/12/01 20:36:04;
        hardware ethernet 00:08:02:e4:34:0d;
        uid 01:00:08:02:e4:34:0d;
        client-hostname "bigbeat";
}
0 comment
0

Related Articles

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More