How to setup Wifi on minimal image with nmcli
- Operation confirmed with our ODROID-XU4 + Wifi Module 3.
Check if your Wifi module enabled
Enter the following commands.
- target
root@odroid:~# ip address 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000 link/ether 00:1e:06:31:fe:2d brd ff:ff:ff:ff:ff:ff 3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000 link/ether 00:13:ef:50:08:af brd ff:ff:ff:ff:ff:ff root@odroid:~# nmcli device DEVICE TYPE STATE CONNECTION wlan0 wifi disconnected -- eth0 ethernet unavailable -- lo loopback unmanaged --
Make sure the network interface wlan0 is available.
Scan available Wifi list
Enable the network interface.
- target
root@odroid:~# nmcli radio wifi on
And scan available Wifi list.
- target
root@odroid:~# nmcli device wifi list * SSID MODE CHAN RATE SIGNAL BARS SECURITY ... Hardkernel Lab 2.4G Infra 7 54 Mbit/s 100 **** WPA2
The result depends on your environment and the Hardkernel Lab 2.4G Wifi is going to be used in this guide.
Select a Wifi network you want to connect and proceed to next step.
Connect to the network
Connect to the Wifi network with this commands.
- target
root@odroid:~# nmcli device wifi connect "Hardkernel Lab 2.4G" password "PASSWORD_FOR_THE_WIFI" Device 'wlan0' successfully activated with '6be4a6cd-6740-4b07-b6d2-82a34df7eb07'.
All done.
Check if it works
Let's see the result of the commands we entered at the first step.
- target
root@odroid:~# ip address 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000 link/ether 00:1e:06:31:fe:2d brd ff:ff:ff:ff:ff:ff 3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:13:ef:50:08:af brd ff:ff:ff:ff:ff:ff inet 192.168.100.173/24 brd 192.168.100.255 scope global dynamic wlan0 valid_lft 7061sec preferred_lft 7061sec inet6 fe80::2b63:224f:b9f1:c87/64 scope link valid_lft forever preferred_lft forever root@odroid:~# nmcli device DEVICE TYPE STATE CONNECTION wlan0 wifi connected Hardkernel Lab 2.4G 1 eth0 ethernet unavailable -- lo loopback unmanaged --
Okay, we can see that the wlan0 device connects to Hardkernel Lab 2.4G Wifi, and this interface is assigned a IP address 192.168.100.173.
Run ping command to check whether the internet works.
- target
root@odroid:~# ping -c 10 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=39 time=55.2 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=39 time=59.9 ms 64 bytes from 8.8.8.8: icmp_seq=3 ttl=39 time=54.2 ms 64 bytes from 8.8.8.8: icmp_seq=4 ttl=39 time=54.3 ms 64 bytes from 8.8.8.8: icmp_seq=5 ttl=39 time=54.2 ms 64 bytes from 8.8.8.8: icmp_seq=6 ttl=39 time=54.0 ms 64 bytes from 8.8.8.8: icmp_seq=7 ttl=39 time=55.1 ms 64 bytes from 8.8.8.8: icmp_seq=8 ttl=39 time=56.3 ms 64 bytes from 8.8.8.8: icmp_seq=9 ttl=39 time=56.2 ms 64 bytes from 8.8.8.8: icmp_seq=10 ttl=39 time=56.9 ms --- 8.8.8.8 ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 9009ms rtt min/avg/max/mdev = 54.079/55.676/59.981/1.759 ms
This nmcli utility would let the system connects to the previous connected Wifi automatically when the system reboots.
Opt. If you can't connect via SSH to the device
If you have a problem with connecting to the assigned Wifi IP via SSH after set up these steps, maybe it is because the SSH daemon started before the wlan0 is initialized.
Try to restart the SSHD daemon.
- target
root@odroid:~# service sshd restart
Opt. How to toggle the network
You can toggle the connection by the following commands.
Disconnect current network.
- target
root@odroid:~# nmcli device DEVICE TYPE STATE CONNECTION wlan0 wifi connected Hardkernel Lab 2.4G eth0 ethernet unavailable -- lo loopback unmanaged -- root@odroid:~# nmcli device disconnect wlan0 Device 'wlan0' successfully disconnected. root@odroid:~# nmcli device DEVICE TYPE STATE CONNECTION wlan0 wifi disconnected -- eth0 ethernet unavailable -- lo loopback unmanaged --
Connect again.
When it is connected, nmcli tries to connect the previous network.
- target
root@odroid:~# nmcli device DEVICE TYPE STATE CONNECTION wlan0 wifi disconnected -- eth0 ethernet unavailable -- lo loopback unmanaged -- root@odroid:~# nmcli device connect wlan0 Device 'wlan0' successfully activated with '241a49dc-72a3-4d73-9074-1008e2dd4df9'. root@odroid:~# nmcli device DEVICE TYPE STATE CONNECTION wlan0 wifi connected Hardkernel Lab 2.4G eth0 ethernet unavailable -- lo loopback unmanaged --
Opt. How to select a network from the known networks
You can easily connect specific network you want at the network list that already had been connected before.
Deactivate current network.
- target
root@odroid:~# nmcli device DEVICE TYPE STATE CONNECTION wlan0 wifi connected Hardkernel Lab 2.4G eth0 ethernet unavailable -- lo loopback unmanaged -- root@odroid:~# nmcli connection down "Hardkernel Lab 2.4G" Connection 'Hardkernel Lab 2.4G' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/Activ) root@odroid:~# nmcli device DEVICE TYPE STATE CONNECTION wlan0 wifi disconnected -- eth0 ethernet unavailable -- lo loopback unmanaged --
See the known networks.
- target
root@odroid:~# nmcli connection NAME UUID TYPE DEVICE Hardkernel Lab 2.4G 241a49dc-72a3-4d73-9074-1008e2dd4df9 802-11-wireless -- Hardkernel Lab 2.4G 1 6be4a6cd-6740-4b07-b6d2-82a34df7eb07 802-11-wireless -- Hardkernel Lab 2.4G 2 c8a98a9c-aa58-44bd-8b96-bc3a4cab8fe9 802-11-wireless -- Hardkernel Lab 2.4G 3 ab91a8b7-fb9f-4289-acad-c11e9ab02f9c 802-11-wireless -- Hardkernel Lab 2.4G 4 bf0968ca-c295-403c-94e0-35f84400fbc7 802-11-wireless -- Wired connection 1 d1356624-11d7-35a7-aa3a-c01ba86c26fe 802-3-ethernet --
Select one and activate the network with that.
- target
root@odroid:~# nmcli connection up "Hardkernel Lab 2.4G 3" Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9) root@odroid:~# nmcli device DEVICE TYPE STATE CONNECTION wlan0 wifi connected Hardkernel Lab 2.4G 3 eth0 ethernet unavailable -- lo loopback unmanaged --