How to Work with the Network from the Linux Terminal: 11 Commands You Need to Know

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 1

Whether you want to download files, diagnose network problems, manage your network interfaces, or view network statistics, there’s a terminal command for that. This collection contains the tried and true tools and a few newer commands.

You can do most of this from a graphical desktop, although even Linux users that rarely use the terminal often launch one to use ping and other network diagnostic tools.

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 2

curl & wget

Use the curl or wget commands to download a file from the Internet without leaving the terminal. If you’re using curl, type curl -O followed by the path to the file. wget users can use wget without any options.. The file will appear in the current directory.

curl -O website.com/file
wget website.com/file

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 3

ping

ping sends ECHO_REQUEST packets to the address you specify. It’s a great way to see whether your computer can communicate with the Internet or a specific IP address. Bear in mind that many systems are configured not to respond to pings, however.

Unlike the ping command on Windows, the Linux ping command will keep sending packets until you terminate it. You can specify a finite amount of packets with the -c switch.

ping -c 4 google.com

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 4

tracepath & traceroute

The tracepath command is similar to traceroute, but it doesn’t require root privileges. It’s also installed by default on Ubuntu, while traceroute isn’t. tracepath traces the network path to a destination you specify and reports each “hop” along the path. If you’re having network problems or slowness, tracepath can show you where the network is failing or where the slowness is occurring.

tracepath example.com

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 5

mtr

The mtr command combines ping and tracepath into a single command. mtr will continue to send packets, showing you the ping time to each “hop.” This will also show you any problems — in this case, we can see that hop 6 is losing over 20% of the packets.

mtr howtogeek.com

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 6

Press q or Ctrl-C to quit when you’re done.

host

The host command performs DNS lookups. Give it a domain name and you’ll see the associated IP address. Give it an IP address and you’ll see the associated domain name.

host howtogeek.com
host 208.43.115.82

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 7

whois

The whois command will show you a website’s whois records, so you can view more information about who registered and owns a specific website.

whois example.com

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 8

ifplugstatus

The ifplugstatus command will tell you whether a cable is plugged into a network interface or not. It isn’t installed by default on Ubuntu. Use the following command to install it:

sudo apt-get install ifplugd

Run the command to see the status of all interfaces or specify a specific interface to view its status.

ifplugstatus
ifplugstatus eth0

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 9

“Link beat detected” means the cable is plugged in. You’ll see “unplugged” if it isn’t.

ifconfig

The ifconfig command has a variety of options to configure, tune, and debug your system’s network interfaces. It’s also a quick way to view IP addresses and other network interface information. Type ifconfig to view the status of all currently active network interfaces, including their names. You can also specify an interface’s name to view only information about that interface.

ifconfig
ifconfig eth0

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 10

ifdown & ifup

The ifdown and ifup commands are the same thing as running ifconfig up or ifconfig down. Given an interface’s name, they take the interface down or bring it up. This requires root permissions, so you have to use sudo on Ubuntu.

sudo ifdown eth0
sudo ifup eth0

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 11

Try this on a Linux desktop system and you’ll probably get an error message. Linux desktops usually use NetworkManager, which manages network interfaces for you. These commands will still work on servers without NetworkManager, though.

If you really need to configure NetworkManager from the command line, use the nmcli command.

dhclient

The dhclient command can release your computer’s IP address and get a new one from your DHCP server. This requires root permissions, so use sudo on Ubuntu. Run dhclient with no options to get a new IP address or use the -r switch to release your current IP address.

sudo dhclient -r
sudo dhclient

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 12

netstat

The netstat command can show a lot of different interface statistics, including open sockets and routing tables. Run the netstat command with no options and you’ll see a list of open sockets.

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 13

There’s a lot more you can do with this command. For example, use the netstat -p command to view the programs associated with open sockets.

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 14

View detailed statistics for all ports with netstat -s.

how-to-work-with-the-network-from-the-linux-terminal-11-commands-you-need-to-know photo 15


We’ve also covered commands for managing process and working with files in the past.

Article How to Work with the Network from the Linux Terminal: 11 Commands You Need to Know compiled by Original article here

More stories

How to Easily Share Files Between Nearby Computers

It’s a common situation — you have several computers near each other and you want to transfer files between them. You don’t have to pull out a USB drive, nor do you have to send them over email — there are faster, easier ways.

How to Watch Local Video Files on Your Wii U

Nintendo’s Wii U has apps for watching Netflix, YouTube, Hulu, and all kinds of other streaming video. But Nintendo doesn’t offer an app that will play media files from an external drive or media server. Here’s a little trick that will let you stream videos from your home network to your TV with

How to Watch Hulu on Ubuntu and Other Linux Distributions

Hulu doesn’t work out-of-the-box on modern Linux distributions. While Netflix “just works” if you’re using Google Chrome, Hulu’s DRM has gotten old and clunky. You can get Hulu to work on Linux, but it’ll take a little tweaking.