Article by: 31.08.2022
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.
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:
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 184.108.40.206
- 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.
A curl command is very useful. We can use it to send all kinds of requests to external resources. Take a look:
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.
We use a host command to get an IP address of a given domain name. Let’s use it:
Here is the result:
We queried a domain name (info.cern.ch) and we got its IP address (220.127.116.11). So you have learned another simple, yet very useful command.
It’s time for another command - ifconfig. We use it to configure network interfaces. Let’s get started:
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.
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.