Disable Automatic Airplane Mode in Ubuntu 22.04 HP Laptop

Last updated: March 27, 2023 — 10 Comments

For laptop user, there could be a quite annoying issue that the ‘Airplane Mode’ automatically turns on when lid closed, or when the screen is tilted sideways.

For HP laptops running Ubuntu, Fedora, or other Linux using systemd, there’s a workaround by mapping the HP e057 and e058 scancodes to 240 (no-op key). So it won’t automatically turn on Airplane Mode, while the option in ‘Wi-Fi’ settings and fn + F12 key combination still function.

NOTE: This tutorial is tested and works in my Ubuntu 22.04 on HP 246 laptop. It may or may not work in your machine.

1. Create service to remap the scancode:

1.) Firstly, press Ctrl+Alt+T on keyboard to open terminal. When it opens, run command to create a service file and edit via Gedit text editor:

sudo gedit /etc/systemd/system/hp-keycodes.service

Depends on your desktop environment, replace gedit in command with your system text editor (e.g., gnome-text-editor for Ubuntu 22.10+/Fedora workstation), or use nano command line editor that works in most Linux. When file opens, paste below lines and save it.

Description=HP setkeycodes fix

ExecStart=/usr/bin/setkeycodes e057 240 e058 240


As mentioned, this service will map e057 and e058 scancodes to no operation keycode 240.

2. Enable the service

2.) After saving the file (for nano, press Ctrl+X, type y and hit Enter), reload and enable the service by running commands below one by one:

sudo systemctl daemon-reload
sudo systemctl enable hp-keycodes.service

And finally restart your computer and check the result!

Undo the changes:

If the method does not work for you, simply run the command in terminal (Ctrl+Alt+T) to disable the service:

sudo systemctl disable hp-keycodes.service

Next remove the file:

sudo rm /etc/systemd/system/hp-keycodes.service

Finally restart your machine to apply change.


I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via ubuntuhandbook1@gmail.com Buy me a coffee: https://ko-fi.com/ubuntuhandbook1

10 responses to Disable Automatic Airplane Mode in Ubuntu 22.04 HP Laptop

  1. Hi,
    I’ve got this :
    “Failed to enable unit: “target.graphic” is not a valid unit name.”
    any idea?

  2. This worked great for me on PopOS 22.04. I didn’t even have to reboot the computer. Thanks!

  3. https://askubuntu.com/questions/1214760/airplane-mode-gets-turned-on-and-stuck-after-sleep-mode/1463613#1463613

    I found an alternative solution that is desktop-agnostic, actually works, and can be implemented on any distro (instead of only ones that use Systemd)

  4. sudo systemctl enable hp-keycodes.service
    Synchronizing state of hp-keycodes.service with SysV service script with /lib/systemd/systemd-sysv-install.
    Executing: /lib/systemd/systemd-sysv-install enable hp-keycodes
    update-rc.d: error: hp-keycodes Default-Start contains no runlevels, aborting.

    —-info —
    HP HP 250 G5 Notebook PC

    Ubuntu 22.04.2 LTS

    HP HP 250 G5 Notebook PC

  5. Thanks for this fix. It worked for me, on an HP Notebook (15). The device went into airplane mode when I opened the lid, but not when I closed it. What a weird design. I had been banging on the power management stuff, but that did not work. This did.

  6. worked for me! HP envy laptop Ubuntu 23.04 ThX!

  7. This method solved the problem.

    When OPENING the laptop lid, the WiFi internet connection was interrupted.
    The WiFi card is blocked.
    I saw “blocked” in the output of the rfkill command in terminal.
    Laptop: HP 255 G9, ArchLinux, Xfce4, Kernel: 6.6.10-arch1-1.

    Nagy László – Hungary

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>