Article by: 31.08.2022
Linux - useful network commands
Linux has a strong presence in all kinds of networks. It is the most common operating system used to run servers and various network devices.
While working with Linux, sooner or later you will need to use its networking abilities. And that’s why you need the basic knowledge of network commands. So let’s take a look at some examples.
ping command
We use the ping command to diagnose a network connection between our own machine and an external one. We can use it to get some useful information:
- How many packets were sent and how many packets were lost
- What’s the IP address of the domain
Here is a simple example of a ping command:
ping google.com
We send a query to the google.com domain. And here is the result:
There is some interesting information:
- The IP address of google.com is 216.58.215.78
- 5 packets were sent
- 5 packets were received
- 0 were lost
Using the above data we can say that there is a working and stable connection between our own computer and google.com. So a ping command is a simple and quick way to diagnose a network connection.
curl command
A curl command is very useful. We can use it to send all kinds of requests to external resources. Take a look:
curl https://livecode.codenga.com/api/i-shop/products
We send a request to the external URL. And here is the response:
The response is formatted as JSON. It is a very common data exchange format used by all kinds of APIs. In practice we would probably want to limit the amount of data returned by the external API - but that’s beyond the scope of this article.
The most important thing here is to remember the curl command itself. Use it whether you want to get some response from the external URL.
host command
We use a host command to get an IP address of a given domain name. Let’s use it:
host info.cern.ch
Here is the result:
We queried a domain name (info.cern.ch) and we got its IP address (188.184.21.108). So you have learned another simple, yet very useful command.
ifconfig command
It’s time for another command - ifconfig. We use it to configure network interfaces. Let’s get started:
ifconfig
We ran the command on our local computer. Note, that we didn’t use any additional parameters. That means we will get basic information about our local network. Take a look:
We got some interesting data:
- MAC address of our local network interface: 8c:85:90:5e:ca:97
- IP address our our local network interface: 192.168.1.18
- info about subnet mask: 0xffffff00
- info about broadcast address: 192.168.1.255
- status of our network interface: active
That’s only the beginning. This command offers much, much more. And that would be a good topic for another article. For now, just remember this useful command.
What next?
This article is just a short introduction to a fascinating topic of Linux network commands. Wann learn more? Get this Codenga course: Linux - network commands.