LinuxNetwork/InternetApril 3, 20210Learn Linux Basic Networking Commands

At any given time when using your PC which is connected to a router, you will be part of a network. Whether you are in an office environment or simply working from home, your computer will be in a network.

 

What is a Computer Network?

A computer network is defined as a group of 2 or more computers that are connected and can electronically communicate with each other. The computers are identified using their hostnames, IP, and mac addresses.

A simple home or office network is referred to as a LAN, short for Local Area Network. A LAN covers a small area such as a home, office, or restaurant network. In contrast, a WAN (Wide Area Network) spans a large geographical region. WAN is mostly used to connect various sites such as office buildings in different locations.

 

1. hostname Command

The hostname command displays the hostname of a Linux system. This is usually set or configured during the installation.
It also is a name that is given to a computer that attached to the network that uniquely identifies over a network and thus allows it to be accessed without using its IP address. To check the hostname, run the command:

$ hostname

The basic syntax for the hostname command is:

# hostname [options] [new_host_name]

If the host name can be resolved, you can display the network address(es) (IP address) of the host name with the -i flag and the -I option establishes all configured network interfaces and shows all network addresses of the host.

$ hostname -i
$ hostname -I

an other useful hostname command option :

$ hostname -d
$ hostname -f
$ hostname -A

2. ping Command

Short for packet internet groper, with ping command we can use to check connectivity between 2 systems or servers.
It sends out an ICMP echo request to a remote host and waits for a reply. If the host is up, the echo request bounces off the remote host and is sent back to the source informing the user that the host is up or available.

The ping command takes the syntax shown.

$ ping options IP address
$ ping www.google.com

PING www.google.com (172.217.166.164) 56(84) bytes of data.
64 bytes from bom07s20-in-f4.1e100.net (172.217.166.164): icmp_seq=1 ttl=57 time=2.40 ms
64 bytes from bom07s20-in-f4.1e100.net (172.217.166.164): icmp_seq=2 ttl=57 time=2.48 ms
64 bytes from bom07s20-in-f4.1e100.net (172.217.166.164): icmp_seq=3 ttl=57 time=2.43 ms
64 bytes from bom07s20-in-f4.1e100.net (172.217.166.164): icmp_seq=4 ttl=57 time=2.35 ms
^C
— www.google.com ping statistics —
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 2.353/2.420/2.484/0.058 ms

Tips : You can specify the number of ECHO_REQUEST’s to be sent after which ping exits, using the -c flag as shown (in this case the ping test will stop after sending 5 packets).

$ ping -c 5 www.google.com

PING www.google.com (172.217.163.36) 56(84) bytes of data.
64 bytes from maa05s01-in-f4.1e100.net (172.217.163.36): icmp_seq=1 ttl=56 time=29.7 ms
64 bytes from maa05s01-in-f4.1e100.net (172.217.163.36): icmp_seq=2 ttl=56 time=29.7 ms
64 bytes from maa05s01-in-f4.1e100.net (172.217.163.36): icmp_seq=3 ttl=56 time=29.4 ms
64 bytes from maa05s01-in-f4.1e100.net (172.217.163.36): icmp_seq=4 ttl=56 time=30.2 ms
64 bytes from maa05s01-in-f4.1e100.net (172.217.163.36): icmp_seq=5 ttl=56 time=29.6 ms

— www.google.com ping statistics —
5 packets transmitted, 5 received, 0% packet loss, time 4004ms
rtt min/avg/max/mdev = 29.499/29.781/30.285/0.307 ms

Tips : The -i flag allows you to set interval in seconds between sending each packet, the default value is one second.

$ ping -i 3 -c 5 www.google.com

 

3. traceroute Command

The traceroute command displays the route that an ICMP ping packet takes from your device to the destination host or server. It displays the IP addresses of devices that the packet hops through before getting to the remote destination.

In line 2 the output shows an asterisk sign * in the round trip. This is an indicator that the packet was dropped and no response was received. This shows that the ping packet was dropped by the router, and this could be for a variety of reasons such as network congestion.

Traceroute command is a cool diagnostic command that you can use to troubleshoot the network where the ping command gives you failed results. It shows the device at which the packets are being dropped.

$ traceroute google.com

 

4. mtr Command

The mtr (my traceoute) command combines the functionalities of the ping and traceroute command. with the mtr command, we can display a host of statistics including the host that each packet travels through, and response times for all the network hops. (read more here about mtr command)

$ mtr google.com

 

5. ifconfig Command

With the ifconfig command, we can see a list of the network interfaces attached to the PC along with other statistics such as the IP addresses associated with each interface, subnet mask, and MTU to mention just a few.

$ ifconfig

 

 

 

Leave a Reply