Introduction:
In this step-by-step guide, we will explore various networking commands in Linux that are commonly used to troubleshoot and manage network connections. These commands are essential for network administrators and anyone looking to diagnose network-related issues. We will cover commands like Ping, ifconfig, Traceroute, Netstat, dig, ss, nslookup, host, arp, hostname, curl, and wget.
Ping:
- The Ping command is used to test network connectivity between your system and another host. To use Ping, open a terminal and enter the following command:
ping <hostname or IP address>
Replace <hostname or IP address>
with the target you want to ping. You'll see responses indicating the round-trip time and packet loss.
ifconfig:
- The ifconfig command displays information about network interfaces on your system. To list all network interfaces, use:
bifconfig
You'll see details like IP addresses, MAC addresses, and network configuration.
Traceroute:
Traceroute helps trace the route packets take to reach a destination. To use Traceroute, enter:
traceroute <hostname or IP address>
It displays a list of intermediate routers and their response times.
Netstat:
- Netstat provides information about active network connections. To list all network connections, use:
netstat -tuln
This command shows listening ports and established connections.
dig (DNS Lookup):
- Dig is a powerful tool for querying DNS (Domain Name System) servers. To check DNS records for a domain, use:
dig <domain>
It displays DNS-related information for the specified domain.
ss:
- The ss command is an alternative to netstat for displaying network socket information. To list all sockets, use:
ss -tuln
It shows socket details like netstat.
nslookup and host:
- Nslookup and host are used for DNS-related tasks. To query DNS records for a domain, use:
nslookup <domain>
or
host <domain>
Both commands provide DNS information for the given domain.
arp:
- Arp is used to display and manipulate the ARP (Address Resolution Protocol) cache. To view the ARP cache, use:
arp
Hostname:
- The hostname command displays the system's hostname. To check your hostname, simply enter:
hostname
Curl:
- Curl is a versatile tool for transferring data over various protocols. To download a webpage, use:
curl -o index.html www.example.com
This saves the HTML content of the specified URL to a file named index.html.
wget:
- Wget is a command-line utility for downloading files. To mirror a website recursively, use:
wget --mirror www.example.com
This downloads the entire website for offline viewing.