Table of contents
If you are into DevOps or having a midlife crisis because of the router not working, networking commands are the way to go. These commands are necessary for troubleshooting, monitoring, and configuring network-related aspects of systems. So, let's dive in and see what's all the fuss about.
ping
the ping
command is used for testing connectivity between two hosts. If you think you are getting slower responses from a server, its a good idea to ping that server and see if there are any issues. The output will show h
Usage:
$ ~ ping google.com
Example Output:
ping google.com (172.217.5.78) 56(84) bytes of data.
64 bytes from 172.217.5.78: icmp_seq=1 ttl=117 time=25.0 ms
64 bytes from 172.217.5.78: icmp_seq=2 ttl=117 time=26.7 ms
64 bytes from 172.217.5.78: icmp_seq=3 ttl=117 time=24.8 ms
64 bytes from 172.217.5.78: icmp_seq=4 ttl=117 time=28.1 ms
ip command
The ip
command is used to configure and display information about network interfaces on a system.
Usage:
To show information about network interfaces:
ip link show
To show IP addresses:
ip addr show
To assign an IP address to an interface:
ip addr add 192.168.1.2/24 dev eth0
To bring an interface up or down:
ip link set dev eth0 up
ip link set dev eth0 down
To change the MAC address of an interface:
ip link set dev eth0 address 00:11:22:33:44:55
To show routing table:
ip route show
To add or remove a route:
ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0
ip route del 192.168.2.0/24
To show TCP/UDP socket information:
ip -s -s link show
Read More about this command. Here is the Cheatsheet by Redhat.
traceroute
The traceroute
command is used to trace the route that packets take from your computer to a destination IP address or domain. It's a network diagnostic tool that helps identify the path that data packets follow across the internet or a local network.
Usage:
$ ~ traceroute google.com
$ ~ traceroute 8.8.8.8
The command sends packets with increasing Time-to-Live (TTL) values to the destination.
Each router along the path decrements the TTL value, and when TTL reaches zero, the router sends an ICMP Time Exceeded message back to the source.
The source then displays information about each hop along the route, including the IP address and round-trip time (RTT).
Example Output:
traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
1 192.168.1.1 (192.168.1.1) 1.234 ms 2.345 ms 3.456 ms
2 isp-router (203.0.113.1) 4.567 ms 5.678 ms 6.789 ms
3 some-other-router (198.51.100.1) 7.890 ms 8.901 ms 9.012 ms
4 destination-router (93.184.216.34) 10.123 ms 11.234 ms 12.345 ms
In the example:
Each line represents a hop in the route.
The first column shows the hop number.
The second column shows the hostname or IP address of the router.
The following columns show the round-trip time (RTT) for three separate packets sent to that hop.
ss command
The ss
command is a replacement for the deprecated netstat
command on Linux systems. It is used to display information about socket connections, routing tables, network interfaces, and more.
Usage:
$ ~ ss -tunap
Example Output:
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:22 0.0.0.0:* users:(("sshd",pid=1234,fd=3))
ESTAB 0 0 192.168.1.2:54321 203.0.113.5:80
In the example, the first line shows a listening socket (LISTEN
) on port 22 (SSH) with the process sshd
listening on it.
The second line shows an established socket (ESTAB
) with the local address 192.168.1.2 and port 54321 connected to the remote address 203.0.113.5 and port 80.
Here are the options for the ss
command.
-t
: Display TCP socket information.-u
: Display UDP socket information.-n
: Show numeric addresses.-a
: Display all sockets.-p
: Display process information.
nslookup
The nslookup
command is a network troubleshooting tool used to query Domain Name System (DNS) servers and obtain information about domain names, IP addresses, and related DNS records.
Usage:
To lookup the IP address for a domain:
nslookup
google.com
To lookup the authoritative DNS servers for a domain:
nslookup -type=ns
google.com
To lookup the mail exchange (MX) records for a domain:
nslookup -type=mx
google.com
To find domain name from an IP address:
nslookup 8.8.8.8
To change DNS server:
nslookup
example.com
8.8.4.4
Interactive mode:
nslookup
> set type=mx
curl/wget
Both curl
and wget
are command-line tools for transferring data with URLs. They are commonly used in scripts, automation, and command-line environments for downloading files or interacting with web services.
Usage: (curl)
Basic GET Request:
Save File:
curl -o output.html
http://example.com/file.html
Follow Redirects:
curl -L
http://example.com
Send POST Data:
curl -u username:password
http://example.com
Example Output:
➜ curl -o output.html http://example.com/file.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1256 100 1256 0 0 1703 0 --:--:-- --:--:-- --:--:-- 1701
Usage: (wget)
Basic GET Request:
Save File:
Recursive Download (with -r):
wget -r -np -nH --cut-dirs=1
http://example.com/files/
Limit Download Speed:
wget --limit-rate=100k
http://example.com/largefile.iso
Continue Partial Download:
wget -c
http://example.com/largefile.zip
Example Output:
➜ wget https://www.7-zip.org/a/7z2301-x64.exe
--2024-01-26 14:26:47-- https://www.7-zip.org/a/7z2301-x64.exe
Resolving www.7-zip.org (www.7-zip.org)... 64:ff9b::310c:caed, 49.12.202.237
Connecting to www.7-zip.org (www.7-zip.org)|64:ff9b::310c:caed|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1589510 (1.5M) [application/octet-stream]
Saving to: ‘7z2301-x64.exe’
7z2301-x64.exe 100%[===========================================>] 1.52M 361KB/s in 4.7s
2024-01-26 14:26:53 (331 KB/s) - ‘7z2301-x64.exe’ saved [1589510/1589510]
Conclusion
I think that's it for this one. The commands mentioned in the article are essential tools for DevOps engineers working with networking tasks in a Linux environment. These commands provide powerful capabilities for network troubleshooting, configuration, and monitoring. Share this article with your friends. See you in the next one.