Can you think of this scenario,
“What will I do if I have been provided with a laptop and no internet?”.
Ideally, it would impossible for most people to even imagine a life with a laptop or mobile but without the internet.
So, It’s always advised to learn a few useful networking commands. To learn networking in Linux one should learn to use the Terminal in Linux. Because using terminal commands is way more powerful than UI as it’ll be faster and more efficient.
A basic understanding of Linux terminal is enough to learn networking in Linux.
How to find the IP Address of my machine?
This is the most basic question in networking and it’s the starting tip of networking.
What’s an IP Address?
IP stands for “Internet Protocol,” which is the protocol (set of rules) governing the format of data sent via the internet or local network. An IP address is basically a unique address to identify a device on the internet or on a local network.
Back to track,
Being a professional web developer, I will be working on developing websites with their backend services. One day I was held up by an intern working on an interesting project. He wants his site to be responsive on Computer, Mobile, and Tablet. Though the site looks responsive on adjusting the browser window and switching to the mobile view on his laptop, the outcome of looking at the phone after deployment was not so impressive.
So, he asked me for help,
“I wanted to check the site’s responsiveness with my mobile on the development mode. Is it possible?”.
“Yes, it is. Connect your laptop and mobile on the same network. Find your laptop ip, and navigate to ip: on your mobile browser”, I replied.
Hearing my words, he opened a new tab in the browser and started typing “https://whatismy...", I stopped him and asked “What are you searching for?”
He answered, “I’m finding my IP address”.
ifconfig command to find the IP address of your machine", I replied.
He opened up the terminal and hit the command,
“Oh, Man! I’m confused now. Which is my IP here?”, was his next question.
I calmly explained to him about each block.
- lo — [LoopBack Interface] This is a special interface that the system uses to communicate with itself
- tun0 — [Tunnelling] Name itself describing, This contains information about the VPN you are connected to
- wlp2s0 — [Wireless on PCI] This is the main interface that is connected to the WIFI of your Local network
Keep in mind that inet address on each block is your IP address.
Since you’re connected to your Wifi, you have to use the last one.
How to download a file using Linux — Terminal?
One fine day my boss sent a bunch of downloadable links to me and asked me to download and wrap them in a Zip file and send it back to him. Kind of junk work that he was lazy to do. So, he handed over it to me. I thought it would be easy work, but then I realized that it has 100+ Downloadable links 🥲.
Activating Zen mode, I started searching for a way to automate this. This is when I encounter about
wget command. This terminal command is used to download a resource from a link.
wget command is highly flexible and can be used in scripts, and cron jobs. As
wget is non-interactive, it can independently download resources in the background and does not require a user to be active or logged in.
The following command will download an image from the w3schools website in your current folder.
You can pass another argument to specify the destination folder where the file should be downloaded.
wget https://www.w3schools.com/html/img_chania.jpg /home/user/downloads/pics/
I wrote a script to download all the files using
wget command and handed over them to my boss in just 15 minutes. He was literally amazed.
How to find out if your system is connected to the internet using a terminal command?
I’m sure that everyone would have this issue at least once in their lifetime.
My Laptop is connected to wifi. But why I’m not able to access the internet whereas the people around me are. By default, most people used to disconnect and re-connect to the same/different wifi network. 99% of the time this try will result in failure and people end up facing a “ Hmm. We’re having trouble finding that site.” message in Firefox or “ No internet” with a dinosaur game in Chrome.
This is when you all should be patient to figure out the issue. You need to ensure if it’s the issue with your system or your browser. You have to figure out if you’re able to access the internet without using a browser.
You can achieve this by using
ping terminal command. Eg.
Ping Command is used to check the network connectivity. This command takes the URL or IP address as as argument and sends data packets to that specified address and prints the response from the server with transition time. It will print the response continuously until you cancel that process (with CTRL + C). Finally it will return the following details.
- Minimum Time taken to receive a response
- Average Time taken to receive a response
- Maximum Time taken to receive a response
We can specify the number of packets to send using the -c flag.
ping google.com -c 10
And we can specify the packet size also using the -s flag
ping google.com -s 40
We can also specify the next request time using -i flag
ping google.com -i 2
and many more.
After executing the above command, hopefully you should be able to find if your system is connected to the internet. Most probably, your browser will be the culprit. Reinstalling the browser will fix this issue.
How to find the IP Address of a Website?
Before we move on, you should be able to answer
What is DNS?
DNS stands for Domain Name System. Every website we use has a domain (Eg. google.com, facebook.com). Each of these domain names will point to particular IP address of a server. DNS is basically a system that has a table that maps each domain with the IP address.
It’s time to move back on track to find the IP address of the site.
Linux has a powerful command called
nslookup (stands for “Name Server Lookup”) is a command to query the DNS server. It is a network administration tool for querying the Domain Name System (DNS) to obtain domain name or IP address mapping or any other specific DNS record. System Admins and DevOps use it to troubleshoot DNS-related problems.
How to Know a Logged-In User?
As such any operating system, Linux also supports multiple users and user management. Each time we can log in as a different user.
who command can be used to know which user we have been logged in as.
In this article, we have learnt about the basic networking commands in Linux.
Subscribe to my newsletter to receive more such insightful articles that get delivered straight to your inbox.
Originally published at https://www.gogosoon.com on December 7, 2022.