Network connection issues

For a while now I’ve been having sporadic network connection issues on NixOS that I’m not sure how to debug. My PC is connected to Ethernet through a Powerline adapter. In NixOS, the connection will occasionally drop, and when I try pinging google.com, I get “temporary failure in name resolution” for a few minutes and then the connection comes back. This happens maybe a few times a day.
I dual-boot Windows and have never had an issue with the connection in Windows, so I’m pretty confident it isn’t a hardware issue. None of my other devices on my home network have this issue either. There’s nothing of note in journalctl that I can tell. I have a WiFi card too, and switching to that by disconnecting Ethernet in NetworkManager sometimes fixes it temporarily, but I’d prefer to use Ethernet most of the time. My networking configuration is pretty simple:

networking = {
  hostName = "desktop";

  # configured per-interface
  useDHCP = false;

  interfaces = {
    enp9s0 = {
      useDHCP = true;
    };
  };

  networkmanager.enable = true;

  firewall = {
    enable = true;
  };
};

Any tips on what I could try to debug this issue?

Use Network Manager to monitor when a link goes down

  networking.networkmanager.dispatcherScripts = [
     {
       source = (pkgs.writeShellApplication {
         name = "link_change.sh";
         runtimeInputs = [ pkgs.networkmanager ];
         text = ''
           logger "$0" "$@"
         '';
       }).out + "/bin/" + "link_change.sh";
     }
  ];

Then look for that script output in your journal when you encounter the problem. Hopefully this will help you determine if the problem is low-level networking or something at the application layer.

You also could check the logs in your router for reports of errors. You might even write a script to continuously monitor connectivity to your router. This could distinguish a problem with basic IP connectivity from a higher layer problem such as DNS.

Just because you do not see the failures in Windows does not mean they do not occur. Windows networking could be caching DNS, be more aggressive with retries or even more forgiving of malformed packets.

Also consider environmental activities. An air conditioner, microwave oven, refrigerator or even a florescent light balast can cause problems with PowerLine networking. If you find NixOS sometimes fails in the afternoon while Windows never has a problem at night, it could simply be caused by an air conditioner compressor coming on.