Restoring Debian/Ubuntu networking from the command line

· 384 words · 2 minute read

I recently upgraded from Ubuntu 20.04 LTS to 22.04 LTS, and a bunch of stuff broke. As with my last problem, it’s probably because I had used third-party repositories or .debs that pulled in different versions of dependencies, so that updating to new standard packages couldn’t figure out how to also update the dependencies. Anyway, I was tired of the standoff, and just went ahead and removed a critical package (python3.10) and let it apt autoremove the billion packages that needed it. As expected, critical stuff stopped working, including all my network connections. This made it hard to reinstall anything, and it seemed like every article on the web relied on stuff I’d uninstalled, such as network-manager.

Here is what I did:

  • ping 192.168.1.1. Network unreachable.
  • ifconfig and note which interfaces are still there. My wireless interface was gone, but enp1s0 was still there. So I grabbed a long Ethernet cable and plugged my machine directly into my router.
  • ping 192.168.1.1. Network still unreachable, so nothing happened automatically.
  • sudo ifconfig enp1s0 192.168.1.99/24. This told the network that I should use a static IP address for my Ethernet interface, with a gateway of 255.255.255.0. I used .99 as a guess for an unoccupied address.
  • sudo ifconfig enp1s0 up. Enable the Ethernet interface.
  • ping 192.168.1.1. This worked, so I knew I could now route packets on my subnet.
  • ping 8.8.4.4. This failed, so I knew I had to figure out how to route packets outside my subnet.
  • sudo route add default gw 192.168.1.1. This is my home router’s gateway.
  • ping 8.8.4.4. This worked, so the network and internet were back.
  • dig yahoo.com. This failed, so I knew the next step was to restore DNS. (I use yahoo.com because I never go there, so I don’t have to worry about unwittingly seeing cached results.)
  • dig @8.8.4.4 yahoo.com. This worked, and satisfied a bit of paranoia that UDP wasn’t back.
  • sudo nano /etc/resolv.conf and add nameserver 192.168.1.1. This told the network that DNS could be resolved from my home router’s DNS server.
  • dig archive.ubuntu.com. This worked, so I now probably had enough to hand the rest of the job over to apt.
  • sudo apt install network-manager. Success! My wifi reappeared in the menu bar a few moments later, and I was able to reinstall everything that was missing.