Enable and Disable AirPort Wireless from the Command Line in Mac OS X

May 31, 2011 - 12 Comments

AirPort Wireless icon Sometimes the easiest fix when troubleshooting an AirPort wireless connection problem is to just turn AirPort on and off. Instead of using the menu item or System Preferences, we can enable and disable AirPort very quickly directly from the Mac OS X Terminal.


To do this, we’re going to use the ‘networksetup’ command. Note that this uses the “AirPort” reference, even with newer versions of Mac OS X where Wi-Fi is no longer called AirPort, so ignore that naming convention change from Apple and just know that both pertain to the Macs wireless networking abilities.

Turn Wi-Fi Off via Command Line in Mac OS X

The network device name will determine how the proper syntax is entered.

networksetup -setairportpower airport off

The device name could be airport, en0, en1, etc, depending on the Mac hardware and the version of OS X. Thus, you may need to specify the device port rather than ‘airport’, for example en1 or en0:

networksetup -setairportpower en0 off

You can use the -getairportpower flag to check the port if you are unsure.

Turn Wi-Fi (Airport) On via Command Line in Mac OS X

Just like turning wi-fi off from the command line, you can also toggle it back on again. As before, pay attention to the device name:

networksetup -setairportpower airport on

And again, you may need to specify device en0 or en1 instead of ‘airport’, like so:

networksetup -setairportpower en0 on

You won’t see any confirmation in the Terminal that the command succeeded or failed, but if you watch the AirPort menu icon you will see the bars disappear indicating the wireless interface is turned off, or reappear indicating that wireless is activated again.

We can also string the commands one after the other to power cycle the wireless interface on a Mac:

Quickly Power Cycle Wi-Fi with Mac OS X’s networksetup Tool

networksetup -setairportpower airport off; networksetup -setairportpower airport on

The AirPort wireless card seems to respond faster to the command line networksetup tool than any other method, making this an ultrafast method of power cycling the wireless interface. This is often enough to resolves basic wireless router connectivity issues like IP conflicts or malfunctioning DHCP requests.

I have enough regular encounters with one particularly flakey router that I created an alias to power cycle my AirPort card, you can do this by adding the following to your .bash_profile just be sure it is on one line:

alias airportcycle='networksetup -setairportpower airport off; networksetup -setairportpower airport on'

Now like any other alias, you only type ‘airportcycle’ and the wireless interface will immediately turn itself off and on again.

Disabling and reenabling AirPort is not the same as connecting to a wireless network from the command line, although you can do that too also by using the networksetup tool.

.

Related articles:

Posted by: David Mendez in Command Line, Mac OS, Tips & Tricks

12 Comments

» Comments RSS Feed

  1. J.D. says:

    Thank you for this! It was very useful when I was making a script to address some of the wifi issues in Sierra.

  2. […] flag again to verify the number. For the change to actually take effect, you will probably want to cycle the wi-fi connection off and on which can also be done through networksetup, though that isn’t always necessary. […]

  3. umoh says:

    i have tried all these command on my imac but i keep getting “You cannot set AirPort power because all AirPort network services are disabled.” please help i really need my airport card to work. thanks

  4. Mark says:

    can u help me?

  5. Mark says:

    I have the enabling Airport software from Apple, but it won’t install. My machine is a dual boot Hackintosh with the Netgear WN311B wireless card. I’ve read that it IS possible to get it to work but when I run the downloaded installer, it won’t install. I wondered if you knew how to fix this

  6. xf says:

    This doesn’t seem to work in Lion DP3, airport is not yet defined as an airport interface, ironically.

  7. Roberto says:

    “Instead of using the menu item”
    Yes, because it is soooooooo complex to do………

    “The AirPort wireless card seems to respond faster to the command line”
    Open the terminal, write the commands……
    Yes I agree it is very faster than to make a simple click in the menu bar………

    lol

  8. Brozoner says:

    The power cycling tip is nice, I hate manually selecting to turn on and off in the menu or CP, takes fooooooooorever

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site