I am trying to switch Wi-Fi network via the command line:

networksetup -setairportnetwork en0 corpnet01
networksetup -setairportnetwork en0 Home

where "Office" and "Home" are DHCP enabled networks. When I switch from corpnet01 to Home, everything works fine. But the other way it doesn't.

When I do it via the UI all works OK:

enter image description here

but when I do it in the terminal, DHCP does not manage to get an IP address:

enter image description here

and networksetup says:

UM00160:~ taapega4$ networksetup -getinfo Wi-Fi
DHCP Configuration
IP address:
Subnet mask:
Router: (null)
Client ID:
IPv6: Automatic
IPv6 IP address: none
IPv6 Router: none
Wi-Fi ID: 8c:85:90:4f:41:77

What else is the UI doing that I am not doing by using the following command?

networksetup -setairportnetwork en0 corpnet01

I know that we require a certificate installed in the keychain to connect to corpnet01.

  • Does this type of network have a name, such as something that describes its class or a descriptor separating it from regular networks? I’m trying to research this exact situation for another person, and you both might know different bits of information that I would like to use to help you both, if I can. – CJK Apr 17 at 14:43
  • Out of curiosity...why are you specifying the SSID to connect to? If "Home" and "corpnet01" are preferred Wi-Fi networks and are not adjacent to each other (I assume you don't live at corporate), you only need to power cycle the Wi-Fi adapter. See this answer. It will authenticate automatically. – Allan Apr 17 at 17:19

If you look at the usage for -setairportnetwork it implies that you have to include the password as an argument as well:

$ networksetup | grep setairportnetwork
Usage: networksetup -setairportnetwork <device name> <network> [password]

WiFi passwords are typically stored in Keychain so it's likely the case that the networking widget is pulling the password from Keychain and passing it as part of this operation behind the scenes.


Here I've looked in Keychain prior to get a rough idea of the item I'm attempting to retrieve via the CLI.


So we're looking for an item that contains "802.1X Password" for the "Kind". So we can use the security CLI tool to retrieve this like so:

$ security find-generic-password -D "802.1X Password" -g
keychain: "/Users/joeuser/Library/Keychains/login.keychain-db"
version: 512
class: "genp"
    0x00000007 <blob>="SomeSSID Secure"
    0x00000008 <blob>=<NULL>
    "cdat"<timedate>=0x32303139303330343132323630355A00  "20190304122605Z\000"
    "desc"<blob>="802.1X Password"
    "mdat"<timedate>=0x32303139303330343132323630355A00  "20190304122605Z\000"
    "svce"<blob>="com.apple.network.eap.user.item.wlan.ssid.SomeSSID Secure"
password: "securitypasswordssid123"

NOTE: When you run this command, you'll still be prompted for passwords to allow security CLI to access the Keychain. You can either do this 1 time, or allow it indefinitely.

The dialog will look like this:



You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .