How to restart Mac OS Network from Terminal
Apparently, Mac OS has some issues with Wi-Fi. It doesn’t work after it wakes up from sleep.
You have to turn wifi on and off to make it work again.
Usually my terminal is open all the time and I prefer to use keyboard for most of the operations on my setup.
You can use ifconfig
utility to restart the network
sudo ifconfig en0 down
sudo ifconfig en0 up
But this command requires sudo, and writing long passwords is cumbersome.
Fortunately there’s a networksetup
utility in macos, which can do it without sudo
.
networksetup -setairportpower en0 off
networksetup -setairportpower en0 on
You can add these commands as alias in ~/.zshrc
or ~/.bashrc
file for faster access.
alias netoff='networksetup -setairportpower en0 off'
alias neton='networksetup -setairportpower en0 on'
alias netrestart='networksetup -setairportpower en0 off && networksetup -setairportpower en0 on'
Remember to source the .rc
file for accessing the newly defined aliases.
source ~/.zshrc # If you use zsh as your shell
# OR
source ~/.bashrc # If you use bash as your shell
Now you just need to run netrestart
on your terminal and your wifi will restart.
P.S. My friend is actively seeking opportunities in Product Management, Marketing Operations, or Data Analytics.
He brings strong expertise in data analytics, mathematics, and finance. Currently based in Bangalore, India, he is open to both remote and in-office opportunities.
If you're looking for a driven professional with strong analytical skills and quick learning ability, please reach out to him directly:
- Email: sachin.23@dmsiitd.org
- LinkedIn: linkedin.com/in/sachiniit
- Resume: View Resume
#macos
#networking
#script
#terminal
#command