Table of Contents
- dig
- host
- hostname
- ip addr
- nslookup
- Ping
- Traceroute
- wget
- whois
- References
Understanding networking commands is always beneficial, and knowledge on networking is crucial for running servers, cloud services, network systems, and many more. Let's see some of the important Linux network commands.
dig
dig
is DNS lookup utility for Linux. It stands for Domain Information Groper. This command is commonly used by sysadmins and network engineers to troubleshoot DNS-related issues. It's quite a handy tool if you need to gather DNS-related information about a particular domain. Let's take a look at an example.
dig wordpress.com
Response:
; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> wordpress.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38564
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;wordpress.com. IN A
;; ANSWER SECTION:
wordpress.com. 300 IN A 192.0.78.17
wordpress.com. 300 IN A 192.0.78.9
;; Query time: 20 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Mon Jan 01 06:00:00 CET 2024
;; MSG SIZE rcvd: 74
Explanation:
- The query to wordpress.com was successful; and we received two IPv4 addresses (A records) associated with the website: 192.0.78.17 and 192.0.78.9
- The query took 20 ms
- The DNS server used for the query was 127.0.0.53 (UDP)
- This query was conducted on Mon Jan 01 06:00:00 CET 2024
host
host
is a good DNS (Domain Name System) lookup utility tool. Let's look one example:
$ host wordpress.com
wordpress.com has address 192.0.78.9
wordpress.com has address 192.0.78.17
wordpress.com mail is handled by 10 mx2.ams.automattic.com.
wordpress.com mail is handled by 10 mx1.dfw.automattic.com.
Here, we've queried the command host on domain wordpress.com; there are couple of interesting information here
- wordpress.com has address 192.0.78.9, and also resolves to the IP address 192.0.78.17. Note: Multiple IP addresses can be associated with a single domain for load balancing purpose.
- The mail servers for wordpress.com are handled by automattic.com. There are two mail exchange servers, potentially in two different locations: ams and dfw, both having the same priority of 10.
hostname
To see system's host name use the hostname
command.
$ hostname
Or, you can echo
an environment variable as mentioned below:
$ echo $HOSTNAME
ip addr
This network command is important, which provides detailed information about IP addresses associated to all network interfaces on your computer.
$ ip addr
nslookup
The nslookup command queries a DNS server to retrieve information about the domain.
$ nslookup amaharjan.de
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: amaharjan.de
Address: 104.219.248.46
Explanation:
- Server: The query was directed to a DNS server located at the IP address 127.0.0.53, which is my local machine.
- 127.0.0.53#53: This is IP address and port of the DNS server being queried. Note: DNS uses
53
as the port number. - Address 104.219.248.46: Indicates IP address of amaharjan.de.
Ping
Ping stands for Packet Internet Groper. It is one of the most commonly used TCP/IP commands to check the network connectivity of a system.
$ ping amaharjan.de
PING amaharjan.de (104.219.248.46) 56(84) bytes of data.
64 bytes from server139-2.web-hosting.com (104.219.248.46): icmp_seq=1 ttl=46 time=164 ms
64 bytes from server139-2.web-hosting.com (104.219.248.46): icmp_seq=2 ttl=46 time=163 ms
...
Explanation:
- PING amaharjan.de (104.219.248.46) 56(84) bytes of data.
- amaharjan.de resolves to the IP address 104.219.248.46, with 56 bytes of data being sent, along with an additional 28 bytes of data as a header.
- 64 bytes of data were received.
- "icmp_seq" represents a sequence number, i.e., 1, 2, 3, etc.
- "Time=164 ms" represents the time it took for the packet to travel to the destination and back. It is measured in milliseconds (ms).
- TTL stands for Time to Live, which represents the maximum number of hops (routers) the packet can traverse before being discarded.
Traceroute
When you visit a website, the data has to travel along a specific path from your system (let's call it point A) to the destination website (point B). The traceroute command, a "network diagnostics tool," identifies the route that packets take between your system and the destination system.
It is also helpful to locate point of failure.
$ traceroute example.com
Here is an example of what a response might look like:
traceroute to example.com (###.###.###.###), 30 hops max, 60 byte packets
1 gateway1.provider.com (###.###.###.###) 2.944 ms 2.887 ms 2.868 ms
2 loopback1.0002.example.net (###.###.###.###) 8.577 ms 8.557 ms 8.537 ms
3 ae19-0.0002.router1.example.net (###.###.###.###) 8.513 ms 8.493 ms 8.475 ms
4 ae1-0.0001.router2.example.net (###.###.###.###) 8.463 ms ae0-0.0003.router3.example.net (###.###.###.###) 8.489 ms 8.468 ms
5 ae3-0-gateway.example.net (###.###.###.###) 8.394 ms ae2-100-gateway.example.net (###.###.###.###) 8.366 ms ae3-0-gateway.example.net (###.###.###.###) 8.359 ms
6 ###.###.###.### (###.###.###.###) 18.718 ms * ###.###.###.### (###.###.###.###) 21.430 ms
7 * ###.###.###.### (###.###.###.###) 98.802 ms ###.###.###.### (###.###.###.###) 96.556 ms
8 ###.###.###.### (###.###.###.###) 183.759 ms 180.158 ms ###.###.###.### (###.###.###.###) 170.844 ms
9 ###.###.###.### (###.###.###.###) 180.115 ms 183.690 ms 183.672 ms
10 ###.###.###.### (###.###.###.###) 173.838 ms 173.822 ms 176.006 ms
11 ###.###.###.### (###.###.###.###) 170.784 ms 175.973 ms 175.894 ms
wget
Occasionally, you might need to download files from the internet or a network. This is when the wget Linux network command becomes useful.
For example, if you wish to download an image from the URL https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Tux.svg/398px-Tux.svg.png. You can do the following:
$ wget https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Tux.svg/398px-Tux.svg.png
whois
The whois
tool is used for querying registered internet domain names . It is quite useful for inquire domain ownership.
First, let's install it:
$ sudo apt get install whois
$ whois amaharjan.de
Domain: amaharjan.de
Nserver: dns1.namecheaphosting.com
Nserver: dns2.namecheaphosting.com
Status: connect
Changed: 2022-12-23T16:06:55+01:00
Explanation:
- Domain: Is the registered domain name.
- Nserver: Stands for
Name server
. It plays an important role in translating domain names into IP addresses. - Status: Shows connectivity status of the domain.
- Changed: Shows last modified date and time of the domain.
This post is a part of the series called A Linux Crash Course for Absolute Beginners.
References
[Trac00] “Traceroute Command - an overview | ScienceDirect Topics.” https://www.sciencedirect.com/topics/computer-science/traceroute-command (accessed Mar. 13, 2024).