If you've used networking commands on Windows, such as ping and tracert, you might wonder if you can use them on Linux, whether on its own or part of WSL. Fortunately, you can.
ping
I remember sitting in a computer networking class in college when the instructor demonstrated the use of the ping command in the Windows Command Prompt. It was the beginning of a lifelong relationship, even if it's crossed operating systems and came back full circle with WSL.
The simplest way to use ping in the Linux and WSL command line is to use ping followed by an IP address or domain name.
The latter will ping the "loopback device," or the interface of your local machine. ping is useful for determining if a host is up, or at least responding to ping requests. Some hosts will still be up but reject ping requests for security. Ping is also useful for determining if 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 for four times. On linux, ping will run forever until you press Ctrl + c, then show you some statistics about the returned packets .
To have ping stop after a certain number of pings, use the -c option. To ping a host four times:
tracert: traceroute or tracepath on Linux
Another useful network diagnostic tool on Windows is the tracert utility. This tool lets you trace a path from your machine through network nodes all the way through to the destination machine . In practice, this isn't necessarily completely reliable because some hosts along the way won't respond. It's still handy for finding out if a site is down for everyone else or just you.
You may look for it in Linux, but you might find it missing. It just has a different name. Try running the "traceroute" command:
Or you might try the tracepath command:
You might have to install an extra package on your system, depending on the Linux distro you're running. If these commands fail, you might try running a search in your package manager to identify a package you might need to install.
As an alternative, you might consider installing MTR, which combines the functions of ping and a traceroute into one utility. To install it on Ubuntu:
You can call MTR with the hostname or IP address similar to ping and traceroute:
The default behavior is to open up a GUI window and keep repeating the traceroute. You can have MTR display in the terminal with the -t option:
You can do this automatically by setting the MTR_OPTIONS environment variable :
You can put this in your .bashrc or .zshrc files to set it every time you launch a new terminal.
Now, when you run MTR, it'll run in the terminal window.
One key difference from conventional traceroutes is that MTR shows statistics on each node, similar to what you would see with a ping. It'll tell you the shortest, longest, and average ping times for each node, as well as the standard deviation. This will tell you how spread out the ping times are around the average.
ipconfig - Just ip on Linux
You might have used the ipconfig command on Windows to see information about your network configuration. The ifconfig used to be the equivalent on Linux but it's just "ip" now .
To see all the network interfaces on your system:
To see the IP address:
In WSL2, by default, you'll see the address of the WSL virtual machine. If you want to manage the network connection of your Windows system on a Windows machine, it's best to do so directly from the Windows side .
netstat - Use lsof or ss
Sometimes, you want to see all of the open network connections. Maybe you're worried that someone has gained unauthorized access to your system. Maybe you just want to see which apps are "phoning home." On Windows, the netstat command will do this. There are also equivalents on Linux
lsof is a common tool for examining open files. On Linux, everything is a file, and this includes network connections. You can just run the lsof command at the shell:
By default, this will just show you all files that any running Linux apps have open. To see all the internet connections, use the -i option:
On Linux, ss will also show information about open sockets, similar to netstat:
One caveat if you're using WSL is that these utilities will only show you the connections on the Linux side of the system. If you want to investigate Windows processes, you can use the Windows netstat utility from WSL using techniques mentioned later in this article.
nslookup: Use nslookup or dig in Linux instead
To find out who's behind a domain name, you might use the nslookup utility on Windows. You can do the same on Linux
There's a similar nslookup command on Linux:
You can also use the dig utility :
Both of these will display the "name servers" of the domain name associated with the address you supplied, in this case, howtogeek.com.
Depending on your Linux system, these tools might not be installed by default. They weren't on the Ubuntu distro that's the default for WSL. If you want these tools, you'll have to install another package called "bind9-dnsutils."
Fortunately, this is easy to do with apt:
Bonus tip: Use both Linux and Windows commands in WSL
If you're using WSL, you can mix and match Linux and Windows commands .
From the Linux side, you can append ".exe" to a command to use the Windows version. For example, to run the Windows netstat command:
From the Windows side, you can also run Linux commands with the wsl command. For example, to run the Linux ping from PowerShell using the default Linux distro:
If you've run networking commands from the Windows command line, you can easily do so from Linux, and WSL even makes it easier by running commands from both systems. A lot of the Windows commands originated on Unix-like systems, which is why many of them are so similar.
