Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    "Register DHCP leases in DNS forwarder" needs dnsmasq restarted after reboot

    Scheduled Pinned Locked Moved DHCP and DNS
    3 Posts 2 Posters 443 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      rosenstand
      last edited by

      Hi

      After each reboot of the router, I need to restart dnsmasq in order to add DHCP leases to /etc/hosts.

      There seem to be 2 bugs,

      1. Code is not run in right sequence at boot time
      2. Code is run 3 times (or 3 threads?) at least when "restarting"

      After boot:

      [2.4.4-RELEASE][root@pfSense.lan]/root: cat /etc/hosts
      127.0.0.1	localhost localhost.lan
      ::1	localhost localhost.lan
      192.168.1.1	pfSense.lan pfSense
      

      After "restarting" dnsmasq (Services -> DNS Forwarder -> Save -> Apply Changes), each host is then written (3 times!?) to /etc/hosts.

      [2.4.4-RELEASE][root@pfSense.lan]/root: cat /etc/hosts
      127.0.0.1	localhost localhost.lan
      ::1	localhost localhost.lan
      192.168.1.1	pfSense.lan pfSense
      
      # dhcpleases automatically entered
      192.168.1.172	Apple-TV-4K.lan Apple-TV-4K		# dynamic entry from dhcpd.leases
      192.168.1.102	Marks-iPhone-X.lan Marks-iPhone-X		# dynamic entry from dhcpd.leases
      192.168.1.106	Marks-iPad-Pro.lan Marks-iPad-Pro		# dynamic entry from dhcpd.leases
      192.168.1.183	MarksiPne6SPlus.lan MarksiPne6SPlus		# dynamic entry from dhcpd.leases
      192.168.1.179	freebsd.lan freebsd		# dynamic entry from dhcpd.leases
      192.168.1.171	Philips-hue.lan Philips-hue		# dynamic entry from dhcpd.leases
      192.168.1.105	Samsung-Galaxy-S7-edge.lan Samsung-Galaxy-S7-edge		# dynamic entry from dhcpd.leases
      192.168.1.180	tado.lan tado		# dynamic entry from dhcpd.leases
      192.168.1.187	nuc.lan nuc		# dynamic entry from dhcpd.leases
      
      # dhcpleases automatically entered
      192.168.1.183	MarksiPne6SPlus.lan MarksiPne6SPlus		# dynamic entry from dhcpd.leases
      192.168.1.172	Apple-TV-4K.lan Apple-TV-4K		# dynamic entry from dhcpd.leases
      192.168.1.102	Marks-iPhone-X.lan Marks-iPhone-X		# dynamic entry from dhcpd.leases
      192.168.1.106	Marks-iPad-Pro.lan Marks-iPad-Pro		# dynamic entry from dhcpd.leases
      192.168.1.179	freebsd.lan freebsd		# dynamic entry from dhcpd.leases
      192.168.1.171	Philips-hue.lan Philips-hue		# dynamic entry from dhcpd.leases
      192.168.1.105	Samsung-Galaxy-S7-edge.lan Samsung-Galaxy-S7-edge		# dynamic entry from dhcpd.leases
      192.168.1.180	tado.lan tado		# dynamic entry from dhcpd.leases
      192.168.1.187	nuc.lan nuc		# dynamic entry from dhcpd.leases
      
      # dhcpleases automatically entered
      192.168.1.183	MarksiPne6SPlus.lan MarksiPne6SPlus		# dynamic entry from dhcpd.leases
      192.168.1.172	Apple-TV-4K.lan Apple-TV-4K		# dynamic entry from dhcpd.leases
      192.168.1.102	Marks-iPhone-X.lan Marks-iPhone-X		# dynamic entry from dhcpd.leases
      192.168.1.106	Marks-iPad-Pro.lan Marks-iPad-Pro		# dynamic entry from dhcpd.leases
      192.168.1.179	freebsd.lan freebsd		# dynamic entry from dhcpd.leases
      192.168.1.171	Philips-hue.lan Philips-hue		# dynamic entry from dhcpd.leases
      192.168.1.105	Samsung-Galaxy-S7-edge.lan Samsung-Galaxy-S7-edge		# dynamic entry from dhcpd.leases
      192.168.1.180	tado.lan tado		# dynamic entry from dhcpd.leases
      192.168.1.187	nuc.lan nuc		# dynamic entry from dhcpd.leases
      

      Coming from OpenWrt, I'm pretty used to just having dnsmasq solve DHCP-provided hostnames automatically without me having to maintain static mappings. I guess the feature is implemented externally (PHP) in pfSense because it uses dhcpd instead of dnsmasq for DHCP server.

      It's been a while since I touched any PHP, but I'm pretty sure I won't be able to solve this myself.

      1 Reply Last reply Reply Quote 0
      • R
        rosenstand
        last edited by

        Yeah, so I couldn't help myself from cloning the repo and look at the code :-)

        In system_hosts_generate() at etc/inc/system.inc:569 I see this condition which I'm guessing could explain why it doesn't work at boot:

        if (!platform_booting()) {
        	system_dhcpleases_configure();
        }
        

        Any idea why the condition is there? I'll look into the boot process of pfSense next time I have an hour to burn :-)

        I can also see that dhcpd.leases parsing is done by /usr/local/sbin/dhcpleases. I still can't figure out why it repeats 3 times though...

        1 Reply Last reply Reply Quote 0
        • GertjanG
          Gertjan
          last edited by

          Right !

          I saw the same thing.
          After a clean boot - using dnsmasq : /etc/hosts seems ok - all my static DHCP are present.

          Restarting it, and ...

          [2.4.4-RELEASE][admin@pfsense.brit-hotel-fumel.net]/root: cat /etc/hosts
          127.0.0.1       localhost localhost.brit-hotel-fumel.net
          ::1     localhost localhost.brit-hotel-fumel.net
          192.168.1.1     pfsense.brit-hotel-fumel.net pfsense
          .......
          2001:470:1f13:5c0:2::c4 Tactile1.brit-hotel-fumel.net Tactile1
          2001:470:1f13:5c0:2::c5 Tactile2.brit-hotel-fumel.net Tactile2
          
          # dhcpleases automatically entered
          192.168.1.95    iPhonevanDiane.brit-hotel-fumel.net iPhonevanDiane              # dynamic entry from dhcpd.leases
          192.168.1.94    iPhonevanPieter.brit-hotel-fumel.net iPhonevanPieter            # dynamic entry from dhcpd.leases
          192.168.1.98    iPhonevebruiker.brit-hotel-fumel.net iPhonevebruiker            # dynamic entry from dhcpd.leases
          192.168.2.148   Galaxy-J3.brit-hotel-fumel.net Galaxy-J3                # dynamic entry from dhcpd.leases
          192.168.2.207   Galaxy-A5-2016.brit-hotel-fumel.net Galaxy-A5-2016              # dynamic entry from dhcpd.leases
          
          # dhcpleases automatically entered
          192.168.1.95    iPhonevanDiane.brit-hotel-fumel.net iPhonevanDiane              # dynamic entry from dhcpd.leases
          192.168.1.94    iPhonevanPieter.brit-hotel-fumel.net iPhonevanPieter            # dynamic entry from dhcpd.leases
          192.168.1.98    iPhonevebruiker.brit-hotel-fumel.net iPhonevebruiker            # dynamic entry from dhcpd.leases
          192.168.2.148   Galaxy-J3.brit-hotel-fumel.net Galaxy-J3                # dynamic entry from dhcpd.leases
          192.168.2.207   Galaxy-A5-2016.brit-hotel-fumel.net Galaxy-A5-2016              # dynamic entry from dhcpd.leases
          
          # dhcpleases automatically entered
          192.168.1.95    iPhonevanDiane.brit-hotel-fumel.net iPhonevanDiane              # dynamic entry from dhcpd.leases
          192.168.1.94    iPhonevanPieter.brit-hotel-fumel.net iPhonevanPieter            # dynamic entry from dhcpd.leases
          192.168.1.98    iPhonevebruiker.brit-hotel-fumel.net iPhonevebruiker            # dynamic entry from dhcpd.leases
          192.168.2.148   Galaxy-J3.brit-hotel-fumel.net Galaxy-J3                # dynamic entry from dhcpd.leases
          192.168.2.207   Galaxy-A5-2016.brit-hotel-fumel.net Galaxy-A5-2016              # dynamic entry from dhcpd.leases
          

          All my LAN network devices have static mapped IP's (all are trusted devices).
          Only devices that have no static DHCP map will multiply in the /etc/hosts file.

          I have found a work around : I'm using the default resolver (unbound) for the last 2 years ;)

          Btw : It's /usr/local/sbin/dhcpleases who is responsible for the host file updating.

          No "help me" PM's please. Use the forum, the community will thank you.
          Edit : and where are the logs ??

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.