
If you’ve used network commands on Windows, such as ping and tracert, you may be wondering whether you can use them on Linux, either on their own or as part of WSL. Fortunately, you can.
ping
I remember sitting in a computer networking class in college when the teacher demonstrated using the ping command in a Windows command prompt. It was the start of a lifelong relationship, even if it transcended the operating systems and came full circle with the WSL.
The simplest way to use ping in Linux and WSL command line is to use ping followed by an IP address or domain name.
ping google.com
ping 127.0.0.1
The latter will ping the “loopback device” or interface of your local device. Ping is useful in determining whether or not a host is ready, or at least responding to ping requests. Some hosts will remain up but reject ping requests for security. Ping is also useful in determining whether a site is down for everyone or just you.
The default behavior of ping on Linux and other Unix-like systems is different from Windows. On Windows, the ping command will run four times. On Linux, ping will run forever until you press it Ctrl+cthen we show you some statistics about the packages returned.
To stop ping after a certain number of pings, use the -c option. To ping the host four times:
ping -c 4 google.com
Traceroute: Traceroute or Tracepath on Linux
Another useful tool for network diagnosis on Windows is the Tracert utility. This tool allows you to trace the path from your device through network nodes all the way to the destination device. In practice, this is not necessarily completely reliable because some hosts along the way will not respond. It’s still easy to tell if the site is down for anyone else or just you.
You can search for it in Linux, but you may find it missing. It just has a different name. Try running the “traceroute” command:
traceroute example.com
Or you can try the Tracepath command:
tracepath example.com
You may have to install an additional package on your system, depending on the Linux distribution you are running. If these commands fail, you may try running a search in your package manager to determine which package you may need to install.
As an alternative, you might consider installing MTR, which combines ping and tracking functions into one utility. To install it on Ubuntu:
sudo apt install mtr
You can connect to MTR using a hostname or IP address similar to ping and traceroute:
mtr howtogeek.com
The default behavior is to open the GUI window and continue to loop the trace path. You can get the MTR display in the terminal using the -t option:
mtr -t howtogeek.com
You can do this automatically by setting the environment variable MTR_OPTIONS:
export MTR_OPTIONS="-t"
You can put this in .bashrc or .zshrc files to set it every time you start a new station.
Now, when you run MTR, it will run in the terminal window.
One key difference from traditional traceroutes is that MTR displays statistics about each node, similar to what you would see through a ping test. It will tell you the shortest, longest, and average ping times for each node, as well as the standard deviation. This will tell you how ping times are spread around average.
ipconfig – IP only on Linux
You may have used the ipconfig command on Windows to see information about your network configuration. ifconfig was equivalent in Linux but is just “ip” now.
To see all network interfaces on your system:
ip link
To see the IP address:
ip address
In WSL2, by default, you will see the address of the WSL virtual machine. If you want to manage your Windows network connection on a Windows machine, it’s best to do it directly from the Windows side.
netstat – use lsof or ss
Sometimes, you want to see all open network connections. Maybe you’re concerned that someone has gained unauthorized access to your system. Maybe you just want to know which apps “call home.” On Windows, the netstat command will do this. There are also equivalents on Linux
lsof is a popular tool for checking open files. In Linux, everything is a file, and this includes network connections. You can just run the lsof command in the shell:
lsof
By default, this will only show you all files that have been opened by any running Linux applications. To see all Internet connections, use the -i option:
lsof -i
On Linux, ss will also display information about open sockets, similar to netstat:
ss
One caveat if you use WSL is that these utilities will only show you connections on the Linux side of the system. If you want to check Windows processes, you can use the Windows netstat utility from WSL using the techniques mentioned later in this article.
nslookup: Use nslookup or Dig in Linux instead
To find out who is behind the domain name, you can use the nslookup utility on Windows. You can do the same thing on Linux
There is a similar nslookup command on Linux:
nslookup howtogeek.com
You can also use the drilling tool:
dig howtogeek.com
Both will return the Name Servers for the domain name associated with the address you provided, in this case, howtogeek.com.
Depending on your Linux system, these tools may not be installed by default. They are not present in Ubuntu, which is the default distribution for WSL. If you want these tools, you will have to install another package called “bind9-dnsutils”.
Fortunately, it’s easy to do using apt:
sudo apt install bind9-dnsutils
Bonus tip: Use Linux and Windows commands in WSL
If you use WSL, you can mix and match Linux and Windows commands.
On the Linux side, you can append “.exe” to a command to use the Windows version. For example, to run the Windows netstat command:
netstat.exe
On the Windows side, you can also run Linux commands using the wsl command. For example, to run a Linux ping from PowerShell using the default Linux distribution:
wsl ping google.com
If you run network commands from the Windows command line, you can easily do so from Linux, and WSL makes it even easier by running commands from both systems. Many Windows commands originated on Unix-like systems, which is why many of them are similar.