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!
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 of your network.
ping -c 4 google.com
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…
…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
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:
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.
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), 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
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.
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?
Using curl or wget, you can easily download a file from without leaving the warm, snug atmosphere of your terminal session.
curl -O 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…
…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.
4. Get a New IP Address
If you wanted to release your IP address and get issued a new one from your DHCP server you can use dhclient:
Using dhclient with the -r option will release your IP Address:
Omitting the -r option will get your DHCP to issue you a new IP Address based on how it’s been configured.
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:
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.