The networking commands are mainly used for getting network system information and troubleshooting networking problems.
Here we look at the 10 commands that I use most often.
1. Ping Command
The ping command is one of the most often used networking utilities for detecting devices on a network and for troubleshooting network problems.
When you ping a device you send that device a short message, which it then sends back (the echo).
The general format is ping hostname or ping IPaddress.
ping www.google.com or ping 22.214.171.124
On Linux the command repeats at 1 second interval. To restrict the number of attempts use the -c switch
ping www.google.com -c 4 //4 pings
2. ifconfig Command
This utility is used for finding network information about your local machine interfaces.
Type the command ifconfig at the prompt to view the IP addresses of all interfaces, and use
ifconfig eth0 //show Ethernet interface details
ifconfig wlan0 //show Wi-Fi interface details
To shut down or bring up an interface use
sudo ifconfig wlan0 down
sudo ifconfig wlan0 up
3. IP Command
Similar to ifconfig and has most of the same functionality. There is an excellent tutorial on using it here.
hostname //shows name of host
hostname -d //shows domain name of host
hostname -I //shows all IP addresses assigned to host
This you can use to release and renew IP addresses from a DHCP server
to release use:
to renew use:
to target a particular interface (e.g eth0) use
dhclient -r eth0
to enable more details use the -v (verbose) switch
dhclient -r -v eth0
Note: the above commands only work if you are using the dhclient daemon.
Doing this on my PI has no effect as it uses dhcpcd daemon and not the dhclient daemon.
Used to display and configure routing information on your host.
It is only really used if you want your machine to act as a router on your network.
However it is also a quick way to find out the address of your gateway as shown in the screenshot below where the gateway address is 192.168.1.1:
For more information on using the command see this article
7. Netstat (network statistics)
Very useful tool for finding information on your network connections and ports.
You can use it to find out all of the tcp or udp ports that are active on your system.
If for example you want to know if the mosquitto broker was active on the server then use:
For more netstat commands see this tutorial- 20 netstat commands
You can see that port 1883 (default MQTT port) is in a listening state.
Very useful command line network monitoring tool like Wireshark.
It is automatically installed on Linux. Here is a very good tutorial on how to use it.-TCP dump Tutorial with Examples
Arp shows the address resolution cache. This will show the IP address and MAC address of devices that the machine knows about.
The screen shot below show the result of using the arp -v command
9. Nslookup, dig and host
These tools are used for troubleshooting DNS issues. Nslookup was the original DNS tool and is available on Windows and Linux. Dig is more powerful and more modern tool to use.
The screen shot below show the results of a nslookup and dig query:
The host tool provides a different output to nslookup and dig. If you query the domain e.g. google.com you get to see the mail servers.
This tutorial shows how to use the host command in more detail.
This is used for viewing and setting up the firewall on Linux machines. By default no firewall rules are installed as shown in the screen shot below:
This howto goes into using it in more detail.
Related tutorials and resources
- Understanding DHCP on Home Networks
- Using The Ping Command – Home Networking Testing
- Basic Home Network Hardware Components, Devices and Services
- 10 Useful Windows Networking Commands