keepcalculator

06 Numbers and Powers

Enable Disable Airport Wireless Connections Command Line

Card No. 06·87260 · Updated · Standard formula, shown below

You can enable or disable airport wireless connections from the command line on macOS using the networksetup command (for modern macOS) or the deprecated airport command (for older versions). This article explains both methods, how they work, and common troubleshooting steps.

Background: The Airport Command and Its Successor

Apple’s AirPort utility historically provided a command-line tool named airport that could control Wi-Fi interfaces. However, starting with macOS Sierra (10.12), Apple deprecated the airport command in favor of networksetup, which is still present in current macOS versions. The airport binary may still exist on your system, but its functionality is limited and it is no longer officially supported. For reliable control on modern systems, use networksetup.

How to Check Your Wi-Fi Interface Name

Before you can enable or disable Wi-Fi, you need to know the exact name of your wireless interface. Typically, it is en0 or en1, but it can vary. To list all network interfaces, run:

networksetup -listallhardwareports

Look for the entry labeled Wi-Fi (or AirPort on older systems). The corresponding device name (e.g., en0) is what you will use in the commands below.

Enabling and Disabling Wi-Fi with networksetup

Once you have the interface name, use the following commands:

  • Disable Wi-Fi: sudo networksetup -setairportpower en0 off
  • Enable Wi-Fi: sudo networksetup -setairportpower en0 on

Replace en0 with your actual interface name. The sudo prefix is required because changing Wi-Fi power requires administrator privileges. You will be prompted for your password. After running the command, you can verify the current status with:

networksetup -getairportpower en0

This will output either Wi-Fi Power : On or Wi-Fi Power : Off.

Using the Deprecated airport Command (Older macOS)

If you are running macOS El Capitan (10.11) or earlier, or if you have the airport binary installed, you can use:

  • Disable: sudo airport en0 -z (this disconnects from the current network but does not turn off the radio completely)
  • Enable: sudo airport en0 -z is not for enabling; instead, rejoin a network with networksetup -setairportnetwork en0 <SSID>

Note that the airport command does not have a direct “power off” flag. The -z option disassociates from any network, effectively disabling the connection but leaving the radio on. To fully power off the Wi-Fi adapter on older systems, you would still use networksetup -setairportpower if available, or use the GUI.

Why Use the Command Line?

Using the command line to toggle Wi-Fi is useful for scripting, automation, and troubleshooting. For example, you can create a shell script that disables Wi-Fi when you plug in an Ethernet cable, or you can quickly toggle Wi-Fi without navigating through System Settings. It also allows you to control Wi-Fi remotely via SSH, which is handy for managing a Mac server or a headless system.

Common Problems and Solutions

Here are typical issues you might encounter:

  • “Wi-Fi interface not found” – You may be using the wrong interface name. Double-check with networksetup -listallhardwareports.
  • Permission denied – Always use sudo; otherwise, you will get an error.
  • Command not found – On newer macOS, the airport command may not be in your PATH. The networksetup command is always available.
  • Wi-Fi still shows as connected – If you use airport -z, it only disconnects from the current network; the radio remains on. To fully disable the radio, use networksetup -setairportpower.

Alternatives to Command Line

If you prefer a graphical interface, you can toggle Wi-Fi from the menu bar icon or in System Settings > Wi-Fi. For advanced control, third-party apps exist, but they often wrap the same networksetup commands. The command line remains the most direct and scriptable method.

Frequently Asked Questions

Can I toggle Wi-Fi without sudo?

No, changing Wi-Fi power requires administrator privileges. You must use sudo and enter your password. If you need to do it without a password prompt, you can configure a sudoers entry, but that has security implications.

What is the difference between disabling Wi-Fi and disconnecting?

Disabling Wi-Fi turns off the radio entirely, saving power and preventing any connection. Disconnecting (e.g., with airport -z) only drops the current network; the radio stays on and may auto-join another known network.

Why is my interface name en0 or en1?

The interface name is assigned by the system based on the order of hardware detection. Typically, en0 is the built-in Ethernet or Wi-Fi, but it can vary. Always verify with networksetup -listallhardwareports.

Will these commands work on macOS Sonoma or Ventura?

Yes, networksetup -setairportpower works on all modern macOS versions, including Sonoma and Ventura. The airport command is deprecated but may still function for some operations.

Can I use these commands on Windows or Linux?

No, these commands are macOS-specific. Windows uses netsh interface set interface or wlan commands, and Linux uses nmcli or ip link set.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →