Generating dhcpd.conf using ARP
If you are leaving in a large network of workstation with static IP assignment, you might be interesting in conversion to dynamic IP assignment for administrative reasons. In the view of administrators, they are happy to control, change settings on centralized server instead of walking around to change settings one by one especially if you are in very large industrial site.
However, writing dhcpd.conf is not as easy as a single click for large unmanaged network. Why? People or applications might strictly rely on IP address or even netbios name. We have to smoothly migrate to DHCP based on current state of network configuration. That means we should assign current IP address of each machine as before and also assign current netbios name to support legacy people and appliations.
Fortunately, there are some trick to accomplish this task with less effort. The magic is ARP. ARP stands for Address Resolution Protocol. We can use ARP to obtain list of IP address and its associlate MAC address as follow.
[root@mail ~]# arp -n Address HWtype HWaddress Flags Mask Iface 192.168.10.42 ether 00:11:85:19:F0:D4 C eth0 192.168.10.1 ether 00:13:F7:08:20:D2 C eth0
So we have both IP address and its MAC address right now. We still need the last piece of information that is its name. In this case, all machines are in private network without internal DNS so we have to prepare ip2nb.sh first. Then lastly prepare a script namely arptodhcpd.sh as below.
#!/bin/sh awk " /..:..:..:..:..:../ { name=""; tmp="/tmp/ip2nb.tmp"; system(sprintf("./ip2nb.sh %s > %s",$1,tmp)); getline name < tmp close(tmp); if (name == "") { split($1,ip,"."); name=sprintf("host%s",ip[4]); } printf("\thost %s {\n",name); printf("\t\thardware ethernet %s;\n",$3); printf("\t\tfixed-address %s;\n\t}\n",$1); }" rm -f /tmp/ip2nb.tmp
For example, above arp -n will give following dhcpd.conf.
[root@mail ip]# arp -n | ./arptodhcpd.sh host server2000 { hardware ethernet 00:11:85:19:F0:D4; fixed-address 192.168.10.42; } host host1 { hardware ethernet 00:13:F7:08:20:D2; fixed-address 192.168.10.1; }
- sugree's blog
- 874 reads
Post new comment