Are you tired of manually connecting to Wi-Fi every time after a reboot? Ubuntu? Or is your laptop losing connection when waking up from sleep? The problem is automatic connection to Wi-Fi — one of the most common problems among Linux users, especially after system updates or changing network adapters. In this article, we'll look at All current methods for setting up Wi-Fi autostart in Ubuntu 22.04/24.04, including hidden settings NetworkManager, system services systemd and even manual scripts for complex cases.
It's important to understand that the causes of the problem can vary, from trivial settings in the graphical interface to deep driver conflicts. We won't limit ourselves to standard advice like "check the box in the settings"—instead, you'll get detailed instructions with explanations, why this or that method works (or doesn't) in your case. And if you're a network administrator, you'll also find solutions for corporate environments here. 802.1X authentication.
Before you begin, check two things:
- 🔹 Your Wi-Fi adapter is detected by the system (command
lspci | grep -i networkorlsusbfor USB adapters). - 🔹 Network Manager is active:
systemctl status NetworkManagermust showactive (running).
1. Standard method: configuration via NetworkManager GUI
Let's start with the simplest thing - the graphical interface NetworkManagerThis method is suitable for 90% of home users and works on all modern versions. Ubuntu (including GNOME- And KDE-environment).
Open the network menu in the upper right corner of the screen (the Wi-Fi icon) and select your network. But instead of connecting normally:
- Click the gear icon ⚙️ next to the network name (or "Network Settings" → "Wi-Fi").
- In the window that opens, go to the tab "General".
- Check the box
Connect automatically(in the English version -Connect Automatically). - Save changes and reboot to test.
If the checkbox was already checked, but auto-connection does not work, the reasons may be as follows:
- 🔌 Conflict with other network managers (eg.
wpa_supplicantstarted manually). - 🔄 The network is saved with incorrect security settings (for example, the password has changed, but the system is trying to connect with the old data).
- ⚡ The Wi-Fi adapter driver does not support power saving (especially relevant for adapters Realtek).
Make sure the network is saved in NetworkManager|Check for any conflicting network services|Update your Wi-Fi adapter driver|Disable any VPN/proxy that may be blocking the connection
-->
To diagnose, run the command:
nmcli connection show
Find your network in the list and check the parameter autoconnect - he must be yesIf not, enable it:
nmcli connection modify "Network_name" connection.autoconnect yes
sudo sed -i 's/wifi.powersave = 3/wifi.powersave = 2/' /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
Then restart NetworkManager: sudo systemctl restart NetworkManager-->
2. Configuration via NetworkManager configuration files
If the GUI doesn't help, it's time to dig into the configuration files. NetworkManager stores connection settings in /etc/NetworkManager/system-connections/Each network is a separate file with the extension .nmconnection.
Open your network file (you will need permissions) sudo):
sudo nano /etc/NetworkManager/system-connections/"Network_name.nmconnection"
Find a section [connection] and make sure it contains the line:
autoconnect=true
If it's not there, add it. Also check the section [wifi] for the presence of a parameter:
hidden=false
(This parameter is important if your network is hidden, i.e. does not broadcast SSID.)
After changes, reboot NetworkManager:
sudo systemctl restart NetworkManager
What to do if the network file is missing from /etc/NetworkManager/system-connections/?
This means the network isn't saved in the system settings. First, connect to it manually through the graphical interface, then check if the file appears. If the file still doesn't appear, export the connection manually:
nmcli connection export "NetworkName" > /etc/NetworkManager/system-connections/NetworkName.nmconnection
Please pay attention to the file permissions:
sudo chmod 600 /etc/NetworkManager/system-connections/"Network_name.nmconnection"
If the rights are too open (for example, 644), NetworkManager will ignore the file for security reasons.
⚠️ Attention: If you use VPN or proxy, which require authentication at system startup, automatic Wi-Fi connection may be blocked until the password is entered. In this case, consider setting up automatic password entry viagnome-keyringor delayed connection viasystemd.
3. Autostart via systemd: for advanced users
If NetworkManager stubbornly ignores your settings, you can force the system to connect to Wi-Fi via systemd — standard service manager in UbuntuThis method is reliable, but requires an understanding of how the services work.
Create a new service file:
sudo nano /etc/systemd/system/wifi-autoconnect.service
Add the following content (replace Network_name And Interface_name on your own):
[Unit]Description=Automatically connect to Wi-Fi on boot
After=network.target NetworkManager.service
Requires=NetworkManager.service
[Service]
Type=oneshot
ExecStart=/usr/bin/nmcli connection up "Network_Name" ifname "Interface_Name"
TimeoutSec=30
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
To find out the name of your Wi-Fi interface, run:
ip a
Usually it's something like wlp3s0 or wlan0.
Now activate and start the service:
sudo systemctl daemon-reloadsudo systemctl enable wifi-autoconnect.service
sudo systemctl start wifi-autoconnect.service
Check the status:
sudo systemctl status wifi-autoconnect.service
If you see an error in the status Activation of network connection failed, the reasons may be the following:
| Error | Possible cause | Solution |
|---|---|---|
Device not found |
Invalid interface name (ifname) |
Check the interface name with the command ip a |
Secrets were required |
Network password not saved in nmcli |
Remove and re-add the network via nmcli |
Connection activation failed |
The network is unavailable or the signal is too weak | Check your Wi-Fi coverage and router settings |
Permission denied |
The service starts before initialization NetworkManager |
Add After=dbus.service to the section [Unit] |
4. Auto-connection via crontab: an alternative approach
If systemd seems too complicated, you can use crontab — the Linux task scheduler. This method is simpler, but less reliable, as it depends on the system boot time.
Open crontab for editing:
crontab -e
Add line (replace Network_name):
@reboot sleep 30 && nmcli connection up "Network_Name"
Here sleep 30 — a 30-second delay that gives the system time to initialize the network. If your computer boots quickly, you can reduce the value to 10 or 15.
The advantages of this method:
- 🔧 No rights required
sudo(works under the user). - 🔄 Easy to edit and debug (logs can be viewed in
/var/log/syslog). - 🛠️ Suitable for temporary solutions or testing.
Flaws:
- ⏱️ Delay
sleepmay be too big or too small for your system. - 🔄 If NetworkManager has not yet been run, the command will fail with an error.
- 📡 Will not work if the network requires interaction (such as accepting terms of use).
⚠️ Attention: If you use Wayland instead of X11, some graphics applications (eg,nm-applet) may not have access toDBusin the early moments of loading. In this case,nmclithroughcrontabmay not work - usesystemd.
5. Auto-connection script with error handling
For the most complex cases (for example, corporate networks with 802.1X, hidden SSID, or unstable adapters) you can write a script on bash, which will be:
- Check network availability.
- Reconnect when disconnected.
- Log errors.
Create a script file:
nano ~/wifi_autoconnect.sh
Add the following code (remember to make the file executable): chmod +x ~/wifi_autoconnect.sh):
#!/bin/bashNETWORK_NAME="Your_Network"
INTERFACE="wlp3s0" # Replace with your interface
LOG_FILE="/var/log/wifi_autoconnect.log"
MAX_RETRIES=5
RETRY_DELAY=10
Logging function
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
Checking if we are connected
is_connected() {
ping -c 1 8.8.8.8 &> /dev/null
return $?
}
Main loop
for ((i=1; i<=$MAX_RETRIES; i++)); do
if is_connected; then
log "Already connected to the network. Exit."
exit 0
fi
log "Attempt $i: Connecting to $NETWORK_NAME..."
nmcli connection up "$NETWORK_NAME" ifname "$INTERFACE" &> /tmp/nmcli_output
if [ $? -eq 0 ]; then
log "Successfully connected to $NETWORK_NAME"
exit 0
else
log "Connection error: $(cat /tmp/nmcli_output)"
sleep $RETRY_DELAY
fi
done
log "Failed to connect after $MAX_RETRIES attempts. Check your network settings."
exit 1
Now add the script to startup via crontab:
@reboot /bin/bash /home/your_user/wifi_autoconnect.sh
Script logs will be saved in /var/log/wifi_autoconnect.logThis will help diagnose problems if auto-connection doesn't work.
For corporate networks with 802.1X Add certificate checking to the script. For example:
# Certificate verification (example for EAP-TLS)if [! -f "/etc/ssl/certs/your_certificate.crt" ]; then
log "Missing certificate. Connection impossible."
exit 1
fi
6. Diagnosing and solving common problems
If none of these methods work, it's time for diagnostics. Here's a list of the most common problems and their solutions:
| Symptom | Possible cause | Solution |
|---|---|---|
| Wi-Fi connects, but there is no internet | Not received IP address or DNS | Check it out nmcli dev show for availability IP4.DNS[1]If necessary, specify DNS manually: nmcli connection modify "Network_Name" ipv4.dns "8.8.8.8,8.8.4.4" |
| Auto-connection works, but only after logging in. | NetworkManager starts too late |
Check the loading order of services: systemctl list-dependencies NetworkManager.service |
| The network is saved but does not connect automatically. | Conflict with wpa_supplicant or other managers |
Disable conflicting services: sudo systemctl disable wpa_supplicant |
| Wi-Fi disconnects after sleep/hibernation | Driver or power saving issues | Disable power saving: sudo iw dev wlp3s0 set power_save off (replace wlp3s0 to your interface) |
| The network requires re-authentication after reboot. | Authentication Server (RADIUS) resets the session | Set up automatic login/password entry via expect or gnome-keyring |
If your problem is not included in the table, run the diagnostic commands and attach the output to a question on the forums (e.g. Ask Ubuntu or Linux Mint):
nmcli general statusnmcli device status
dmesg | grep -i wifi
journalctl -u NetworkManager --no-pager -n 50
⚠️ Attention: On some laptops (especially with adapters) Intel AX200/AX210) Auto-connection may break after a kernel update. In this case, try rolling back to the previous kernel version via GRUB or install proprietary drivers from the manufacturer.
7. Autostart Wi-Fi in Ubuntu server versions (without GUI)
If you use Ubuntu Server or a minimal installation without a graphical interface, setting up auto-connection has its own nuances. There are no nm-applet, so everything is configured through nmcli or netplan.
First check if it is installed NetworkManager:
sudo apt install network-manager
Then set up the connection:
sudo nmcli dev wifi connect "NetworkName" password "YourPassword"
Enable auto-connection:
sudo nmcli connection modify "Network_name" connection.autoconnect yes
If you use netplan (standard for Ubuntu Server 20.04+), edit the file /etc/netplan/00-installer-config.yaml:
network:version: 2
renderer: NetworkManager
wifis:
wlp3s0: # Replace with your interface
dhcp4: true
access-points:
"Network_name":
password: "your_password"
Apply changes:
sudo netplan apply
For server versions it is especially important:
- 🔐 Store passwords encrypted (use
wpa-pskinstead of plain text). - 🔄 Set up backup connections (for example, via
eth0, if Wi-Fi is not available). - 📡 Monitor network status via
cronorsystemd-timers.
FAQ: Frequently asked questions about autostarting Wi-Fi in Ubuntu
Why does Wi-Fi only connect after manually entering the password, even though it is saved?
This is a typical problem with gnome-keyring — password storage. Keys are not unlocked automatically upon system boot. Solutions:
- Set an empty password for the default key:
seahorse→ Edit → Change password. - Use
pamfor automatic unlocking:sudo pam-auth-update→ enable "Login with password". - Save the password in plain text (not secure!):
nmcli connection modify "Network_Name" wifi-sec.key-mgmt wpa-psk wifi-sec.psk "your_password".
How to auto-connect to a hidden Wi-Fi network?
For hidden networks (hidden SSID) V nmcli use the flag hidden yes:
nmcli connection add type wifi con-name "Network_Name" ifname wlp3s0 ssid "Network_Name" wifi-sec.key-mgmt wpa-psk wifi-sec.psk "password" connection.autoconnect yes 802-11-wireless.hidden yes
Or edit the connection file in /etc/NetworkManager/system-connections/, adding the line:
hidden=true
Auto-connection works, but there's no internet. What should I do?
The problem is most often related to DNS or gateway. Check:
- Received? IP address:
ip a show wlp3s0. - Is the gateway accessible:
ping $(ip r | grep default | awk '{print $3}'). - Do they work? DNS:
nslookup google.com.
If ping it goes to the gateway, but DNS doesn't work, please specify manually DNS:
nmcli connection modify "Network_Name" ipv4.dns "8.8.8.8,1.1.1.1"
How to debug auto-connection issues?
Enable verbose logging NetworkManager:
- Edit
/etc/NetworkManager/NetworkManager.conf: - Restart the service:
sudo systemctl restart NetworkManager. - View logs:
journalctl -u NetworkManager -f.
[logging]level=DEBUG
domains=ALL
Look for lines with error or warn, especially the mentions supplicant, dhcp, or authentication.
Is it possible to set up automatic connection to multiple networks with priority?
Yes, NetworkManager Supports connection prioritization. To prioritize networks:
- Check your current priorities:
nmcli connection show(columnPRIORITY). - Change the priority (the higher the number, the higher the priority):
nmcli connection modify "Network_name1" connection.autoconnect-priority 10
nmcli connection modify "Network_name2" connection.autoconnect-priority 5
The system will try to connect to the highest priority network, and if it is unavailable, it will move on to the next one.