welw | About_me Blog WebAssembly

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:

  1. Remove no-resolv Directive: Comment out or remove the no-resolv line to allow dnsmasq to read from /etc/resolv.conf. ```conf

    no-resolv

    ```

  2. Explicitly Set Upstream DNS Servers: Since you removed no-resolv, ensure /etc/resolv.conf contains the correct upstream DNS servers. Alternatively, keep no-resolv and explicitly add the DNS servers in dnsmasq.conf: conf server=10.0.0.2 server=8.8.8.8 server=1.1.1.1 # Fallback

  3. Check Interface Configuration: Ensure dnsmasq is listening on the correct interface and that it is not blocked by except-interface=wlan0 if relevant.

  4. Restart dnsmasq Service: After making changes, restart the dnsmasq service. bash sudo systemctl restart dnsmasq

  5. Verify DNS Resolution: Use nslookup or dig on the Raspberry Pi to verify DNS resolution. bash nslookup c2.localdomain dig c2.localdomain

  6. Check /etc/resolv.conf on Clients: Ensure clients pointing to dnsmasq as 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:

  1. Check /etc/hosts File: Ensure that /etc/hosts on your server contains the correct entry for C2.localdomain. bash cat /etc/hosts It should include something like: 10.0.0.113 C2.localdomain

  2. Verify DHCP Leases: Check the DHCP leases file to confirm that the IP assigned to C2 matches what you expect. bash cat /var/lib/misc/dnsmasq.leases Look for an entry corresponding to C2 and verify its IP address.

  3. Check DNS Query Logs: Look at the dnsmasq logs to see if it is querying for C2.localdomain and how it is responding. bash cat /var/log/dnsmasq.log Ensure you enable detailed logging if needed: Edit /usr/local/etc/dnsmasq.conf: log-queries log-facility=/var/log/dnsmasq.log Then restart dnsmasq: bash sudo systemctl restart dnsmasq

  4. DNS Forwarding: Ensure that dnsmasq is forwarding queries correctly. You can test by specifying dnsmasq directly: bash nslookup C2.localdomain 10.0.0.2

  5. Local DNS Resolution: Since C2.localdomain is a local hostname, ensure it is being resolved locally and not relying on external DNS servers. The dhcp-host directive should handle this.

  6. Network Configuration: Make sure that all devices on your network are configured to use 10.0.0.2 as 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:

  1. Ensure dnsmasq is Listening on Local Interface: Verify that dnsmasq is listening on 127.0.0.1. Check /usr/local/etc/dnsmasq.conf for any interface restrictions: bash grep listen-address /usr/local/etc/dnsmasq.conf It should look something like: listen-address=127.0.0.1 listen-address=10.0.0.2

  2. Configure /etc/resolv.conf: Ensure that /etc/resolv.conf includes 127.0.0.1 or 10.0.0.2 as the primary DNS server. On some systems, /etc/resolv.conf is dynamically generated, so you might need to edit a different file:

    • For Static Configuration: Edit /etc/resolv.conf directly: bash sudo nano /etc/resolv.conf Add or ensure the following line is present: nameserver 127.0.0.1 Or: nameserver 10.0.0.2

    • For Dynamic Configuration: If /etc/resolv.conf is regenerated by DHCP or another service, you might need to modify the DHCP client configuration. For example, if using dhcpcd, edit /etc/dhcpcd.conf: bash sudo nano /etc/dhcpcd.conf Add the following lines: static domain_name_servers=127.0.0.1 Or: static domain_name_servers=10.0.0.2 Then restart dhcpcd: bash sudo systemctl restart dhcpcd

    • Alternative Method: Use resolvconf: If your system uses resolvconf, you can create a custom configuration file: bash sudo mkdir -p /etc/resolvconf/resolv.conf.d/head sudo nano /etc/resolvconf/resolv.conf.d/head Add: nameserver 127.0.0.1 Or: nameserver 10.0.0.2 Then regenerate resolv.conf: bash sudo resolvconf -u

  3. Check Network Manager or Similar Services: If you are using NetworkManager or another service to manage your network, it might be overriding the DNS settings. You can check and modify the settings accordingly.

  4. Restart dnsmasq: After making these changes, restart dnsmasq to ensure it picks up the new configuration: bash sudo systemctl restart dnsmasq

  5. Flush 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.