I'm looking for a way to disconnect from my current WIFI network via CLI. There is a way to do that, but it's a GUI way.

Any ideas how to accomplish that?


a busy cat

Note: I don't want to disable Wi-Fi because I need Airdrop to be function so I just want to disconnect it from the existing network.

EDIT: Why do I want this?

At work we connect out MBPs to Displays w/ ethernet attached. Also we heavily use AirDrop functionality. The aim is to write a script, that automatically disconnects from WIFI networks, when ethernet cable is plugged in, so that we can still use other WIFI features like AirDrop & Apple Watch unlocking.


2 Answers 2


Use networksetup.

There are several ways to disconnect from a Wi-Fi network via Terminal:

  • Disable the Wi-Fi service. This will require root privileges. The radio will remain on, but it won't connect to anything.

    sudo networksetup -setnetworkserviceenabled Wi-Fi off

  • Turn off the airport power (this is like clicking the (GUI) Wi-Fi icon and selecting "turn off Wi-Fi". You don't need sudo and you should know which interface (en0, en1, etc.) is your Airport adapter. If you don't try the service and macOS will attempt to guess which one it is.

    networksetup -setairportpower Wi-Fi off

In the specific case where you don't want auto-join, just set the network to not auto-join and then toggle the network status using networksetup.

If you just want to disconnect from a WiFi network, disable the adapter:

sudo networksetup -setnetworkserviceenabled Wi-Fi off && sleep 15 && sudo networksetup -setnetworkserviceenabled Wi-Fi on

(You can issue the command without sudo but you will get a popup prompting you for a password for each networksetup invocation)

  • Hey Allan, thanks for your response, but for AirDrop to work I need wifi enabled. That's why I specifically wrote 'disconnect'.
    – Panagiotis
    Commented Jun 8, 2018 at 12:13
  • 2
    @PanagiotisToniBobolakis That level of explanation is best put in the body of the question. If you explain why disabling it and linking to another question here that already has this answer - makes it clear you want to control the SSID association only - not change the power state or
    – bmike
    Commented Jun 8, 2018 at 12:16
  • If I reboot will I need to run the sudo networksetup -setnetworkserviceenabled Wi-Fi off command again?
    – Doryx
    Commented Nov 10, 2021 at 21:23
  • 1
    It exists getairportpower <iface> which should show the state of the iface - on or off. But if disabled, it will not be accessible from networksetup it seems.
    – Timo
    Commented Apr 16, 2022 at 10:39
  • Thanks Allan for this detailed answer. I've tried the command you suggested to disconnect from current WiFi network, but unfortunately it keeps auto-connecting to the WiFi after reenabling the adapter. Any idea on how it can be done on recent macOS?
    – AnthoPak
    Commented Jun 7 at 12:35

You can use this one (found on the internet and tried myself):

Instead of "DEVICE_NAME" use your interface (i.g.: en0)

sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport "DEVICE_NAME" -z

You must log in to answer this question.

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