The Most Useful macOS Terminal Network Commands I Discovered

I remember feeling a little intimidated when I first tried out macOS Terminal network commands. After all, the Terminal can look pretty cryptic at a glance. But once I realized how much faster (and sometimes easier) it is to troubleshoot and explore network settings right from the console, I was hooked. In this ultimate guide, I’m sharing the most useful tools and tips I discovered along the way.
The key takeaway? You can quickly diagnose network issues, test connectivity, and monitor traffic just by typing a few commands. Ready to see how it all works?
Set up your environment
Before digging in, I like to do a quick check that my Terminal is ready to go.
- Update macOS: Ensuring your system is current helps avoid weird conflicts.
- Install command-line tools: In many cases, Xcode’s command-line tools are enough for standard commands.
- Use a comfortable Terminal profile: A dark theme or a larger font can reduce eye strain, especially if you’re regularly running tests.
If anything feels off, you can open the “Preferences” in the Terminal app to adjust text size, background color, or keyboard shortcuts. It may sound small, but it makes a big difference if you’re going to be in there often.
Check your local network
Sometimes the simplest step is verifying your local setup. One command I rely on is:
ifconfig
- Displays IP addresses and network interfaces.
- Helps confirm which interface (like “en0” for Wi-Fi) is active.
You can also try:
networksetup -listallhardwareports
- Shows hardware ports like Wi-Fi, Ethernet, or virtual interfaces.
I find these handy whenever I’m switching between networks or tinkering with Wi-Fi settings.
Diagnose DNS issues
If web pages aren’t loading or sites aren’t resolving, DNS (Domain Name System) might be the culprit. Two favorite commands for me are:
nslookup example.com
- Retrieves DNS records and reveals which DNS server answered the query.
- Quick way to see if your DNS configuration is correct.
dig example.com
- Offers deeper detail than nslookup, including query time and record types.
- Great for investigating advanced DNS settings.
Whenever my website is suddenly unreachable, these two commands help me figure out if it’s a DNS glitch or something else.
Trace your routes
When I want to see how data travels across the internet hops, traceroute is my best friend:
traceroute example.com
- Maps the path your data takes from your computer to the destination server.
- Helps pinpoint slow or failing nodes along the way.
I run this if a site feels sluggish or if I suspect a routing problem. If a segment is timing out, it often appears as asterisks in the output, giving me a clue about where the slowdown might be happening.
Monitor real-time traffic
Sometimes you just want to know what’s going on under the hood, right now. That’s where the nettop command comes in:
sudo nettop
- Provides a live view of network connections, processes, and data usage.
- Allows you to sort by process or connection so you can spot bandwidth hogs.
I love using nettop to see which apps are suddenly pulling down huge chunks of data. It’s especially useful if my Mac fan kicks in unexpectedly and I suspect a runaway process is eating bandwidth.
Scan open ports
Need to see which apps or services are listening on certain ports? The lsof (list open files) command with a port filter is a quick solution:
sudo lsof -i :80
- Identifies processes listening on port 80 (HTTP).
- Swap out 80 for any other port number you want to check.
Alternatively, try nmap if you want a broader port scan:
nmap localhost
- Shows open ports on your local machine.
- Great for checking server security or debugging services.
If you ever suspect that something is hogging a port you need, these commands will point you in the right direction.
Summing it all up
Exploring these macOS Terminal network commands made my troubleshooting workflow so much smoother. Now, instead of clicking through various System Preferences or third-party apps, I can handle most common network tasks right from the Terminal. It feels empowering to know exactly how to ping a site, trace a route, or spot-check DNS queries on the fly.
If you’re new to these tools, I suggest bookmarking a little cheatsheet of commands. Start with one or two, run them in different scenarios, and you’ll quickly grow more comfortable with the Terminal environment. Before you know it, you’ll be diagnosing network issues with confidence and maybe even discovering more hidden capabilities in macOS. Happy exploring!