DHCP Assigned ‘Static’ Addresses

I have a couple of laptops. When I’m using them at home I would prefer they have static IP addresses like my desktops. This allows me to remote into them via VNC by name. Having the IP address change on me is quite inconvenient.

BUT when I’m on the road, I need to be using DHCP so I get an IP address correctly assigned. I use to go back and forth between static and DHCP addresses when I rarely left the house with a laptop, but these days I seem to regularly need DHCP so that is what I use even though I long for the static days.

It occurred to me today that there should be no reason why I couldn’t have DHCP assign my laptops addresses from the static address area. After all I used to have Windows-based DHCP servers at the office doing that very thing. And anything Windows can do Linux can do better….. (can’t believe I am singing the praises of linux, but that is the world I am forced to live in now).

Did some quick research and sure enough, DHCP on my linux server has no trouble assigning a specific IP address to a specific MAC address. In your /etc/dhcp/dhcpd.conf file you add an entry like this:

host lapdude {
  hardware ethernet 80:1F:02:B5:B3:80;
  fixed-address lapdude.hallock.net;

The particularly cool thing here is that I’m not assigning an IP address directly, but looking up the dns entry lapdude.hallock.net and assigning that IP address.

Needless to say, to do this, you must also create a DNS entry, but I’m going to do that anyway – kind of the whole point.

And now, while at home, I can access my laptop via the DNS entry lapdude.hallock.net and when I leave the house, DHCP will correctly assign an IP address based on that server’s rules.

I guess I should also state the obvious. If you are using a DHCP server on something like your router (which most home users would do), this isn’t going to work. You have to have a linux server running to provide DHCP (and probably DNS).

To do it on the VERY cheap, there is no reason why you couldn’t set up a Raspberry Pi to provide DHCP and DNS services. Some day, I may very well migrate my network services server from a very old P4 to an RPI just to save the continuous 60W being drained by that server.

Note to self:

To restart dhcp server on RPI:

service isc-dhcp-server restart
This entry was posted in c-pcos and tagged . Bookmark the permalink.

One Response to DHCP Assigned ‘Static’ Addresses

  1. Sean Straw says:

    This is alternately referred to as a “DHCP Reservation” or “Static Lease”. I’ve used them forever and a day on my routed network for my home office. An added benefit – esp when you use the DNS lookup – is that if you get a new network assignment, the changes are centralized, rather than having to go to each workstation and device to reconfigure them. Hoa about virtual machines and dormant stuff – nothing like firing up something you haven’t used in a while and having it have an incorrect static assignment – no problem though if you’re using DHCP reservations.

    I still typically assign servers with hard-coded IP addresses (often because they’ll have multiple IPs – sadly still a necessity when dealing with SSL certificates), but handing out reserved leases to workstations, mobile devices and networked printers simplifies things greatly.

    A good open source router, such as OpenWRT, will support DHCP reservations – most of the mainstream stuff does a poor job of real network management though. I still run DHCP and DNS (and a host of other services) on full-on servers, but any of my OpenWRT routers could accomplish the DHCP task.


    I haven’t tried, so I don’t know if the OpenWRT DHCP implemenation would support DNS lookups for the IP assignments.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s