Enable and Disable AirPort Wireless from the Command Line in Mac OS X
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.
Turn Airport Off via Command Line
networksetup -setairportpower airport off
Turn Airport On via Command Line
networksetup -setairportpower airport 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 AirPort 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.