Operations 10 min read

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.

Open Source Linux
Open Source Linux
Open Source Linux
Master Linux Network Commands: IP, Netstat, Ping, Traceroute, DNS & DHCP Explained

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 a

You can add the -4 or -6 options to filter only IPv4 or IPv6 addresses.

ip -4 a
ip -6 a

Another 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.

ifconfig

Network 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 -tul

To see the process ID (PID) of the service listening on a port, add -p. This requires sudo to display the PID.

sudo netstat -tulp

Network 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
ping

runs continuously until you stop it (e.g., Ctrl+Shift+C).

Specify the number of pings with -c:

ping -c 3 192.168.1.10

If 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.10

Multiple options can be combined, e.g., ping an IPv4 address three times:

ping -4 -c 3 192.168.1.10

Some firewalls block ping. Allowing ping on internal networks while blocking it on WAN or DMZ can help with troubleshooting while limiting exposure.

Traceroute Command

traceroute

shows 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.com

Like ping, you can specify IPv4 or IPv6. traceroute defaults to IPv4.

traceroute -4 google.com
traceroute -6 google.com

Additional 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.com

You can also specify a DNS server to use for the lookup:

host google.com 1.1.1.1

Dig Command

The dig command provides more detailed DNS information. Its basic usage mirrors host:

dig google.com

Specify a DNS server with @:

dig @8.8.8.8 google.com

Query all DNS records with the any option:

dig google.com any

Query specific record types, such as MX:

dig google.com mx

Perform a reverse DNS lookup with -x:

dig -x 8.8.8.8

System Resolve Command

systemd-resolve

shows the current DNS server settings. Running it displays a line “Current DNS Server” with the servers obtained via DHCP or manually configured.

systemd-resolve --status

When using split DNS, refresh the resolver cache with --flush-caches so the system quickly starts resolving new IP addresses:

sudo systemd-resolve --flush-caches

This 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 dhclient
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxtroubleshootingSysadmincommands
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.