Raspberry pi did not autoconnect to vpn server. Troubleshoot.
Check VPN service logs, ensure correct credentials, verify network connectivity, and review configuration files for errors. Restart both the VPN service and the Raspberry Pi.
dnsmasq: set primary and fallback server
Edit /etc/dnsmasq.conf and add:
server=8.8.8.8 # Primary DNS (Google DNS)
server=1.1.1.1 # Fallback DNS (Cloudflare DNS)
Restart dnsmasq with sudo systemctl restart dnsmasq.
how to configure multiple dns servers with dnsmasq? I have a feeling that consecutive server statements overwrite previous entries:
In dnsmasq, consecutive server= statements do not overwrite each other; they add to the list of DNS servers. Ensure your /etc/dnsmasq.conf includes each server you want:
conf
server=8.8.8.8 # Primary DNS (Google DNS)
server=8.8.4.4 # Secondary Google DNS
server=1.1.1.1 # Tertiary DNS (Cloudflare DNS)
server=1.0.0.1 # Secondary Cloudflare DNS
Why does a host not resolve?
The issue likely stems from the no-resolv directive in your dnsmasq.conf file. This directive tells dnsmasq not to read any resolv.conf file, which means it won't use the specified nameservers (10.0.0.2 and 8.8.8.8) in /etc/resolv.conf.
Here are a few steps to troubleshoot and fix this:
Remove
no-resolvDirective: Comment out or remove theno-resolvline to allowdnsmasqto read from/etc/resolv.conf. ```confno-resolv
```
Explicitly Set Upstream DNS Servers: Since you removed
no-resolv, ensure/etc/resolv.confcontains the correct upstream DNS servers. Alternatively, keepno-resolvand explicitly add the DNS servers indnsmasq.conf:conf server=10.0.0.2 server=8.8.8.8 server=1.1.1.1 # FallbackCheck Interface Configuration: Ensure
dnsmasqis listening on the correct interface and that it is not blocked byexcept-interface=wlan0if relevant.Restart
dnsmasqService: After making changes, restart thednsmasqservice.bash sudo systemctl restart dnsmasqVerify DNS Resolution: Use
nslookupordigon the Raspberry Pi to verify DNS resolution.bash nslookup c2.localdomain dig c2.localdomainCheck
/etc/resolv.confon Clients: Ensure clients pointing todnsmasqas their DNS server have the correct entry in their/etc/resolv.conf, typically:bash nameserver 10.0.0.2
By following these steps, dnsmasq should correctly forward DNS queries to the specified upstream servers, allowing hostname resolution.
A few more things to check:
Check
/etc/hostsFile: Ensure that/etc/hostson your server contains the correct entry forC2.localdomain.bash cat /etc/hostsIt should include something like:10.0.0.113 C2.localdomainVerify DHCP Leases: Check the DHCP leases file to confirm that the IP assigned to
C2matches what you expect.bash cat /var/lib/misc/dnsmasq.leasesLook for an entry corresponding toC2and verify its IP address.Check DNS Query Logs: Look at the
dnsmasqlogs to see if it is querying forC2.localdomainand how it is responding.bash cat /var/log/dnsmasq.logEnsure you enable detailed logging if needed: Edit/usr/local/etc/dnsmasq.conf:log-queries log-facility=/var/log/dnsmasq.logThen restartdnsmasq:bash sudo systemctl restart dnsmasqDNS Forwarding: Ensure that
dnsmasqis forwarding queries correctly. You can test by specifyingdnsmasqdirectly:bash nslookup C2.localdomain 10.0.0.2Local DNS Resolution: Since
C2.localdomainis a local hostname, ensure it is being resolved locally and not relying on external DNS servers. Thedhcp-hostdirective should handle this.Network Configuration: Make sure that all devices on your network are configured to use
10.0.0.2as their DNS server.
By checking these areas, you should be able to pinpoint why C2.localdomain is not resolving.
Example:
pi@p2:~ $ nslookup c2.localdomain Server: 127.0.0.1 Address: 127.0.0.1#53
** server can't find c2.localdomain: NXDOMAIN
pi@p2:~ $ nslookup c2.localdomain 10.0.0.2 Server: 10.0.0.2 Address: 10.0.0.2#53
Name: c2.localdomain Address: 10.0.0.113
pi@p2:~ $ cat /etc/dnsmasq.conf | grep server server=10.0.0.2 server=8.8.8.8 server=1.1.1.1 pi@p2:~ $
It looks like dnsmasq is correctly forwarding the query to itself and resolving c2.localdomain to 10.0.0.113 when queried directly. However, it seems that the local resolver on your Raspberry Pi is not using dnsmasq for DNS resolution.
Here are the steps to ensure that the Raspberry Pi uses dnsmasq as its DNS server:
Ensure
dnsmasqis Listening on Local Interface: Verify thatdnsmasqis listening on127.0.0.1. Check/usr/local/etc/dnsmasq.conffor any interface restrictions:bash grep listen-address /usr/local/etc/dnsmasq.confIt should look something like:listen-address=127.0.0.1 listen-address=10.0.0.2Configure
/etc/resolv.conf: Ensure that/etc/resolv.confincludes127.0.0.1or10.0.0.2as the primary DNS server. On some systems,/etc/resolv.confis dynamically generated, so you might need to edit a different file:For Static Configuration: Edit
/etc/resolv.confdirectly:bash sudo nano /etc/resolv.confAdd or ensure the following line is present:nameserver 127.0.0.1Or:nameserver 10.0.0.2For Dynamic Configuration: If
/etc/resolv.confis regenerated by DHCP or another service, you might need to modify the DHCP client configuration. For example, if usingdhcpcd, edit/etc/dhcpcd.conf:bash sudo nano /etc/dhcpcd.confAdd the following lines:static domain_name_servers=127.0.0.1Or:static domain_name_servers=10.0.0.2Then restartdhcpcd:bash sudo systemctl restart dhcpcdAlternative Method: Use
resolvconf: If your system usesresolvconf, you can create a custom configuration file:bash sudo mkdir -p /etc/resolvconf/resolv.conf.d/head sudo nano /etc/resolvconf/resolv.conf.d/headAdd:nameserver 127.0.0.1Or:nameserver 10.0.0.2Then regenerateresolv.conf:bash sudo resolvconf -u
Check Network Manager or Similar Services: If you are using
NetworkManageror another service to manage your network, it might be overriding the DNS settings. You can check and modify the settings accordingly.Restart
dnsmasq: After making these changes, restartdnsmasqto ensure it picks up the new configuration:bash sudo systemctl restart dnsmasqFlush DNS Cache: Flush the DNS cache on the Raspberry Pi to clear any old entries:
bash sudo systemd-resolve --flush-caches
By ensuring that 127.0.0.1 or 10.0.0.2 is listed as the primary DNS server in /etc/resolv.conf, the Raspberry Pi should use dnsmasq for DNS resolution, including resolving local hostnames like c2.localdomain.