Baeldung Pro – Linux – NPI EA (cat = Baeldung on Linux)
announcement - icon

Learn through the super-clean Baeldung Pro experience:

>> Membership and Baeldung Pro.

No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.

1. Overview

On Linux machines, frequent and unpredictable Wi-Fi disconnects can be a frustrating issue. While temporary solutions like rebooting, toggling airplane mode, or restarting the networking service might be effective, they could be short-lived as the issue might recur often.

In this tutorial, we’ll explore common causes and practical solutions to get rid of frequent Wi-Fi connection drops and ensure a more seamless network experience.

2. Common Culprits

Before we jump into solutions, let’s identify the common causes of random Wi-Fi disconnections. By understanding the potential causes, we can narrow down the scope and focus on the most likely reasons for issues.

Here, we focus on causes rooted within the Linux system, excluding router-originated or signal interference issues:

  • Outdated or incompatible Wi-Fi drivers: Using outdated or incompatible Wi-Fi drivers can interfere with system network settings, leading to drops.
  • Network misconfiguration: Incorrect network settings can cause Wi-Fi connectivity issues, such as conflicts in IP addresses, DNS issues, incompatible network modes, incorrect proxy settings, or conflicts between network management tools.
  • Power management issues: Aggressive power management settings for the Wi-Fi adapter can cause it to turn off or disconnect.

Let’s look at each of these potential reasons for Wi-Fi disconnecting unexpectedly.

3. Turn off Power Saving

Sometimes, the system’s power-saving feature can cut energy to the Wi-Fi adapter and cause it to disconnect. To avoid this, we can disable power management for the wireless adapters.

One way to do this is by editing the default-wifi-powersave-on.conf configuration file. After opening the file using sudo privileges, we modify the [connection] section and set the wifi.powersave directive to 2:

$ cat /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
...
[connection]
wifi.powersave = 2
...

Next, we can restart NetworkManager using systemctl to apply the changes:

$ sudo systemctl restart NetworkManager.service

As usual, sudo might be necessary to restart the network manager. Either way, this should ensure Wi-Fi power saving stays off even after reboot.

4. Disable IPv6

Many older routers and network setups rely on IPv4 and may not handle IPv6 traffic efficiently, leading to unstable connections. Additionally, enabling both IPv4 and IPv6 may also cause conflicts, confusing the network manager and resulting in connection drops.

To bypass this, let’s use the sysctl -w command to disable IPv6:

$ sysctl -w net.ipv6.conf.all.disable_ipv6=1
$ sysctl -w net.ipv6.conf.default.disable_ipv6=1
$ sysctl -w net.ipv6.conf.lo.disable_ipv6=1

By setting these variables to 1, we disable IPv6 on the network interface. However, this change is lost upon reboot.

We can make it persist by directly editing the /etc/sysctl.conf file:

$ cat /etc/sysctl.conf
...
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

Finally, we execute sysctl -p to apply and persist the changes without needing to reboot the system. When done, this could help stabilize the Wi-Fi connection. However, disabling IPv6 comes with the trade-off of potentially losing out on some of its advantages.

5. Switch Networking Service

Sometimes, simply switching the service responsible for networking might do the trick. For instance, we can use the systemd-networkd daemon instead of the default NetworkManager. This also helps us check whether the current network service is causing disconnections.

First, let’s stop and disable the NetworkManager to prevent conflicts using systemctl:

$ sudo systemctl stop NetworkManager.service
$ sudo systemctl disable NetworkManager.service

After that, let’s enable systemd-networkd to make it the operating network service:

$ sudo systemctl enable systemd-networkd.service
$ sudo systemctl start systemd-networkd.service

Of course, we also have to start the systemd-resolved service to handle network name resolution:

$ sudo systemctl enable systemd-resolved
$ sudo systemctl start systemd-resolved

Alternatively, we can also try other network managers such as WICD.

6. Reinstall Wireless Drivers

If switching the network manager doesn’t resolve these random Wi-Fi disconnections, it’s worth trying to reinstall or update the Wi-Fi adapter driver. Outdated or corrupt drivers can often cause connectivity problems, and reinstalling them may help resolve these issues.

Thus, it might help to identify and install the correct wireless drivers.

7. Different Kernel Version

Since the kernel is responsible for many aspects of a system, including networking, changing the current kernel can be a way to fix frequent Wi-Fi connection problems.

7.1. Upgrade the Kernel

Running an older version of Linux might lead to connectivity issues too. So, updating the kernel can often resolve these problems, as newer kernels include bug fixes and improvements for hardware compatibility.

To do that, we can use a local package manager like the apt command to update and upgrade the system:

$ sudo apt update && sudo apt upgrade

Once done, we can verify the kernel version with the uname -r command.

7.2. Roll back to an Older Kernel

Conversely, updating the kernel can sometimes introduce new bugs or compatibility issues with current Wi-Fi drivers. So, downgrading to a previous version that worked correctly is another way to avoid frequent Wi-Fi drops.

If the issue started after a recent update, we can try booting into an older kernel version.

First, let’s list available kernels on the system to make sure the previous version still exists:

$ apt list --installed | grep linux-image

Here, the command retrieves all installed packages on the system and then pipes the output through grep to show only the installed Linux kernel images. If not available, we should be able to easily install the specific version with apt.

Next, let’s reboot the system and select the previous kernel from the GRUB menu. To access it, we can press and hold the Shift key if using BIOS for booting. If the machine uses UEFI, we can press Esc repeatedly during GRUB loading to bring up the boot menu.

Just like before, we use uname -r to verify the kernel version once the system boots up. By downgrading the kernel, we could bypass the issues introduced in the newer version.

8. Check for Hardware Issues

If none of the above solutions work, the problem might turn out to be in the hardware.

For example, when a Wi-Fi card overheats, it can cause the hardware to malfunction, leading to intermittent connectivity issues. Similarly, a Wi-Fi card with a problematic chip, whether due to physical damage or other hardware issues, can cause the same problems.

In this case, we can switch to a different Wi-Fi adapter and test the connection to help us determine if the issue lies with the main network card.

9. Conclusion

In this article, we explored various culprits behind frequent Wi-Fi connection drops. We then delved into practical solutions to address these issues, such as disabling certain system features, trying different network managers, and more.

Applying these steps should help pinpoint and ultimately resolve these random Wi-Fi disconnections. Therefore, it’s important to methodically troubleshoot and experiment with different solutions to find the one that works best.