Network

How to use wpa_cli command

wpa_cli is included in the wpa_supplicant package. It can check status and change configuration, including trigger events and passphrases when connecting to wireless networks.

Using wpa_cli

wpa_cli operates in two modes: as a command-line interpreter, such as wpa_cli -i eth1 scan, or as an interactive shell, such as wpa_cli -i eth1. Commands can be abbreviated. For example, use wpa_cli -i eth1 stat instead of wpa_cli -i eth1 status to check status. The abbreviations are listed in the table below.

Full commandShort commandDescription
statusstatdisplays the current connection status
disconnectdiscprevents wpa_supplicant from connecting to any access point
quitqexits wpa_cli
terminatetermkills wpa_supplicant
reconfigurereconreloads wpa_supplicant with the configuration file supplied (-c parameter)
scanscanscans for available access points (only scans it, doesn’t display anything)
scan_displayscan_ddisplays the results of the last scan
list_networkslist_ndisplays a list of configured networks and their status (active or not, enabled or disabled)
select_networkselect_nselect a network among those defined to initiate a connection (ie select_network 0)
enable_networkenable_nmakes a configured network available for selection (ie enable_network 0)
disable_networkdisable_nmakes a configured network unavailable for selection (ie disable_network 0)
remove_networkremove_nremoves a network and its configuration from the list (ie remove_network 0)
add_networkadd_nadds a new network to the list. Its id will be created automatically
set_networkset_nshows a very short list of available options to configure a network when supplied with no parameters.See next section for a list of extremely useful parameters to be used with set_network and get_network.
get_networkget_ndisplays the required parameter for the specified network. See next section for a list of parameters
save_configsave_csaves the configuration

Using wpa_cli with set_network is shown in the following example.

set_network <network id> <key> <parameter> [<parameter>] 

Using wpa_cli with get_network is shown in the following example.

get_network <network id> <key> 

The key parameters for set_network and get_network are detailed in the table below.

KeyDescriptionParameters
ssidAccess point namestring
id_strString identifying the networkstring
priorityConnection priority over other APsnumber (0 being the default low priority)
bssidMac address of the access pointmac address
scan_ssidEnable/disbale ssid scan0, 1, 2
key_mgmtType of key managementWPA-PSK, WPA_EAP, None
pairwisePairwise ciphers for WPACCMP, TKIP
group=TKIPGroup ciphers for WPACCMP, TKIP, WEP104, WEP40
pskPre-Shared Key (clear or encrypted)string
wep_key0WEP key (up to 4: wep_key[0123])string
eapExtensible Authentication ProtocolMD5, MSCHAPV2, OTP, GTC, TLS, PEAP, TTLS
identityEAP identity stringstring
passwordEAP passwordstring
ca_certPathname to CA certificate file/full/path/to/certificate
client_certPathname to client certificate/full/path/to/certificate (PEM/DER)
private_keyPathname to a client private key file/full/path/to/private_key (PEM/DER/PFX)

Example of using set_network from the command line:

set_network 0 ssid "my access point"
set_network 0 id_str Home_Network
set_network 0 bssid 00:0d:0b:64:00:6c
set_network 0 scan_ssid 0
set_network 0 key_mgmt WPA-PSK
set_network 0 pairwise CCMP TKIP
set_network 0 group CCMP TKIP
set_network 0 psk "makemeveryverysecret"
set_network 0 EAP TLS
set_network 0 "[email protected]"
set_network 0 ca_cert "/etc/cert/ca.pem"
set_network 0 client_cert "/etc/cert/user.pem"
set_network 0 private_key "/etc/cert/user.prv"

Example of setting set_network keys in wpa_supplicant.conf:

network={
    ssid="my access point"
    id_str="Home_Network"
    bssid=00:0d:0b:64:00:6c
    scan_ssid=0
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk=c2277f7dd8cb0000fe000000b76cfda7102ed7eefbd29ad0000000000f5e349a
}

Thanks to Red Hat for the information.

EOF.← Back to articles