Blog

Automating ISC DHCP (3 comment)

Added by Ohad Levy over 2 years ago

using omapi (omshell):

Add a server

server 192.168.2.99 (my remote DHCP server)
connect
new host
set name = "nx" 
set hardware-address = 54:52:00:13:21:a4
set hardware-type = 1
set ip-address = 192.168.2.105
set statements = "next-server = c0:a8:02:7d; filename = \"pxelinux.0\";option host-name \"nx.lan\";" 
create

next-server has to be in hex, a simple method that converts IP's to hex:

def self.ip2hex ip
  ip.split(".").map{|i| "%02x" % i }.join(":")
end

Remove a server

server 192.168.2.99
connect
new host
set ip-address =  192.168.2.106
open
remove

More complex setup with gpxelinux.0

server 192.168.2.99
connect
new host
set name = "u904" 
set hardware-address = 54:52:00:4b:a5:38
set hardware-type = 1
set ip-address = 192.168.2.106
set statements = "next-server = c0:a8:02:7d; filename = \"gpxelinux.0\"; option host-name \"u904.lan\"; vendor-option-space = \"pxelinux\"; option pxelinux.magic = f1:00:74:7e; option pxelinux.pathprefix = \"http://foreman/\"; option pxelinux.configfile = \"unattended/pxe\";" 

create