dhcpctl and omapi
Chow Chi Ho (FP&HO)
chchow at cabletv.com.hk
Tue Mar 27 07:56:21 UTC 2007
it seems that the omshell can update the dhcp.lease interactively.
but , how can we update the dhcpd.conf in the same way as omshell ?
-----Original Message-----
From: dhcp-users-bounce at isc.org [mailto:dhcp-users-bounce at isc.org]On Behalf Of jgomez at infoweapons.com
Sent: Monday, March 26, 2007 11:54 AM
To: dhcp-users at isc.org
Subject: dhcpctl and omapi
>Anyone knows how to use dhcpctl or omapi to add or remove the hardware
>list at dhcpd.conf ?
The OMAPI Command Shell, omshell, provides an interactive way to connect
to, query, and possibly change, the ISC DHCP Server's state via OMAPI, the
Object Management API. By using OMAPI and omshell, you do not have to
stop, make changes, and then restart the DHCP server, but can make the
changes while the server is running. Omshell provides a way of accessing
OMAPI.
Omshell deals with local and remote objects. Local objects are ones
created in omshell with the new command. Remote objects are ones on the
server: leases, hosts, and groups that the DHCP server knows about. Local
and remote objects are associated together to enable viewing and
modification of object attributes. Also, new remote objects can be created
to match local objects.
omshell is started from the command line. Once omshell is started,
there are several commands that can be issued:
server address
where address is the IP address of the DHCP server to connect
to.
If this is not specified, the default server is 127.0.0.1
(local host).
port number
where number is the port that OMAPI listens on. By default,
this is 7911.
key name secret
This specifies the TSIG key to use to authenticate the OMAPI
transactions. name is the name of a key defined in dhcpd.conf with
the omapi-key statement. The secret is the secret generated from
dnssec-keygen or another key generation program.
connect
This starts the OMAPI connection to the server as specified by the server
statement.
Note: The four commands mentioned above namely, server address, port
number, key name secret, and connect is use in opening a connection
Creating local objects
Any object defined in OMAPI can be created, queried, and/or modified. The
object types available to OMAPI are defined in dhcpd(8) and dhclient(8).
When using omshell, objects are first defined locally, manipulated as
desired, and then associated with an object on the server. Only one object
can be manipulated at a time. To create a local object, use
new object-type
object-type is one of group, host, or lease.
At this point, you now have an object that you can set properties
on.
For example, if a new lease object was created with new lease, any
of a
Lease's attributes can be set as follows:
set attribute-name = value
Attribute names are defined in dhcpd(8) and dhclient(8).
Values
should be quoted if they are strings. So, to set a
lease's IP
address, you would do the following:
set ip-address = 192.168.4.50
Associating Local and Remote Objects
The information about this lease can be queried from the server by
open
Now, the local lease object being created and set the IP address for is
associated with the corresponding lease object on the DHCP server. All of
the lease attributes from the DHCP server are now also the attributes on
the local object, and will be shown in omshell.
Viewing a Remote Object
To query a lease of address 128.1.2.164, and find out its attributes,
after connecting to the server, take the following steps:
new lease
This creates a new local lease object.
set ip-address = 128.1.2.164
This sets the local object's IP address to be 128.1.2.164
open
Now, if a lease with that IP address exists, you will see all
the
information the DHCP server has about that particular lease. Any
data
that isn't readily printable text will show up in colon-separated
hexa-
decimal values. In this example, output back from the server for the
entire transaction might look like this:
> new "lease"
obj: lease
> set ip-address = 128.1.2.164
obj: lease
ip-address = c0:a8:04:32
> open
obj: lease
ip-address = c0:a8:04:32
state = 00:00:00:02
dhcp-client-identifier = 01:00:10:a4:b2:36:2c
client-hostname = "client1"
As you can see here, the IP address is represented in
hexadecimal, as
are the starting and ending times of the lease.
Creating a Remote Object
Attributes of remote objects are updated by using the set command
as
before, and then issuing an update command. The set command sets
the
attributes on the current local object, and the update command
pushes
those changes out to the server.
Continuing with the previous example, if a set client-hostname = "
Jonna" was issued, followed by an update command, the output would
look about like this:
> set client-hostname ="Jonna"
obj: lease
ip-address = c0:a8:04:32
state = 00:00:00:02
dhcp-client-identifier = a4:b2:36:2c:01:00:10
client-hostname = "Jonna"
subnet = 00:00:00:06
pool = 00:00:00:07
hardware-address = 00:10:a4:b2:36:2c
hardware-type = 00:00:00:01
ends = dc:d9:0d:3b
starts = 5c:9f:04:3b
tstp = 00:00:00:00
tsfp = 00:00:00:00
cltt = 00:00:00:00
> update
obj: lease
ip-address = c0:a8:04:32
state = 00:00:00:02
dhcp-client-identifier = a4:b2:36:2c:01:00:10
client-hostname = "Jonna"
subnet = 00:00:00:06
pool = 00:00:00:07
hardware-address = 00:10:a4:b2:36:2c
hardware-type = 00:00:00:01
ends = dc:d9:0d:3b
starts = 5c:9f:04:3b
tstp = 00:00:00:00
tsfp = 00:00:00:00
cltt = 00:00:00:00
New Remote Objects
New remote objects are created much in the same way that
existing
server objects are modified. Create a local object using new, set
the
attributes as you'd wish them to be, and then create the remote
object
with the same properties by using create.
Now a new object exists on the DHCP server which matches the
properties
that you gave your local object. Objects created via OMAPI are
saved
into the dhcpd.leases file.
name = "client"
hardware-address = 00:80:c7:84:b1:94
> set hardware-type = 1
obj: host
name = "client"
hardware-address = 00:80:c7:84:b1:94
hardware-type = 1
> set ip-address = 128.1.2.20
obj: host
name = "client"
hardware-address = 00:80:c7:84:b1:94
hardware-type = 1
ip-address = c0:a8:04:28
> create
obj: host
name = "client"
hardware-address = 00:80:c7:84:b1:94
hardware-type = 00:00:00:01
ip-address = c0:a8:04:28
>
Your dhcpd.leases file would then have an entry like this in it:
host client {
dynamic;
hardware ethernet 00:80:c7:84:b1:94;
fixed-address 128.1.2.20;
}
The dynamic; line is to denote that this host entry did not come
from
dhcpd.conf, but was created dynamically via OMAPI.
Resetting Attributes
If you want to remove an attribute from an object, you can do this
with
the unset command. Once you have unset an attribute, you must use
the
update command to update the remote object. So, if the host
"some-
host" from the previous example will not have a static IP address
any-
more, the commands in omshell would look like this:
obj: host
name = "client"
hardware-address = 00:80:c7:84:b1:94
hardware-type = 00:00:00:01
ip-address = c0:a8:04:28
> unset ip-address
obj: host
name = "client"
hardware-address = 00:80:c7:84:b1:94
hardware-type = 00:00:00:01
ip-address = <null>
>
Refreshing Objects
A local object may be refreshed with the current remote object
proper-
ties using the refresh command. This is useful for object that change
periodically, like leases, to see if they have been updated.
This
name = "client"
hardware-address = 00:80:c7:84:b1:94
hardware-type = 00:00:00:01
ip-address = c0:a8:04:28
> remove
obj: <null>
>
--------
This email and/or attachments are confidential and may also be
legally privileged. If you are not the intended recipient, you are
hereby notified, that any review, dissemination, distribution or
copying of this email and/or attachments is strictly prohibited.
Please notify security at infoweapons.com immediately by email and
delete this message and all its attachments. Thank you.
More information about the dhcp-users
mailing list