Master Linux Network Commands: IP, Netstat, Ping, Traceroute, DNS & DHCP Explained
Learn how to use essential Linux networking tools—including ip, ifconfig, netstat, ping, traceroute, host, dig, and dhclient—to view interface details, monitor connections, test reachability, query DNS, and manage DHCP leases, with command options and practical tips for effective system troubleshooting.
Interface Information
Use the interface information commands when you need more details about the network interfaces of the device you are logged into.
IP Command
Show all IP addresses:
ip aYou can add the -4 or -6 options to filter only IPv4 or IPv6 addresses.
ip -4 a
ip -6 aAnother way to view network information is with ifconfig, which is easier to read than ip. It shows similar information, but also displays basic transmit/receive statistics.
ifconfigNetwork Status Command
The netstat command is useful for discovering which ports various services are listening on. Use -t for TCP, -u for UDP, -l to show listening ports, and -n to display IP addresses instead of hostnames.
Options can be combined, for example:
netstat -tulTo see the process ID (PID) of the service listening on a port, add -p. This requires sudo to display the PID.
sudo netstat -tulpNetwork Availability
Network availability commands can quickly check whether you can reach a host on the network or whether the host is powered on.
Ping Command
The most well‑known network command is ping, which tests whether a device is reachable unless blocked by a firewall. It works locally without routing through a router.
Use ping with an IP address or hostname:
ping 192.168.1.10
ping thehostname pingruns continuously until you stop it (e.g., Ctrl+Shift+C).
Specify the number of pings with -c:
ping -c 3 192.168.1.10If IPv6 is enabled, ping may default to IPv6; use -4 or -6 to force the address family.
ping -4 192.168.1.10
ping -6 192.168.1.10Multiple options can be combined, e.g., ping an IPv4 address three times:
ping -4 -c 3 192.168.1.10Some firewalls block ping. Allowing ping on internal networks while blocking it on WAN or DMZ can help with troubleshooting while limiting exposure.
Traceroute Command
tracerouteshows the path packets take to reach another network on the Internet. It is most useful when multiple routers are involved.
Basic usage with an IP address or hostname:
traceroute 8.8.8.8
traceroute google.comLike ping, you can specify IPv4 or IPv6. traceroute defaults to IPv4.
traceroute -4 google.com
traceroute -6 google.comAdditional options exist, but the basic command is sufficient for most users.
Domain Name System
DNS commands are useful for assigning hostnames or overriding DNS values in routers, and for verifying that a hostname resolves to the correct IP address.
Host Command
Use host to look up the IP address associated with a domain name on a local network or the Internet:
host google.comYou can also specify a DNS server to use for the lookup:
host google.com 1.1.1.1Dig Command
The dig command provides more detailed DNS information. Its basic usage mirrors host:
dig google.comSpecify a DNS server with @:
dig @8.8.8.8 google.comQuery all DNS records with the any option:
dig google.com anyQuery specific record types, such as MX:
dig google.com mxPerform a reverse DNS lookup with -x:
dig -x 8.8.8.8System Resolve Command
systemd-resolveshows the current DNS server settings. Running it displays a line “Current DNS Server” with the servers obtained via DHCP or manually configured.
systemd-resolve --statusWhen using split DNS, refresh the resolver cache with --flush-caches so the system quickly starts resolving new IP addresses:
sudo systemd-resolve --flush-cachesThis command is only available on systems that use systemd.
DHCP
DHCP commands are handy when you need to manually release and renew DHCP leases after making changes to a router or switch.
Dhclient Command
When you assign a static IP via DHCP, change the DHCP address range, or make other DHCP‑related network changes, dhclient can update the device’s lease more easily.
Without the command you would have to disconnect and reconnect the network physically or wait for the lease to expire.
To release and renew the DHCP lease on your device, run the following two commands with sudo:
sudo dhclient -r
sudo dhclientSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
