Managing network settings and configurations on macOS can be a straightforward process with the right commands. Here’s a detailed guide on essential network commands that can help troubleshoot, configure, and optimise your macOS network settings.
netstat – Show Network Status
The netstat command symbolically displays the contents of various network-related data structures. There are a number of output formats, depending on the options for the information presented. The first form of the command displays a list of active sockets for each protocol.
View Information on All Sockets
netstat -at
Network Info for IPv6
netstat -lt
Per Protocol Network Statistics
netstat -s
Statistics for a Specific Network Protocol
netstat -p igmp
Statistics for Network Interfaces
netstat -i
ntop
View Real-Time Network Information
ntop
traceroute – Print the Route Packets Take to a Network Host
The traceroute command utilises the IP protocol time to live field and attempts to elicit an ICMP TIME_EXCEEDED response from each gateway along the path to a host. The only mandatory parameter is the destination host name or IP number. The default probe datagram length is 40 bytes but can be increased by specifying a packet size.
Trace the Path Packets Take to a Destination
traceroute google.com
Without Resolving Domain Names
traceroute -n google.com
Run traceroute in Debug Mode
traceroute -d google.com
nc – Arbitrary TCP and UDP Connections and Listen
The nc (or netcat) utility can be used for almost anything involving TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrary ports, perform port scanning, and handle both IPv4 and IPv6. Unlike telnet, nc scripts nicely and separates error messages onto standard error.
Establish a Network Connection
nc -v google.com 443
Connect Over Port 443 with a Timeout of 15 Seconds
nc -v -w 15 google.com 443
Force IPv4-only Connection
nc -v -4 google.com 443
Setup a Network Listener on Port 2195 for Testing
nc -l 2195
tcpdump – Dump Traffic on a Network
tcpdump prints out a description of the contents of packets on a network interface that match the Boolean expression. The description is preceded by a time stamp, printed by default as hours, minutes, seconds, and fractions of a second since midnight. Capturing packets needs admin rights, so each command starts with sudo.
Capture Some Packets
sudo tcpdump -nS
Capture All Packets
sudo tcpdump -nnvvXS
Capture Packets for a Specific Port
sudo tcpdump -nnvvXS port 443
Capture Packets for a Given Port Destined for 192.168.1.1
sudo tcpdump -nnvvXS port 443 and dst 192.168.1.1
Capture Packets and Save to a Pcap File
sudo tcpdump -nnS -w /tmp/dump.pcap port 443 and dst 192.168.1.1
Read and Analyse Captured Packets
tcpdump -qns 0 -A -r /tmp/dump.pcap
networkQuality – Network Quality Testing Tool
networkQuality measures different aspects of network quality, including:
- Maximal capacity (speed)
- Responsiveness (measured in roundtrips per minute (RPM) under working conditions)
Note: This tool connects to the Internet to perform its tests, using data from your Internet service plan.
Verbose Output
networkquality -v
Test Upload/download in Sequential Instead of Parallel
networkquality -s
Using Private Relay
networkquality -v -p
nslookup – Query Internet Name Servers Interactively
nslookup allows users to query Internet domain name servers. It has two modes:
- Interactive mode : Query name servers for information about hosts and domains or print lists of hosts.
- Non-interactive mode : Print just the name and requested information for a host or domain.
nslookup
nettop – Display Updated Information About the Network
The nettop program displays a list of sockets or routes, providing real-time network statistics.
Display Updated Network Information
nettop
Disable Address to Name Resolution
nettop -n
Less Intensive CPU Usage (Draws Less Often)
nettop -c
dns-sd – Multicast DNS (mDNS) & DNS Service Discovery (DNS-SD) Test Tool
The dns-sd command is a network diagnostic tool similar to ping or traceroute. Unlike those tools, most of its functionality is implemented in library code, making it available to any application.
Return a List of Domains Recommended for Registering (Advertising) Services
dns-sd -E
Return a List of Domains Recommended for Browsing Services
dns-sd -F
Follow TexArxs on LinkedIn for more on macOS management and security.