DHCP on hotspot

msknight

New Member
Joined
Jan 31, 2025
Messages
5
Reaction score
1
Credits
58
I've got a particular situation, and there is likely one correct way of solving it, and numerous wrong ways.

So far, I've been picking all the wrong ways.

I want to make it a wifi hostpot and serve DHCP on the wifi interface only.

I've got as far as giving the server an IP address and configured the hotpot.

The physical interface on eth0 is 192.168.1.253/24 and the gateway is 192.168.1.254 on another machine. I can attach a laptop to the wifi hotspot, give it a fixed IP of 192.168.1.50 and I can route and resolve DNS.

My only problem now is DHCP against the wlan0 interface.

I added the following into dhcpd.conf...
Code:
subnet 192.168.1.0 netmask 255.255.255.0 { 
range 192.168.1.100 192.168.1.200; 
option routers 192.168.1.254; 
option domain-name-servers 192.168.1.254, 192.168.0.15; 
default-lease-time 600; 
max-lease-time 7200; 
}

The service fails to start because the wlan interface has picked up the IP 10.42.0.1 and thus when I try to start the isc-dhcp-server.service I get...

Code:
Jan 31 09:11:03 iphotspot dhcpd[950]: No subnet declaration for wlan0 (10.42.0.1).
Jan 31 09:11:03 iphotspot dhcpd[950]: ** Ignoring requests on wlan0.  If this is not what
Jan 31 09:11:03 iphotspot dhcpd[950]:    you want, please write a subnet declaration
Jan 31 09:11:03 iphotspot dhcpd[950]:    in your dhcpd.conf file for the network segment
Jan 31 09:11:03 iphotspot dhcpd[950]:    to which interface wlan0 is attached. **
So there are a number of approaches I could take. Give wlan0 an IP on the 192.168.1.x and then do I give it the same as eth0 192.168.1.253 or give it a different IP. Find some way to attach that subnet declaration against wlan0 in the configuration file even though it's on a different IP.

For reference, isc-dhcp-server has wlan0 against the interfacesv4 setting.

I have tried changing the IP address for wlan0 into the same range, ti 192.168.1.252 and also the same IP as the eth0 address 192.168.1.253... but then everything goes to toast.

Grateful for advice.
 


I am a little further forward.

It seems that the DHCP is being called by NetworkManager and it is starting dnsmasq on the hoof, with a set of parameters.

Code:
nobody       550  0.0  0.9  14836  4096 ?        S    11:46   0:00 /usr/sbin/dnsmasq --conf-file=/dev/null --no-hosts --keep-in-foreground --bind-interfaces --except-interface=lo --clear-on-reload --strict-order --listen-address=192.168.1.253 --dhcp-range=192.168.1.1,192.168.1.244,60m --dhcp-leasefile=/var/lib/NetworkManager/dnsmasq-wlan0.leases --pid-file=/run/nm-dnsmasq-wlan0.pid --conf-dir=/etc/NetworkManager/dnsmasq-shared.d

All I need to find now, is how to change those parameters because dhcp-start is not valid in the following command.

Code:
sudo nmcli connection modify Hotspot ipv4.dhcp-start 192.168.1.100 ipv4.dhcp-end 192.168.1.200
 
You really need two interfaces to do this right.

You have to have an interface in the same subnet as the dhcp broadcast.

Do you have an interface in the 192.168.1.x subnet?

If you want to broadcast dhcp on the wlan. You'll have to put an IP range in that subnet.

It doesn't matter if you use bind or dnsmaq, you'll still have to do this.
 
OK - I've done that. I put the eth0 interface in the 192.168.0 subnet and the wlan0 interface on 192.168.1.253.
The client now connects via wifi, gets an IP from the pool and can talk to the gateway as well as resolve domain name.
My only problem now is that network manager starts dnsmasq with a wide DHCP range and I can't find out where it is configuring this...
Code:
--dhcp-range=192.168.1.1,192.168.1.244,60m
I have attempted to put a configuration file in /etc/dnsmasq.conf and it does look like my range from 100 to 200 is being picked up, but then that wide range is coming in again and overriding it.
Code:
Jan 31 12:02:27 iphotspot dnsmasq-dhcp[725]: DHCP, IP range 192.168.1.100 -- 192.168.1.200, lease time 1h
Jan 31 12:02:27 iphotspot dnsmasq-dhcp[725]: DHCP, IP range 192.168.1.1 -- 192.168.1.244, lease time 1h
 
That will work, but if you're going to split the subnet, you need to change your netmask and gateways.

Interface1.
192.168.1.1/25 or subnetmask 255.255.255.128
max IP range 2-127 .. gw 192.168.1.1

Interface2.
192.168.1.129/25 or subnetmask 255.255.255.128
max IP range 130-254 .. gw 192.168.1.129

The IP ranges can be smaller, but they have to be within that subnet.
 
Thanks. That bit has been done.

My only fly in the ointment now is that wide DHCP range that I can't override. I've been all over the /etc/NetworkManager directory and I can't find anything in any of the configuration files that seems to be responsible for that wide DHCP range.
 
This should come from /etc/dnsmasq for most distros.

Code:
grep dhcp-range /etc/dnsmasq.conf

Or possibly /etc/dnsmasq/dnsmasq.conf or /etc/dnsmasq.d/*conf
You can set the subnet mask like this

Code:
dhcp-range=192.168.0.140,192.168.0.200,255.255.255.128,12h
 
My only problem now is that network manager starts dnsmasq with a wide DHCP range and I can't find out where it is configuring this...
--dhcp-range=192.168.1.1,192.168.1.244,60m
Where exactly do you get this reported?
This looks like option to program rather than output from it.

edit:
In your post #1 you said:
I added the following into dhcpd.conf...
subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.100 192.168.1.200; option routers 192.168.1.254; option domain-name-servers 192.168.1.254, 192.168.0.15; default-lease-time 600; max-lease-time 7200; }

In your post #2 you said:
It seems that the DHCP is being called by NetworkManager and it is starting dnsmasq on the hoof, with a set of parameters.

nobody 550 0.0 0.9 14836 4096 ? S 11:46 0:00 /usr/sbin/dnsmasq --conf-file=/dev/null --no-hosts --keep-in-foreground --bind-interfaces --except-interface=lo --clear-on-reload --strict-order --listen-address=192.168.1.253 --dhcp-range=192.168.1.1,192.168.1.244,60m --dhcp-leasefile=/var/lib/NetworkManager/dnsmasq-wlan0.leases --pid-file=/run/nm-dnsmasq-wlan0.pid --conf-dir=/etc/NetworkManager/dnsmasq-shared.d

This is confusing because isc-dhcp and dnsmasq are 2 separate DHCP servers, you seem to be using both while only one is required and working, the other is uneeded and seemingly working.

I suggest you get rid of the one you're not using, this seems to be isc-dhcp.
 
Last edited:
Thanks all. I ended up using dnsmasq as network manager was triggering it, itself. (there turned out to be an instance of dnsmasq that was being started as its own process, rather than a service) I had trouble setting up a. ipv4.method manual so resorted to a shared. That caused network manager to force its own DHCP range which was very wide, so I got around this by using, in the configuration file /etc/NetworkManager/dnsmasq-shared.d/Hotspot.conf - a load of IP reservations so that DHCP wouldn't dish them out and it would give me some room for setting static IPs.

The overall configuration using nmcli was straightforward and simple... it was the behaviour of the DHCP configuration that network manager started automatically, and overriding the scope that I'd set in the configuration file, that was the last hurdle in the end. Fortunately, the reservations were listened to and I got some breathing space with it.

Thank you all for your input on this.
 
I had to disable the NetworkManager service because it caused so much trouble. I use ifupdown instead.

Signed,

Matthew Campbell
 


Members online


Top