Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DHCP server dynamic IP allocation with Host Name and Description fields from Static info #2946

Closed
Northguy opened this issue Nov 20, 2018 · 13 comments
Assignees
Labels
bug Production bug
Milestone

Comments

@Northguy
Copy link
Contributor

Northguy commented Nov 20, 2018

I configured OPNsense as DHCP server and would like to identify my devices in the DHCP leases table a bit more easily, based on a description. Most devices only show generic manufacturer info under the MAC address, but do not provide a Hostname or a more verbose description.

I tried creating a static mapping for the MAC address but am not necessarily looking for a static IP lease. Therefore I did not fill in the IP address in the edit box. According to the help it says "If no IPv4 address is given, one will be dynamically allocated from the pool", but if I follow this way, the MAC address is shown as ' static' in the leases table without an IP. i.e.: I have created a static lease without a visible dynamic IP?

Is this a bug, or is there another way to create an easily identifiable indicator for the MAC addresses that have obtained a dynamic lease?

Issue seems (not entirely) related to #1465

@zz0rk
Copy link

zz0rk commented Nov 20, 2018

I am in the same boat and would also appreciate some feedback from an expert. I've set up several static DHCP mappings and they show as 'active' when in use under Leases; but no IP address is being populated for each entry row.

@ja-finn
Copy link

ja-finn commented Feb 8, 2019

I was looking for the same. In my old Asus router I could just type in a new hostname and I'm guessing it tied it to the MAC. It's really nice to have for devices that you can't set a hostname on (ie IoT).

Further it seems that setting a static entry without defining an IP address leaves you unable to edit the entry afterwards. No edit button or thrascan to remove it.

OPNsense 19.1.1

screenshot from 2019-02-08 09-54-46

@teklabania
Copy link

Here's some more formal BUG report for the issue.

Brief description:

What I want to achieve is to translate MAC address to hostname without caring about IP address assigned to the host.

OPNSense: 19.1.6

Steps to reproduce

  • go to Services -> Unbound DNS -> General
  • set "Register DHCP static mappings" to true
  • go to Services -> DHCPv4 -> Interface
  • scroll down to section "DHCP Static Mappings for this interface."
  • click "+" to add new Static DHCP Mapping
  • Under "Static DHCP Mapping" provide:
    • MAC address
    • Hostname
  • click Save
  • go to Services -> DHCPv4 -> Leases

Results

  • IP from the pool is leased to MAC address
  • No hostname is assigned to IP address
  • DNS query does not resolve hostname provided under "Static DHCP Mapping"

Expected results

  • IP from the pool is leased to MAC address
  • Hostname is assigned to IP address
  • DNS query resolves hostname provided under "Static DHCP Mapping"

Screenshot:

The picture shows the current state and the arrows show where the IP leases should go to.
2019-04-24_21-21

Additional info:

https://forum.opnsense.org/index.php?topic=12369.0
https://forum.netgate.com/topic/125306/dhcp-static-mapped-hostname-to-dns-resolver-without-specifying-ip

@AdSchellevis
Copy link
Member

AdSchellevis commented Apr 25, 2019

@teklabania it can't do what you think it does, but might require better explanation in the help text (ideas are welcome).

When the marker is set, it will write out all dns entries which come with a valid ip address.

if (isset($config['unbound']['regdhcpstatic']) && is_array($config['dhcpd'])) {
foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) {
if (isset($dhcpifconf['staticmap']) && isset($dhcpifconf['enable'])) {
foreach ($dhcpifconf['staticmap'] as $host) {
if (!$host['ipaddr'] || !$host['hostname']) {
continue;
}
$domain = $config['system']['domain'];
if ($host['domain']) {
$domain = $host['domain'];
} elseif ($dhcpifconf['domain']) {
$domain = $dhcpifconf['domain'];
}
$unbound_entries .= "local-data-ptr: \"{$host['ipaddr']} {$host['hostname']}.{$domain}\"\n";
$unbound_entries .= "local-data: \"{$host['hostname']}.{$domain} IN A {$host['ipaddr']}\"\n";
if (!empty($host['descr']) && $unboundcfg['txtsupport'] == 'on') {
$unbound_entries .= "local-data: '{$host['hostname']}.{$domain} TXT \"".addslashes($host['descr'])."\"'\n";
}
}
}
}
}

Since leases change over time, this specific feature would require unbound to restart after every given lease, to load the file again (which for obvious reasons doesn't happen).

The duplication of entries as shown in the last screenshot seem to happen on my end as well, which should hopefully be easy to fix. I'll prepare a fix and close the issue, feel free to suggest changes in a new ticket to better explain the unbound registration feature.

It might be an option to check DHCP Registration, which has a daemon active to watch the leases file, although I'm not exactly sure if/how static leases end up in /var/dhcpd/var/db/dhcpd.leases.

@AdSchellevis
Copy link
Member

In theory it would be possible to add logic in https://github.com/opnsense/core/blob/master/src/opnsense/scripts/dns/unbound_dhcpd.py to use the configured hostname, but you easily end up in a race condition there, since a change doesn't trigger a new lease.

It looks like client-hostname in /var/dhcpd/var/db/dhcpd.leases is always set to the response received from the client. I can't spend the amount of time needed to add a feature to support this, it works out of the box when using static leases. The gui glitch should be fixed by 839ec35.

@AdSchellevis AdSchellevis self-assigned this Apr 25, 2019
@AdSchellevis AdSchellevis added the bug Production bug label Apr 25, 2019
@fichtner fichtner added this to the 19.7 milestone Apr 25, 2019
fichtner pushed a commit that referenced this issue Apr 28, 2019
@Northguy
Copy link
Contributor Author

Northguy commented May 16, 2019

Hi @AdSchellevis . I see you closed the issue I originally logged. I was not available to react due to spring holiday at the time you closed the issue and afterward forgot about it, so please forgive me resurrecting this thread.

I did not log a formal template for this issue, so it is good that @teklabania did put in the effort. My case was actually more simple than @teklabania wrote, but had almost the same goal. Although I do not care about the Unbound part of his problem description.

Brief description:
What I want to achieve is to have recognisable devices in the DHCP leases table, while i do not actually care that a static IP is assigned (or resolved by Unbound DNS). In order to reach this goal, I add a hostname and description while not providing a static IP in the static leases table (as is described by the help text)

OPNSense: 19.1.7

Steps to reproduce
go to Services -> Unbound DNS -> General
set "Register DHCP static mappings" to true
go to Services -> DHCPv4 -> Interface
scroll down to section "DHCP Static Mappings for this interface."
click "+" to add new Static DHCP Mapping
Under "Static DHCP Mapping" provide:
MAC address
Hostname
click Save
go to Services -> DHCPv4 -> Leases
Results
IP from the pool is not visibly leased to MAC address
No hostname is assigned to IP MAC address
DNS query does not resolve hostname provided under "Static DHCP Mapping"

Expected results
IP from the pool is leased to MAC address
Hostname and description is assigned to MAC / IP address
DNS query resolves hostname provided under "Static DHCP Mapping"

As Unbound is left out of this equation, this would not result in a race condition?

Screenshot:
image

It is unclear which 'glitch' you refer to with 839ec35, but applying the mentioned patch did not result in desired outcome as indicated with the screenshot.

@AdSchellevis
Copy link
Member

@Northguy the gui glitch this 839ec35 fixes is the duplication of the mac addresses as mentioned in the screenshot, descriptions should be visible as configured when set in a static entry without an address (at least on my end).

@Northguy
Copy link
Contributor Author

OK, applied opnsense-patch 839ec35 which indeed combines information. Only issue I see is that Interface name now has gone missing....

image

@AdSchellevis
Copy link
Member

@Northguy can you create new issue for the missing interface in this case? I'll try to look at it when I have a bit of time available.

@teklabania
Copy link

@AdSchellevis, thank you for taking care of this issue with duplicated mac addresses. It's a pitty we cannot get the feature of getting hostname being assigned to MAC and being resolved by DNS. So putting additional info under hostname form could be good idea.

Currently under:
Services -> DHCPv4 -> Interface -> DHCP Static Mappings for this interface -> "+"
we have:

Hostname: Name of the host, without domain part.

Maybe something like this would do:

Hostname: Name of the host, without domain part. If no IPv4 address is given above, hostname will not be resolved by Unbound DNS.

@AdSchellevis
Copy link
Member

@teklabania sounds like a good idea indeed to better explain the feature, would this be something you might be willing to create a pull request for?

@Northguy
Copy link
Contributor Author

@Northguy can you create new issue for the missing interface in this case? I'll try to look at it when I have a bit of time available.

Done. See #3487

@Northguy
Copy link
Contributor Author

@teklabania sounds like a good idea indeed to better explain the feature, would this be something you might be willing to create a pull request for?

@AdSchellevis see #3488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Production bug
Development

No branches or pull requests

6 participants