OPNsense Forum

English Forums => General Discussion => Topic started by: hunterjwizzard on February 22, 2022, 03:54:16 AM

Title: DHCP Reservations?
Post by: hunterjwizzard on February 22, 2022, 03:54:16 AM
Hey folks,

I've been scouring the documentation and settings, but for the life of me I can't figure out how to set up DHCP reservations. Is it called something different on OPNsense?
Title: Re: DHCP Reservations?
Post by: RamSense on February 22, 2022, 08:30:56 AM
DHCP static mappings?

opnsense-services DHCPv4 (or V6) - leases and hit the + to make a static mapping
Title: Re: DHCP Reservations?
Post by: hunterjwizzard on February 22, 2022, 09:53:03 PM
That did the trick! Thanks!

Now to figure out why a few of my devices are not appearing on the OPNsense lease table...
Title: Re: DHCP Reservations?
Post by: RamSense on February 22, 2022, 09:56:03 PM
maybe those devices are not active at the moment, when at DHCP - leases scroll down on that page and hit the button [show all configured leases]

maybe than they show up?
Title: Re: DHCP Reservations?
Post by: cookiemonster on February 23, 2022, 12:03:01 AM
They'll show up once their current lease lapses, request a new one, and the defined ip is given.
Title: Re: DHCP Reservations?
Post by: hunterjwizzard on February 23, 2022, 01:27:06 AM
The devices in question are IP cameras, currently streaming a live image to my NVR. They are definitely active. They also show as active according to an IP scanner. I'm sure they'll show up eventually but it is odd that the router says there are 42 active leases but the scanner is finding 50.
Title: Re: DHCP Reservations?
Post by: RamSense on February 23, 2022, 07:20:31 AM
Just reboot the (WiFi)router and see what happens when they all get reconnected and show up in opnsense.
Title: Re: DHCP Reservations?
Post by: hunterjwizzard on February 23, 2022, 08:44:33 PM
Cameras are all wired(pro tip: do not use wifi cameras. They can be jammed with a $20 router some hacked russian firmware). But I will be rebooting the OPNsense this Saturday for some maintenance. We'll see if they show up then.
Title: Re: DHCP Reservations?
Post by: cookiemonster on February 23, 2022, 10:16:49 PM
If you reboot the camera, it will force it to request an ip address. This is the cleanest way unless you can ssh to the camera and force a dhcp client restart or has a management interface that allows you to do that. An ifdown followed by an ifup would also be the next best thing. Given that most cameras don't have an easy way to do that, a reboot is often necessary.
Title: Re: DHCP Reservations?
Post by: hunterjwizzard on February 24, 2022, 09:24:05 PM
Tried that - camera came right back up on its old IP address and still not detected on OPNsense. Very strange. There's probably a reset button on the camera I can try.
Title: Re: DHCP Reservations?
Post by: cookiemonster on February 24, 2022, 09:56:23 PM
Can you show the pool you have setup and the reservations?
Services > DHCPv4 > Interface . what is your range?
Then below on "DHCP Static Mappings for this interface." does the camera should appear with an ip?
Then in Services > DHCPv4 > Leases  - here you can add a static lease with the + sign
You might have done all this already.
The next thing is to check the logs. Seems to need to be changed to informational. Look for messages there after powercycling the camera.
Title: Re: DHCP Reservations?
Post by: hunterjwizzard on February 24, 2022, 11:34:21 PM
My DHCP range is 192.168.1.1 - 192.168.1.254

There are six cameras total, four have been static-mapped to ​251-254, those are working fine. The last two cameras are on .2 and .73. While we're on he subject the NVR itself is on .60. All three of those fail to appear on the leases map.


Checking the  logs, this is probably unrelated but I am seeing a bunch of errors like:

uid lease 192.168.1.197 for client 74:ee:2a:fe:38:d2 is duplicate on 192.168.1.0/24


Not sure if that means anything.


So because it couldn't hurt, I just bounced power to the camera on .2, just unplugged the POE injector since it happens to be near my desk, waited until it stopped appearing on the NVR, then put it back.

Same as before, camera came right back up on the same IP and was immediately detected by the NVR. It did not generate any messages in the log file.
Title: Re: DHCP Reservations?
Post by: cookiemonster on February 25, 2022, 01:18:10 PM
QuoteMy DHCP range is 192.168.1.1 - 192.168.1.254
Ok but what is your available range for dynamic allocation? The point being you should have a pool for dynamic allocation within your "Available range" that is separate from the static leases pool.
So let's say you have an Available range of :192.168.5.1 - 192.168.5.254
Then you could have a "range" 'from' 192.168.5.150 'to' 192.168.5.180. These will be used dynamically.
Then you could allocate reserved ips outside it and avoid collisions.

This might not be the problem at the moment though.
What I normally do to avoid mac typos is in the "DHCP Static Mappings for this interface." list, I find the device, click on the pencil button that takes it to the "Static DHCP Mapping" and add the IP I want to give it there. The same can be done from the leases page. A powercycle of the client device (not opn) later and it gets the allocated ip.
If that doesn't work for these cameras, I'm out of ideas.
Title: Re: DHCP Reservations?
Post by: hunterjwizzard on February 25, 2022, 07:55:15 PM
Right, sorry, the range is 192.168.1.10 to 192.168.1.245. This might explain why the camera at .2 is having a problem.

Quote from: cookiemonster on February 25, 2022, 01:18:10 PM
What I normally do to avoid mac typos is in the "DHCP Static Mappings for this interface." list, I find the device, click on the pencil button that takes it to the "Static DHCP Mapping" and add the IP I want to give it there. The same can be done from the leases page. A powercycle of the client device (not opn) later and it gets the allocated ip.
If that doesn't work for these cameras, I'm out of ideas.

That's exactly what I've been doing - the issue is that two of the cameras and the NVR are not appearing on the lease map at all. Along with 5 other active devices. It's very strange.

Anyway I've got a maintenance window tomorrow where the router will be coming down. Going to reboot the NVR and cycle the last 2 cameras again. I'll figure it out eventually.
Title: Re: DHCP Reservations?
Post by: RamSense on February 25, 2022, 09:40:09 PM
I have it also like cookie monster is saying.

When you hit the + for static, give that device an ip outside of your ->
services-dhcp4-lan: Range 192.168.1.10 - 192.168.1.245.

So that is why cam 251,252 til 254 are working, those are outside the dynamic range.
Try giving the devices with static ip inside the range an ip outside the range (250,249,248 etc) and I think it will solve the problem of not connecting.
Title: Re: DHCP Reservations?
Post by: hunterjwizzard on February 26, 2022, 11:13:57 AM
Maybe a picture will help.

On the left, see the camera IPs. Notice how two of those IPs are 192.168.1.2 & 192.168.1.73:

(https://i.imgur.com/MW8wxPF.png)

On the right, see the list of DHCP leases currently listed in numeric order. Notice how none of the IPs listed are 192.168.1.2 & 192.168.1.73. These IPs belong to IP cameras that are online and passing traffic. Also notice the absence of 192.168.1.60, the IP of my NVR, which is online and receiving information from the cameras.

In total there are 8 live devices on my network that don't have leases on the OPNsense DHCP. A few of these are even "smart plugs" which are going out through The Internet. The big question is why are these devices which have good valid IPs failing to appear on the OPNsense lease table?
Title: Re: DHCP Reservations?
Post by: cookiemonster on February 28, 2022, 10:56:01 PM
OPN will register a lease only if it has issued it. I'm wondering if the picture shows that the IP has been given to camera via it's management interface. If so, OPN doesn't know about it and won't appear in the leases list.
To solve, you need to use that interface to set it to dhcp, so that it requests it from OPN.
Try the log:
% sudo cat /var/log/dhcpd/latest.log | grep -i 'the-mac-address'
Look for a DHCPREQUEST line
Title: Re: DHCP Reservations?
Post by: hunterjwizzard on March 01, 2022, 04:01:41 AM
In this case the lease was handed out by the previous router. The camera DOES have a management interface... in chinese. So I'm sure I never set it staticly. Unfortunately, neither camera has a reset switch. So, new plan: unplug camera, set computer on static IP on that address, plug camera back in thus forcing it to pick up a new IP. Will let you know.