A Python interface to manage IP addresses in phpIPAM through REST API, with integration to ISC-DHCP
phpIPAM is an open-source web IP address management application. Its goal is to provide light and simple IP address management application.
Site: phpIPAM homepage
./dhcp2phpipam.py add ClientIP ClientDHCID ClientName RouterIP
Where:
- ClientIP : Host IP address
- ClientDHCID : Host MAC Address
- ClientName : Hostname
- RouterIP :
RouterIP
is required to determine the subnet in which theClientIP
should be added.ClientIP
is added on the same subnet whereRouterIP
is located. It can be the IP of the gateway of the subnet or some other reference IP in that subnet
./dhcp2phpipam.py update ClientIP ClientDHCID ClientName
/dhcp2phpipam.py del ClientIP
- Install packages
pip install requests
or
sudo apt update && sudo apt install python-requests libssl-dev
-
Create directory
/etc/dhcp/dhcpd-hooks.d/
-
Download and copy
dhcp2phpipam.py
in/etc/dhcp/dhcpd-hooks.d/
-
Edit
dhcp2phpipam.py
and set phpIPAM url, api name and api token
phpipam_url = 'https://phpipam.local'
api_id = 'your_api_name'
api_token = 'your_api_key'
- Set execute permission on
dhcp2phpipam.py
chmod +x `/etc/dhcp/dhcpd-hooks.d/dhcp2phpipam.py`
-
Download and copy
usr.sbin.dhcpd
in:/etc/apparmor.d/local/
and restart apparmor service -
Create directory
/etc/dhcp/dhcpd.conf.d/
-
Download and copy
dhcpd-event.conf
in/etc/dhcp/dhcpd.conf.d/
-
Edit
/etc/dhcp/dhcpd.conf
and includedhcpd-event.conf
with trigers update
include "/etc/dhcp/dhcpd.conf.d/dhcpd-event.conf";
-
Restart DHCP Server
-
Enjoy