Previous Section  < Day Day Up >  Next Section

Recipe 24.5. Adding Static Hosts to dhcp

24.5.1 Problem

You have some servers or other machines to which you want to assign static IP addresses. You can use /etc/hosts, but it's a bit of bother to edit /etc/hosts on each of the zillion PCs you're responsible for. Can you do it in dhcpd.conf?

24.5.2 Solution

Yes, you surely can. You'll need the MAC address of your network card, which you can find with ifconfig:

$ /sbin/ifconfig

eth0      Link encap:Ethernet  HWaddr 00:03:6D:00:83:CF

          inet addr:192.168.1.5  Bcast:192.168.1.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

.....

You want the HWaddr value.

On Windows 95/98/ME, open a DOS prompt and run winipcfg. On NT/2000/XP, run ipconfig.

Make an entry in dhcpd.conf like this:

host mail1 {

   hardware ethernet 00:03:6D:00:83:CF;

   fixed-address 192.168.1.100;

   }

Note that multiple-line directives must be enclosed in curly braces.

Name servers have their own directive in dhcpd.conf, so they don't need MAC addresses:

option domain-name-servers 192.168.1.10, 192.168.1.11

That's all there is to it. Use this for any machine you wish to have a static IP address.

24.5.3 Discussion

You can still use /etc/hosts for important servers, as a fallback for local users. Remember, with /etc/hosts the network does not break when a single server goes down.

Every network card ever made has a unique 48-bit Media Access Control (MAC address). The Institute of Electrical and Electronics Engineers, Inc. (IEEE) assigns the first 24 bits, then the manufacturer assigns the remaining 24 bits.

24.5.4 See Also

  • dhcp-options(5), dhcpd.conf(5), dhcpd(8)

    Previous Section  < Day Day Up >  Next Section