Using WPA_Supplicant to Connect to WPA2 Wi-fi from Terminal on Ubuntu 16.04 Server

In this tutorial, we are going to learn how to connect to Wi-fi network from the command line on Ubuntu 16.04 server and desktop using wpa_supplicant.

In a modern home wireless network, communications are protected with WPA-PSK (pre-shared key) as opposed to WPA-Enterprise, which is designed for enterprise networks. WPA-PSK is also known as WPA-Personal. wpa_supplicant is an implementation of the WPA supplicant component. A supplicant in wireless LAN is a client software installed on end-user’s computer that needs to be authenticated in order to join a network.

Now let’s see how to connect to WPA2 wireless network using wpa_supplicant.

Step 1: Enable wireless interface

First, make sure your wireless card is enabled. You can use rfkill.

sudo apt install rfkill

To check the status of wireless card, run

rfkill list

Sample output:

ubuntu connect to wireless network command line

As you can see, my wireless card is blocked by software. To unblock it, use the following command:

rfkill unblock wifi

If you are using the desktop version of Ubuntu, then you also need to stop Network Manager with the following command, otherwise it will cause connection problem when using wpa_supplicant.

sudo systemctl stop NetworkManager

You also need to disable NeworkManager start at boot time by executing the following command.

sudo systemctl disable NetworkManager

Step 2: Find your wireless interface name and wireless network name

Run iwconfig to find the name of your wireless interface.

iwconfig

wlan0 is a common name, but my wireless interface is called wlp3s0. You can also see that it’s not associated with any access point right now.

connect to wifi terminal ubuntu

If your wireless interface isn’t shown, perhaps you need to bring it up with the following command.

sudo ifconfig wlp3s0 up

Then find your wireless network name by scanning nearby networks with the command below. Replace wlp3s0 with your own interface name. ESSID means network name.

sudo iwlist wlp3s0 scan | grep ESSID

ubuntu 16.04 connect to wifi command line

Step 3: Connect to Wi-fi network using wpa_supplicant

Now install wpa_supplicant on Ubuntu 16.04.

sudo apt install wpasupplicant

We need to create a file named wpa_supplicant.conf using the wpa_passphrase utility. wpa_supplicant.conf is the configuration file describing all networks that the user wants the computer to connect to. Run the following command to create this file. Replace ESSID and Wi-fi passphrase with your own.

wpa_passphrase your-ESSID your-passphrase | sudo tee /etc/wpa_supplicant.conf

wpa_passphrase

Note that in the above screenshot, I wrapped my ESSID with double-quotes, because my ESSID contains a whitespace.

The output will be piped to tee which then write to /etc/wpa_supplicant.conf file. Now use the following command to connect your wireless card to wireless access point.

sudo wpa_supplicant -c /etc/wpa_supplicant.conf -i wlp3s0

By default, wpa_supplicant runs in the foreground. If the connection is completed, then open up another terminal window and run

iwconfig

You can see that the wireless interface is now associated with an access point.

how to enable wifi in ubuntu using terminal

You can press CTRL+C to stop the current wpa_supplicant process and run it in the background by adding -B option.

sudo wpa_supplicant -B -c /etc/wpa_supplicant.conf -i wlp3s0

Although we’re authenticated and connected to wireless network, but we don’t have an IP address yet. To obtain a private IP address from DHCP server, use the following command:

sudo dhclient wlp3s0

Now your wireless interface has a private IP address, which can be shown with:

ifconfig wlp3s0

connect to wifi terminal ubuntu 16.04

Now you can access the Internet. To release the private IP address, run

sudo dhclient wlp3s0 -r

Connecting to Hidden Wireless Network

If your wireless doesn’t broadcast SSID, then you need to add the following line in /etc/wpa_supplicant.conf file.

scan_ssid=1

Like below:

network={
        ssid="LinuxBabe.Com office network"
        #psk="12345qwert"
        psk=68add4c5fee7dc3d0dac810f89b805d6d147c01e281f07f475a3e0195
        scan_ssid=1
}

Auto Connect on Startup

To automatically connect to wireless network at boot time, we need to edit the wpa_supplicant.service file. It’s a good idea to copy the file from /lib/systemd/system/ directory to /etc/systemd/system/ directory, then edit it because we don’t want newer version of wpasupplicant to override our modifications.

sudo cp /lib/systemd/system/wpa_supplicant.service /etc/systemd/system/wpa_supplicant.service

sudo nano /etc/systemd/system/wpa_supplicant.service

Find the following line.

ExecStart=/sbin/wpa_supplicant -u -s -O /run/wpa_supplicant

Change it to the following. Obviously you need to change wlp3s0 if that isn’t your interface name.

ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant.conf -i wlp3s0

If you can find the following line in this file, comment it out (Add the # character at the beginning of the line).

Alias=dbus-fi.w1.wpa_supplicant1.service

Save and close the file. Then enable wpa_supplicant service to start at boot time.

sudo systemctl enable wpa_supplicant.service

We also need to start dhclient at boot time to obtain a private IP address from DHCP server. This can be achieved by creating a systemd service unit for dhclient.

sudo nano /etc/systemd/system/dhclient.service

Put the following text into the file.

[Unit]
Description= DHCP Client
Before=network.target

[Service]
Type=simple
ExecStart=/sbin/dhclient wlp3s0 -v
ExecStop=/sbin/dhclient wlp3s0 -r

[Install] 
WantedBy=multi-user.target

Save and close the file. Then enable this service.

sudo systemctl enable dhclient.service

How to Obtain a Static IP Address

Edit the dhclient configuration file.

sudo nano /etc/dhcp/dhclient.conf

Add the following line in the file. Replace the IP address with your preferred IP address. This makes dhclient request a static IP address from router.

interface "wlp3s0" {
     send dhcp-requested-address 192.168.0.122;
}

Save and close the file. Then restart dhclient service.

sudo systemctl restart dhclient

I found that this only works for the first time, or when the Ubuntu system boots up. Perhaps it’s because of my router setup. If you run the /sbin/dhclient wlp4s0 command multiple times (via the dhclient service), the router might refuse dhclient’s request. Also note that iOS’s hotspot doesn’t support client requesting a particular IP address.

The better way to make sure your Ubuntu system have a static IP address is probably by logging into your router’s management interface and assigning a static IP to the MAC address of your wireless card, if your router supports this feature.

Using a Hostname to Access Services on Ubuntu

Actually, you don’t have to obtain a static IP address for your Ubuntu box. Ubuntu can use mDNS (Multicast DNS) to announce its hostname to the local network and clients can access services on your Ubuntu box with that hostname. This hostname can always be resolved to the IP address of your Ubuntu box, even if the IP address changes.

In order to use mDNS, you need to install avahi-daemon, which is an open-source implementation of mDNS/DNS-SD.

sudo apt install avahi-daemon

Start the service.

sudo systemctl start avahi-daemon

Enable auto-start at boot time.

sudo systemctl enable avahi-daemon

Avahi-daemon listens on UDP 5353, so you need to open this port in the firewall. If you use UFW, then run the following command.

sudo ufw allow 5353/udp

Then you should set a unique hostname for your Ubuntu box with the hostnamectl command. Replace ubuntubox with your preferred hostname, which should not be already taken by other devices in the local network.

sudo hostnamectl set-hostname ubuntubox

Now restart avahi-daemon.

sudo systemctl restart avahi-daemon

If you check the status with

systemctl status avahi-daemon

you can see the mDNS hostname, which ends with the .local domain.

avahi-daemon mdns hostname

On the client computer, you also need to install an mDNS/DNS-SD software.

  • Linux users should install avahi-daemon.
  • Windows users need to enable the Bonjour service by either installing the Bonjour print service or installing iTunes.
  • On macOS, Bonjour is pre-installed.

Now you can access services by using the ubuntubox.local hostname, eliminating the need to check and type IP address.

Wrapping Up

I hope this tutorial helped you set up Ubuntu server 16.04 wifi from the command line. As always, if you found this post useful, then subscribe to our free newsletter. You can also follow us on Google+Twitter or like our Facebook page.

Rate this tutorial
[Total: 112 Average: 4.3]

39 Responses to “Using WPA_Supplicant to Connect to WPA2 Wi-fi from Terminal on Ubuntu 16.04 Server

  • user1397
    2 years ago

    You got me through a tough situation, thank you good sir!

  • This is such a detailed tutorial. Thanks very much!
    I’m curious about having an additional wifi adapter via USB and have it setup as an AP which bridges the connection to wlan0 which is connected to the internet.
    Does Ubuntu support bridging e.g. wlan0 and wlan1?
    I’ve been trying to get this to work on Xenial server but to not avail.
    Thanks in advance

  • Worked like a charm!!! Even giving me chills at the very beginning when you asks for someone seeking for internet connection to apt-get something (dam!) didn’t gave it up and jumped to Step 2! It took a while to understand the steps but finally I got it working.
    Would like to add that you need to initialize wireless interface once on Step 2 using:
    $ sudo ip link set wls3s0 up
    I’m bringing back to life an old Atom Acer netbook with Ubuntu server 16.04 (32bits) and was just mad why daheck have it discovered my wireless hardware beautifully on install process (I did insert SSID, passphrase, etc) and after first boot it was just gone!!!

    Well, I own you a few hours. So, thx =D

  • Doesn’t work on Ubuntu 18.04

  • Lyon Qiu
    2 years ago

    Great article! Works like a charm! Thank you!

  • Antonio
    1 year ago

    Thank you very much for the detailed tutorial. I am sorry that it did not seem to work for me. After rebooting, there is still no connection. Where might the issues be? Thanks again 🙂

  • Schibes
    1 year ago

    Nice guide for the most part, Steps 1 thru 3 working good and I can connect to Wi-Fi, but Auto Connect on Startup is not working. I checked journalctl and wpa_supplicant is spamming a whole bunch of “no such device” errors in there, but when I up-arrow thru my command history line by line and manually restart the supplicant it works fine. Will check out some other guides and post back here if I figure it out, thanks

  • Very useful guide. Thank you

  • Ulisse
    1 year ago

    It works also for Ubuntu Server 18.10 so thank you very much for this useful and clear guide!

  • An awesome article which expresses how to use wpa_supplicant to connect wifi manually!

  • Just amazing tutorial. I spended all the day learning wpa_supplicant, and finally I found this manual that mathes everything in a easy to understand way. Thank you so much!!!

  • I gott a problem in Debian 10 with boot during too much time cause by “dependency problem”, then I diabled the [email protected] service, don’t know why, but it solved all.

  • Thanks a lot.. This saved me from a day’s frustration.

  • topquant
    9 months ago

    Tried this on Ubuntu 16.04. Stumped on the following:

    sudo wpa_supplicant -c /etc/wpa_supplicant -i wlan0
    Successfully initialized wpa_supplicant
    Could not read interface p2p-dev-wlan0 flags: No such device

    My network card supports p2p. Any help would be greatly appreciated.

    • Are you sure wlan0 is he device name?

      whats the output of iwconfig ?

  • after running

    sudo systemctl enable wpa_supplicant.service

    i get the following

    Failed to enable unit: File /etc/systemd/system/dbus-fi.w1.wpa_supplicant1.service already exists and is a symlink to /lib/systemd/system/wpa_supplicant.service.

  • Thank you Linuxbabe, where ever you are! You gave me the needed configuration file locations, iwconfig and wpa_supplicant commands to start the wireless interface, wlp6s0, on Ubuntu 17.04.

    For others, I put this together to bring up wlp6s0. Your mileage will undoubtedly vary.

    $ sudo /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlp6s0.pid -i wlp6s0 -D nl80211,wext -c /etc/wpa_supplicant.conf -C /run/wpa_supplicant
  • This is a great resource. Detailed explanation with focus on what is being done and why. Helped a lot. Thanks.

  • Reading this post solved my problem in setting up Raspberry pi with ubuntu server. Thanks a lot!

  • Walter Galan
    7 months ago

    Thanks for the tutorial. Extremely helpful!

  • Ajay Mani
    7 months ago

    Thanks a lot! Very detailed and accurate. Helped me to get a head start on server.

  • sudo systemctl enable wpa_supplicant.service
    cuando hago este paso me salta esto
    failed to enable unit: file /etc/systemd/system/dbus-fi.w1.wpa_supplicant1.service already exists and is a symlink to /lib/systemd/system/wpa_supplicant.service.

    • Comment out the following line in /etc/systemd/system/wpa_supplicant.service file.

      Alias=dbus-fi.w1.wpa_supplicant1.service

      Reload systemd.

      sudo systemctl daemon-reload

      Then enable wpa_supplicant.

      sudo systemctl enable wpa_supplicant.service
  • muchas gracias por la ayuda! quiero saber en el caso de ir a otro lado en mi Universidad tiene wifi pero no es claramente el mismo de mi casa como hago para conectarme los mismo paso? porque cuando quiero conectarme me sale el de mi casa

  • I also had to make sure than my interface was up:

    sudo ifconfig wlan0 up
  • Thanks so much. This was amazing. I also had to make sure to use the ‘sudo ifconfig wlan0 up’ command to enable my device.

  • Good and helpful info. Please could you update our with more current command line examples esp for a current OS like Debian 10 (Buster) that has fully switched to using iw instead of iwconfig and also include the fact that following these instructions could possibly break a working wifi connection that uses NetworkManager package to manage their wifi and connect. Thanks.

    • I have said in this article that if your system is running NetworkManager, then you need to stop and disable it.

      sudo systemctl stop NetworkManager
      sudo systemctl disable NetworkManager

      I might write a tutorial for Debian.

  • A+ article, other than the fact that you tell people to install software without an internet connection, right at the top of the article.
    However, the systemctl service setups helped get my wpa supplicant running. (using the ip link / ip addr commands)

  • Lost_Penguin
    1 month ago

    Hello! Has anybody had success using this with ubuntu 18.04.4 LTS?

  • Great! Everything went well except for the dhclient running on startup, it wasnt working I dont know why. When I looked at systemctl status dhclient it showed the service started correctly and then it stops itself.

    What I did was removing the ExecStop from the service and then it started working correctly at startup, not sure why

    Anyway, Thank you!

    • I had the same issue (Ubuntu 19.10) and your fix worked (I commented the line out). Thanks!

  • kuldeep
    1 month ago

    not able to connect to wifi with wpa_supplicant. i follow all the instruction what you said in the article.
    first i used.

    wpa_passphrase "my ssid "my password" | sudo tee /etc/wpa_supplicant.conf

    after that i used

    sudo wpa_supplicant -c /etc/wpa_supplicant.conf -i wlxc83a35c4a90

    and i got the following error.
    i am new on wpa_supplicant so not able to understand the error properly.
    Successfully initialized wpa_supplicant
    wlxc83a35c4a906: SME: Trying to authenticate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Trying to associate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Associated with 48:f8:b3:5d:e6:b4
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: SME: Trying to authenticate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Trying to associate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Associated with 48:f8:b3:5d:e6:b4
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: SME: Trying to authenticate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Trying to associate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Associated with 48:f8:b3:5d:e6:b4
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: SME: Trying to authenticate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Trying to associate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Associated with 48:f8:b3:5d:e6:b4
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid=”SenseGrow_Testing” auth_failures=1 duration=10 reason=CONN_FAILED
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-SSID-REENABLED id=0 ssid=”SenseGrow_Testing”
    wlxc83a35c4a906: SME: Trying to authenticate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Trying to associate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Associated with 48:f8:b3:5d:e6:b4
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid=”SenseGrow_Testing” auth_failures=2 duration=23 reason=CONN_FAILED
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-SSID-REENABLED id=0 ssid=”SenseGrow_Testing”
    wlxc83a35c4a906: Associated with 48:f8:b3:5d:e6:b4
    wlxc83a35c4a906: WPA: Invalid EAPOL-Key MIC when using TPTK – ignoring TPTK
    wlxc83a35c4a906: WPA: Could not verify EAPOL-Key MIC – dropping packet
    wlxc83a35c4a906: Authentication with 48:f8:b3:5d:e6:b4 timed out.
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: WPA: 4-Way Handshake failed – pre-shared key may be incorrect
    wlxc83a35c4a906: CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid=”SenseGrow_Testing” auth_failures=3 duration=46 reason=WRONG_KEY
    wlxc83a35c4a906: CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid=”SenseGrow_Testing” auth_failures=4 duration=77 reason=CONN_FAILED
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-SCAN-FAILED ret=-16 retry=1
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-SSID-REENABLED id=0 ssid=”SenseGrow_Testing”
    wlxc83a35c4a906: SME: Trying to authenticate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Trying to associate with 48:f8:b3:5d:e6:b4 (SSID=’SenseGrow_Testing’ freq=2462 MHz)
    wlxc83a35c4a906: Associated with 48:f8:b3:5d:e6:b4
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid=”SenseGrow_Testing” auth_failures=5 duration=75 reason=CONN_FAILED
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    wlxc83a35c4a906: CTRL-EVENT-DISCONNECTED bssid=48:f8:b3:5d:e6:b4 reason=3 locally_generated=1
    wlxc83a35c4a906: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
    ^Cnl80211: deinit ifname=wlxc83a35c4a906 disabled_11b_rates=0
    wlxc83a35c4a906: CTRL-EVENT-TERMINATING

    any help will be greatly appreciated.

    • It’s not clear what went wrong from the log messages. Maybe your password is wrong. (You don’t need to wrap the password in double quotes.)

      • kuldeep
        1 month ago

        i did the same what you said,
        but not able to connect again if you need something you can ask.

    • I don’t have anything to ask. Either your ESSID or password is wrong. Or you have some special characters in your password that are interpreted as a meta characters by the Bash shell.

  • Michael
    4 weeks ago

    Seems like there might be an issue with the dhclient.service text file that you recommend using? When using it as typed, I get the following error:

    [email protected]:/home/user# systemctl enable dhclient.service
    Failed to enable unit: File dhclient.service: Bad message
    

    I fixed this by moving the [Install] block to a new line, and moving the parameter to another newline, like below, which seemed to do the trick.

    #Unit and Service blocks
    [Install] 
    WantedBy=multi-user.target
    

    Anybody else find this issue? I’m on Ubuntu Server 18.04 myself, hopefully this might be of use to some people!

  • hacker
    1 week ago

    For the dhclient.serviced unit file, if we use the systemd ‘Type=simple’ we need to also use the dhclient ‘-d’ option to keep the dhclient process in the foreground.

    Without the ‘-d’ option the dhclient process will return after it starts it’s background process and systemd will thenexecute the unit file’s ExecStop command.

    -ExecStart=/sbin/dhclient wlp6s0 -v
    +ExecStart=/sbin/dhclient wlp6s0 -d

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.