Tuesday, February 2, 2016

How to restart Mac OS X networking

Command line tip: How to restart Mac OS X networking

Apple LogoIf you’re a terminal warrior like me, you’ll occasionally need to reboot the OS X network interface. There’s a quick way to do this through the command line – but first you need to know the identity of your network interface.
Run the ifconfig command in your terminal and find the interface with an IP address attached to it. On my MacBook Pro, the ethernet interface is en0 while the wireless interface is en1.  Yours may be similar.

Shutting down the network interface

Now that you’ve identified the interface, shutting it down and restarting it is a breeze. Run this command:
sudo ifconfig en0 down
And to start things back up again…
sudo ifconfig en0 up
That’s it. It’s a simple command that’s worth remembering – or bookmarking!

How to Find and Change Your MAC Address on OS X


How to Find and Change Your MAC Address on OS X

Each network card on your computer has a built-in unique MAC (Media Access Control) address that can be used to identify your computer. This is usually fine, but it is possible to change it natively in OS X.
If you are running Windows or Linux you can change your MAC address easily on those platforms as well, though we should note that this is more of an advanced topic and most people shouldn’t change their MAC addresses unless they really need to.

How to find your MAC Address

OS X provides a quick and easy way to find your MAC address. Just hold down the Option key and click the Wi-Fi icon in the menu bar:
The ‘Address’ portion with all the colons is your MAC address. This is your physical MAC address, which for most people is the address you want. However, if your address has been changed, you can check what address your computer is actually using to communicate with by firing up a Terminal and running:
ifconfig en0 | grep ether
This will output your MAC address for the hardware interface en0, which for most Macs is used for Wi-Fi. You can check which interface is used for wireless by holding down the Option key and clicking the Wi-Fi icon in the menu bar, which will quickly show you what device you are using to access the Internet:

Screenshot_6_23_15__4_48_PM

How to Change Your MAC Address

If you want to change your MAC address and have a specific one in mind, you can set it with:
sudo ifconfig en0 ether aa:bb:cc:dd:ee:ff
This will set your MAC address for en0. If you have a Mac that also has an ethernet port, you may need to use en1.

How to Get a Random MAC Address

If you’re going for privacy, randomizing your MAC address is probably the best option. This command will do it automatically:
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' | xargs sudo ifconfig en0 ether
This will generate and set a new MAC address for en0 every time you run it. The changes made from both these commands will be reverted when you restart, so this is not permanent. If you want, you can make a script and set it to run on startup, giving you a new one for each session.
Keep in mind that after you edit your MAC address you may have network problems, so it is a good idea to restart your Wi-Fi after changing it.