Managing DHCP static mappings in pfSense can be a tedious task, especially when dealing with multiple VLANs or bulk operations. While the pfSense web interface is excellent for day-to-day administration, it can become cumbersome when you need to handle numerous DHCP static assignments or migrate them between interfaces. That’s where this new collection of command-line tools comes in to save the day.

I’m excited to share a set of PHP scripts I’ve developed specifically for pfSense 2.7.2 CE that makes managing DHCP static mappings a breeze. These tools are designed to handle everything from bulk imports to complete system cleanups, all from the command line.

GitHub: pfSense DHCP Static Mapping Scripts

The Tool Suite

The project includes four powerful scripts:

  1. add_dhcp_static.php: Import static DHCP assignments from CSV files
  2. export_dhcp_static.php: Back up your existing DHCP static mappings to CSV
  3. remove_dhcp_static.php: Selectively remove specific DHCP assignments
  4. remove_all_dhcp_static.php: Clean slate - remove all static DHCP assignments

Key Features

What makes these scripts particularly useful:

  • Cross-VLAN Support: Unlike the web GUI, these tools can easily move static assignments between different VLAN interfaces
  • Bulk Operations: Import multiple static mappings at once using a simple CSV format
  • Flexible Removal: Remove entries by IP, MAC address, or hostname
  • Reservation Pool Override: Create static assignments within the reservation pool (something the web GUI doesn’t allow)
  • Conflict Prevention: Built-in checks for duplicate IPs, MACs, and hostnames
  • Easy Backup: Quick CSV export of all your static DHCP assignments

Real-World Use Cases

These tools really shine in scenarios like:

  • Migrating a subset of devices to a new VLAN
  • Bulk importing static assignments from another system
  • Creating quick backups before making major DHCP changes
  • Cleaning up old or unused DHCP assignments
  • Automating DHCP management tasks through scripts

Getting Started

The tools are straightforward to use. Here’s a quick example of backing up your current DHCP assignments and then adding new ones:

# Export current assignments
php /root/export_dhcp_static.php > dhcp_backup.csv

# Import new assignments
php /root/add_dhcp_static.php new_reservations.csv

The CSV format is simple and human-readable:

mac,ipaddr,hostname,description
00:11:22:33:44:55,192.168.1.100,device1,Test Device

Important Considerations

While these tools are powerful, there are a few things to keep in mind:

  • Always backup your pfSense configuration before making bulk changes
  • The scripts must be run directly on the pfSense firewall with root access
  • When using the reservation pool override feature, those entries won’t be editable in the web GUI
  • You may need to restart the DHCP service after making changes

Conclusion

If you’re managing a pfSense firewall with numerous DHCP static mappings, these tools can significantly streamline your workflow. They’re especially valuable for network administrators dealing with frequent DHCP changes or managing multiple VLANs.

Check out the project on GitHub: pfSense DHCP Static Mapping Scripts

Feel free to contribute, report issues, or suggest improvements. This is an open-source project aimed at making pfSense DHCP management more efficient for everyone.