I am trying to set up some static IP leases on /etc/config/dhcp.
According to the User Guide, I add the section config host with options 'mac', 'ip' or 'name' etc. whatever I can find under /var/dhcp.leases e.g.
In this example it seems you set up one 'config host' section for each device.
I'd like to confirm if this is correct (before locking myself out potentially...).
What do you think?
Should work fine. Here are a couple of mine so you have another data point. Using LuCI is the easiest way to do this, as it already knows about the MAC and other info, so you can just pick them from the menus on the Static Leases page when you do an "Add"...
config host
option name 'ubuntu-server'
option dns '1'
option mac '00:15:7E:BD:9B:B5'
option ip '10.1.1.200'
option hostid '0200'
option duid '00020000ac1d0ce49795f046f349'
config host
option name 'home-assistant'
option dns '1'
option mac '00:15:5D:01:A4:0E'
option ip '10.1.1.202'
option hostid '0202'
option duid '00049be8e4d00f32b053270b060705d70382'
If mac is specified that has priority, any request from that MAC will be leased, and the hostname in the DNS table will be set to either the name configured, or if that is undefined, the name sent by the device.
Forcing the name is useful for things like cheap IP cameras or iPhones that default to the same name.
If mac is not specified but name is, then the first request from that name will be leased, regardless of the MAC. This is useful for laptops that may be connected wired or wireless (with different MAC, but the same name). Or any situation where the NIC or the entire device may be replaced but you want to keep the same IP.
Is the inverted comma compulsory? I was wondering if I need/should set one. Looks indeed cleaner to me doing it, especially as so far I have been avoiding blank spaces.
But I used hyphens and was wondering if these should be underscores instead (apparently dnsmasq is sensitive here).
What's the advantage of using hostid and dns ("Add static forward and reverse DNS entries for this host." hmm, and if not?).
Ok, I quoted all and all clients shift to their allocated static IP when they reconnect.
However, running /etc/init.d/dnsmasq restart fails with udhcpc: started, v1.36.1 udhcpc: broadcasting discover udhcpc: no lease, failing
However, I haven't manually deleted anything from /tmp/dhcp.leases or /var/dhcp.leases.
So by and by devices should shift to their new IP location. Maybe a restart of the router itself will shift all of them, but that's not urgent for now.
This is normal. The dhcp server first proves to see if there is another server on the network. If it gets a lease, that means yes there is and the server will not start because it would cause a conflict. If no lease is found, the server starts normally.