Dhcpd.Conf Static Ip Assignments

Re: Static IP address templates for dhcpcd.conf

Fri Apr 08, 2016 8:21 pm

Great stuff and very timely for my wireless Access Point project.
Thanks rurwin!

I want to be able to use this AP in several locations, without knowing beforehand what the router setup is.

[update]
I really like the possibilies this offers, now that it has been explained to me in more detail.
However, for the sake of non-expert users (same here) following this, I made the above statement about my AP but need to retrakt that.
After some tinkering and even more thinking about the ramifications, I'm not going to use static addresses on the Ethernet side (eth0) of my AP. It's OK to do all that on my own SOHO network, and I do, but the risks to screw-up a foreign network (apartment complex, hotel,...) by assigning a static IP address are simply too great.

I'll get the IP address assigned through the DHCP server from the router and lacking a console, I'll use the clever trick to send the IP address as audio at boot time. If I really need it.
viewtopic.php?f=91&t=11857&p=949015

To get access to the Pi on my W10 box, I already use PuTTY, but will now only use the pi_hostname.local addressing instead of the static IP address. If you do too, you need to ask raspi-config (Advanced Options) to enable the SSH part and I suggest you change the RPi hostname.

Last edited by paulv on Sat Apr 09, 2016 11:20 am, edited 1 time in total.

Emulate a fixed IP address using MAC address with DHCP

In many networks with DHCP it is desirable to have predictable IP addresses and hostnames for DHCP clients. This can be accomplished by having the DHCP server hand out IP addresses and set hostnames according to the client's MAC or hardware address. The method will vary according to the DHCP server in use, but for many home routers with DHCP and DNS built in, it can be accomplished through the web interface to the router.

Home router with DHCP and DNS

The router address can be found by looking at the gateway in the route on the client.

# /sbin/route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0

In this example, the router is at 192.168.1.1 so the web interface would generally accessed by http://192.168.1.1/ . There is generally a link in the user interface for the router to display current connections, and this will typically include the current hostname, IP address, and MAC address of each client. With this information one can then navigate to a page allowing the reservation and assignment of IP addresses by MAC address. Consult your router's documentation or on-line help for details.

Linux DHCP server

The same effect can be accomplished by modifying the DHCP server configuration on a Linux host. For the CentOS dhcp package information similar to that obtained from the router in the home example can be obtained from the dhcpd.leases and a section can then be created in dhcpd.conf (for this CentOS package /var/lib/dhcpd/dhcpd.leases and /etc/dhcpd.conf respectively) to define each host. See the dhcpd and dhcpd.conf man pages for details. You may also want to consider using the group and pool directives. Similar techniques can be used for other software providing a DHCP server.

dhcpd.leases

lease 192.168.0.249 { starts 3 2010/11/10 21:46:35; ends 4 2010/11/11 03:46:35; tstp 4 2010/11/11 03:46:35; binding state free; hardware ethernet 00:01:08:00:ad:33; }

dhcpd.conf

host myhost { hardware ethernet 00:01:08:00:ad:33; fixed-address 192.168.0.249; option host-name "myhost"; }

This page created and maintained by PhilSchaffner. Other Wiki contributors are invited to make corrections, additions, or modifications.

TipsAndTricks/EmulateFixedAddressByDHCP (last edited 2011-04-30 11:43:08 by PhilSchaffner)

0 thoughts on “Dhcpd.Conf Static Ip Assignments

Leave a Reply

Your email address will not be published. Required fields are marked *