Sub topic 12
Equivalent commands on Linux and macOS
This chapter assumes you know what an IP address, a default gateway, and a DNS server are. It also assumes you can read ipconfig, ping, and tracert output on Windows. The goal is to map each Windows tool to its Linux or macOS counterpart and to flag the differences that cause confusion.
The mapping at a glance
| Task | Windows | Linux | macOS |
|---|---|---|---|
| Show addresses | `ipconfig` | `ip addr show` | `ifconfig` |
| Show default gateway | `ipconfig` | `ip route show` | `netstat -rn` |
| Test reachability | `ping` | `ping` | `ping` |
| Trace the path | `tracert` | `traceroute` | `traceroute` |
| Renew DHCP lease | `ipconfig /release`, `/renew` | depends on the network manager | System Settings or `ipconfig set` |
| Flush DNS cache | `ipconfig /flushdns` | depends on the resolver | `dscacheutil -flushcache` |
The ping and traceroute commands exist on all three systems, but their defaults and options differ. The configuration commands differ more, because Windows puts everything in ipconfig.
Viewing addresses and the gateway
On Linux, the ip command replaces the older ifconfig. One command lists addresses and another lists routes. The default gateway is the default via line in the route table.
ip addr show
ip route showThe ip addr show output gives each interface's IPv4 address with its prefix length, such as /24, which is the subnet mask in short form. It also shows the MAC address on the link/ether line. The ip route show output contains a line like default via 192.168.1.1 dev eth0, and that address is your default gateway.
On macOS, ifconfig shows the addresses and netstat -rn shows the routing table. Both are standard on the system. Note that ifconfig reports the mask in hexadecimal, so 0xffffff00 means 255.255.255.0.
ping: different defaults
On Windows, ping sends four echo requests and stops. On Linux and macOS, it runs until you press Ctrl+C. Use -c to set a count.
ping -c 10 8.8.8.8Windows uses -n for the count and -t to run continuously, so these options do not carry over. Linux and macOS also print a summary on exit, with packets sent, packets received, percent loss, and minimum, average, and maximum round-trip time.
The TTL value in replies often differs by operating system, because each system starts with its own default. Do not rely on it to identify a host, since it also drops by one at every router.
traceroute: UDP by default
Windows tracert sends ICMP echo requests. Linux and macOS traceroute sends UDP datagrams to high port numbers by default. Each probe has an increasing TTL, so each router along the path returns an ICMP Time Exceeded message, as covered in the TTL chapter. The final host answers with ICMP Port Unreachable instead of an echo reply.
traceroute example.com
traceroute -n example.com
sudo traceroute -I example.com-nskips reverse DNS lookups, like-don Windows, and makes the trace faster.-Isends ICMP echo probes, which matches Windows behavior. It typically needs root on Linux.
Renewing leases and flushing DNS
There is no single command for these tasks on Linux. The right one depends on what manages the network and DNS on that machine, such as NetworkManager or systemd-resolved. Check which one your system uses before you run anything. On macOS, the DNS cache command is dscacheutil -flushcache, and newer versions may also need the mDNSResponder process to be signalled.
Same method, different tools
The layered workflow does not change. Check your address and gateway, then ping the loopback, the gateway, a remote IP, and a remote name, and trace the path if the failure is beyond the gateway.
Exercise
A Linux trace to a server stops after hop 5 and shows only asterisks, while tracert on Windows reaches the server. Why can this happen, and what would you try?
Show answer
Linux traceroute sends UDP probes by default, and a firewall on the path may drop them, while Windows tracert sends ICMP echo requests that the firewall allows. Run sudo traceroute -I example.com to send ICMP probes and compare the result.
Exercise
Which Linux command shows your default gateway, and which line of its output do you read?
Show answer
ip route show. The gateway is the address after default via.