5 Networking Commands for the Linux Terminal
Pinterest Stumbleupon Whatsapp
Advertisement

Working in the command line can have numerous advantages over working in the Graphical User Interface (GUI). It’s almost always faster, relative to the GUI. More advanced computer users often prefer command line for it’s scripting and concise process of working.

Here are some of the Linux networking commands you can use and apply immediately. Some commands may require administrative privileges — so make sure you have sudo access!

programmers terminal
Image Credit: Julia Tim via Shutterstock

1. ping

The go-to-command to quickly begin to diagnose network issues, find the IP address of a device on the network, or even monitor the reliability 7 Simple Steps to Diagnose a Network Problem 7 Simple Steps to Diagnose a Network Problem Network issues are frustrating, especially when the problem lies with your ISP. Next time you can't get online, here's the process you should follow on your end to diagnose the network problem. Read More of your network.

ping -c 4 google.com

5 Networking Commands for the Linux Terminal ubuntu terminal network ping

There are a few things to note from the above command and its yield. At a glance you can see the IP address that responded to the request along with the time it took to respond. The -c 4 option will limit the ping to four replies. If you decided to run the following command…

ping google.com

…the ping will run indefinitely, until you decided to stop it. This can be accomplished by pressing Ctrl + C on your keyboard.

Output to a File

The reason you may want to leave a ping running for a long period could be to monitor the network connection between two devices. Or even between your computer and the internet. This can be achieved by running:

ping -O google.com > someFile.txt

network ping before nano

After you run this command it will seem like nothing is happening and your cursor will just blink continuously. However, there are two things happening in this command. There is an infinite ping running and it is piping the output of that ping command to a file called someFile.txt in the same directory. This file can be opened and subjected to your forensic investigation. By default the ping command will not show when there was no reply. Enter the -O option as you see above.

To demonstrate this, I have an infinite ping running, piping it’s output to a text file, and while it’s running I unplugged and reconnected my network cable a few times. This will simulate a drop in connection, and the connection returning. To view the contents of the text file you can run the following command:

nano someFile.txt

network ping nano ubuntu terminal

The above information displayed in the text file clearly shows where the network connection has dropped. If you’re experiencing strange network issues, this simple experiment can help you eliminate certain possibilities. For example, if you were to leave a ping running against a device on your local network and there were no dropped replies, but the same experiment against an address on the internet does show some dropped packets. There is a strong likelihood that your computer hardware is okay, but the device connecting to the internet may need further inspection.

person network problems
Image Credit: T-Design via Shutterstock

2. The New ip Command

If you were a fan of the ifconfig command (used for finding the IP address of your device, which was useful for remote connections How to Establish a Remote Desktop Access to Ubuntu From Windows How to Establish a Remote Desktop Access to Ubuntu From Windows Wish you could access your home computer from work or the computer in the basement from your living room? Remote desktop is the answer. We'll show you how to remotely access Ubuntu from Windows. Read More ), you may be interested in knowing it has been superseded by its hip, cooler, more fully-featured younger brother. While there is a smorgasbord of objects and options to choose from, here’s some of the common commands to help you deal with the phasing out of ifconfig.

ip address show

terminal network ip address command

Evidently, this shows you the IP addresses of any interfaces your devices have. This will be the main command used to replace ifconfig:

ip link set DEVICE down
ip link set DEVICE up

Similar to ifconfig DEVICE down or ifconfig DEVICE up you can set your devices state to up or down. Simply replace DEVICE with the interface you would like to change the state of.

ip link ubuntu

3. Download a File From the Internet

Open a web browser, navigate to the page, click the download link. That’s the way to download a file, right?

No!

Using curl or wget, you can easily download a file from without leaving the warm, snug atmosphere of your terminal session 4 Ways to Teach Yourself Terminal Commands in Linux 4 Ways to Teach Yourself Terminal Commands in Linux If you want to become a true Linux master, having some terminal knowledge is a good idea. Here methods you can use to start teaching yourself. Read More .

curl -O https://www.openssl.org/source/openssl-1.0.2l.tar.gz

network terminal curl download

wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz

Essentially both of the above commands will get you the same result. wget has a major strong side which is download recursively compared to curl. Although the winner in the “Protocols that are supported” category is curl by a long shot. By comparison, curl supports the following protocols…

network curl protocols

…while wget supports HTTP, HTTPS, and FTP. This is by no means a definitive comparison between both commands. And depending on what is your use case, your mileage may vary. Understanding and using wget will help you use some neat downloading tricks Mastering Wget & Learning Some Neat Downloading Tricks Mastering Wget & Learning Some Neat Downloading Tricks Sometimes it's just not enough to save a website locally from your browser. Sometimes you need a little bit more power. For this, there's a neat little command line tool known as Wget. Wget is... Read More .

4. Get a New IP Address

If you wanted to release your IP address and get issued a new one from your DHCP server DHCP Explained: Installing & Configuring A Free DHCP Server [Linux] DHCP Explained: Installing & Configuring A Free DHCP Server [Linux] Read More you can use dhclient:

dhclient -r

Using dhclient with the -r option will release your IP Address:

dhclient

Omitting the -r option will get your DHCP to issue you a new IP Address based on how it’s been configured.

ubuntu dhclient

network cables
Image Credit: Nednapa Sopasuntorn via Shutterstock

5. Get More Information About a Website

While the whois command may not be shipped by default with your distribution of Linux. It’s really useful to be able to be able to view a website’s whois record right from the command line.  To install whois run the following commands:

apt-get update
apt-get install whois

Once you have whois installed you can simply query any domain name to get more information:

whois makeuseof.com

terminal ubuntu whois

Network Commands in the Terminal: Simple!

Whether you’re locked in the command line or you’re using the terminal emulator, text commands are more efficient for networking issues than point-and-click. Particularly, the responses are more verbose and useful.

Which Linux commands do you run frequently? Are you a command line person or a GUI person? We would love to know which commands you use frequently on your Linux based system.

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. M Parak
    August 2, 2017 at 11:13 am

    I stumbled on this article and found it to be very useful and informative.
    (Good 5 min refresher on command line gems)

    In a world that has no shortage of Long winded articles that were designed to make the writer look smart, it was good to read something that was "straight up useful".

    The average reader doesn't have the time to sift through mountains of self praise and pompous droning.

    • Yusuf Limalia
      August 3, 2017 at 7:19 am

      Hi MParak. Thank you for your kind words! Don't mean to shamelessly plug MUO but feel free to browse our other articles. I think you will find all the other authors are similar if not better!

      Thanks again!