fix: dnsmasq dhcp

This commit is contained in:
Ryan Yin
2024-02-17 13:45:14 +08:00
parent fd4f1f9086
commit 34ca7615b4
2 changed files with 18 additions and 3 deletions

View File

@@ -13,6 +13,20 @@ NOTE: dae(running on aquamarine) do not provides http/socks5 proxy server, so a
- check dae's log by `sudo journalctl -u dae`
1. DNS & DHCP is provided by `dnsmasq` service, check the configuration of `dnsmasq`.
### DHCP cannot be obtained
1. `ss -tunlp`, check if `dnsmasq` is running and listening on udp port 67.
1. `journalctl -u dnsmasq` to check the log of `dnsmasq`.
1. Request a new IP address by disconnect and reconnect one of your devices' wifi.
1. `nix shell nixpkgs#dhcpdump` and then `sudo dhcpdump -i br-lan`, check if the DHCP request is received by `dnsmasq`.
1. The server listens on UDP port number 67, and the client listens on UDP port number 68.
1. DHCP operations fall into four phases:
1. Server **discovery**: The DHCP client broadcasts a DHCPDISCOVER message on the network subnet using the destination address 255.255.255.255 (limited broadcast) or the specific subnet broadcast address (directed broadcast).
1. IP lease **offer**: When a DHCP server receives a DHCPDISCOVER message from a client, which is an IP address lease request, the DHCP server reserves an IP address for the client and makes a lease offer by sending a DHCPOFFER message to the client.
1. IP lease **request**: In response to the DHCP offer, the client replies with a DHCPREQUEST message, broadcast to the server,[a] requesting the offered address.
1. IP lease **acknowledgement**: When the DHCP server receives the DHCPREQUEST message from the client, it sends a DHCPACK packet to the client, which includes the lease duration and any other configuration information that the client might have requested.
1. So if you see only `DISCOVER` messages, the dhsmasq is not working properly.
## References

View File

@@ -4,7 +4,7 @@
mainGatewayAddress = "192.168.5.1";
dhcpRange = {
start = "192.168.5.50";
end = "102.168.5.99";
end = "192.168.5.99";
};
in {
# https://github.com/ghostbuster91/blogposts/blob/main/router2023-part2/main.md
@@ -116,8 +116,8 @@ in {
services.resolved.enable = false;
services.dnsmasq = {
enable = true;
# resolve local queries (i.e. add 127.0.0.1 to /etc/resolv.conf)
resolveLocalQueries = true;
# resolve local queries (add 127.0.0.1 to /etc/resolv.conf)
resolveLocalQueries = false; # may be conflict with dae, disable this.
alwaysKeepRunning = true;
# https://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=tree
settings = {
@@ -149,6 +149,7 @@ in {
# Override the default route supplied by dnsmasq, which assumes the
# router is the same machine as the one running dnsmasq.
"option:router,${hostAddress}"
"option:dns-server,${hostAddress}"
];
# local domains