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

May 31, 2011 - 10 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 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 OS X

networksetup -setairportpower airport off

Note that you may need to specify the device port rather than ‘airport’, for example en1 or en0:

networksetup -setairportpower en0 off

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

networksetup -setairportpower airport on

Again, you may need to specify device 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.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: David Mendez in Command Line, Mac OS X

10 Comments

» Comments RSS Feed

  1. Brozoner says:

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

  2. 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

  3. xf says:

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

  4. 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

  5. Mark says:

    can u help me?

  6. 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

  7. [...] 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. [...]

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

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