Ubuntu 24.04: Workaround for Wi-Fi Disconnecting When Closing the Laptop Lid

Although the Surface Pro 5 (CPU: Core i7-7660U) is still powerful enough for daily use, it is restricted by not being officially supported by Windows 11.
While there are ways to forcefully install Windows 11, it carries risks regarding drivers and security, so this time I decided to take the plunge and install Ubuntu 24.04 LTS.

As a result, Ubuntu runs snappily and is ideal for development purposes.
However, there was one catch—
Closing the Type Cover automatically puts it to sleep, which disconnects the Wi-Fi.

This is caused by the Surface-specific specification where the “Type Cover = lid," but actually, this behavior is a common phenomenon on other laptops as well.

目次

Advertisement

Objective: Maintain Communication Even with the Lid Closed

  • Prevent the device from sleeping when closing the Type Cover or lid
  • Maintain Wi-Fi connectivity to prevent SSH and VPN connections from dropping
  • Ensure stable communication by adding a USB wired LAN adapter if necessary

Goal: Turn the Surface Pro 5 into a “Use-While-Closed Laptop" with Ubuntu

  • Disable suspend so operations continue even when closed
  • Eliminate waiting for Wi-Fi reconnection
  • Enhance communication pathways using a USB wired LAN

Issue: Ubuntu’s Lid Event and Wi-Fi Power-Saving Behavior

Ubuntu detects “lid close" events via ACPI (Advanced Configuration and Power Interface), and
systemd-logind automatically executes a suspend.
While this feature is convenient for mobile use, it is inconvenient when you want to use the device like a server.

During sleep, the Wi-Fi device loses power, and re-recognition and reconnection processes occur upon wake-up, causing temporary communication drops.
This can also cause SSH sessions and remote work to be forcibly disconnected.


Solution: Disable the Lid Switch via systemd-logind.conf Settings

① Edit the configuration file

sudo nano /etc/systemd/logind.conf

② Modify the following 3 lines

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

This ensures that closing the lid will not trigger sleep mode, allowing operations to continue.

③ Apply the settings

sudo systemctl restart systemd-logind

With this state, even if you close the Type Cover, Ubuntu will not go to sleep and the Wi-Fi will be maintained.
The Surface-specific “cover-linked suspend" issue is thus resolved.

④ Verify Wi-Fi communication

Confirm that responses do not stop with the following command while the lid is closed:

ping -c 5 8.8.8.8

If communication continues, it is a success.

⑤ Configure USB Wired LAN (Netplan)

In environments with weak Wi-Fi, using a wired LAN adapter provides stability.

Check the device name

ip link

Names starting with enx (e.g., enx00e04c123456) are USB wired LAN adapters.

Add the configuration

sudo vim /etc/netplan/01-netcfg.yaml

Content:

network:
  version: 2
  renderer: networkd
  ethernets:
    enx00e04c123456:
      dhcp4: true
      optional: true

Fix permissions:

sudo chmod 600 /etc/netplan/01-netcfg.yaml

Apply:

sudo netplan apply

Verify:

ip addr show enx00e04c123456

If inet 192.168.x.x is displayed, the connection is complete.

⑥ Control Priority Between Wi-Fi and Wired LAN

When using both simultaneously, set the priority using route-metric.

ethernets:
  enx00e04c123456:
    dhcp4: true
    dhcp4-overrides:
      route-metric: 100
wifis:
  wlan0:
    dhcp4: true
    dhcp4-overrides:
      route-metric: 200

Lower numbers indicate higher priority.
With this setting, wired LAN is prioritized, and Wi-Fi can be operated as a backup.

Summary: Key Points for Reviving a Surface with Ubuntu

Item | Configuration File | Content
Action when lid is closed | /etc/systemd/logind.conf | HandleLidSwitch=ignore
Maintain Wi-Fi | Netplan / wpa_supplicant | Prevent suspend
Wired LAN setup | /etc/netplan/01-netcfg.yaml | Auto-connect with dhcp4: true
Priority | route-metric | Use wired connection preferentially