Networking CLI Tools¶
Linux¶
Basic Tools¶
cat /etc/resolv.conf
¶
This file contains the DNS rules for the system.
This is symlinked to /run/systemd/resolve/stub-resolv.conf
on some systems.
You shouldn't edit this file directly.
Using resolvectl status
will display details about the uplink DNS servers that
are currently in use.
ping
¶
Sends ICMP ECHO_REQUEST packets to network hosts.
It's commonly used to check if a host is reachable across an IP network.
ping
Example:¶
ping google.com
traceroute
(tracert on Windows)¶
Shows the route packets take to reach a network host.
It can identify the path and measure transit delays of packets across an IP network.
traceroute
Example:¶
traceroute google.com
nslookup
¶
Queries the Domain Name System to obtain domain or IP address mapping.
It's useful for finding out information about domain names and their corresponding IP addresses.
nslookup
Example:¶
nslookup example.com
dig
¶
Similar to nslookup, but provides more detailed information.
It's a tool for querying DNS name servers.
dig
Example:¶
dig @8.8.8.8 google.com
dig google.com A +short
A
records for google.com
.
* +short
: This flag makes dig
only output the IP addresses.
netstat
¶
Deprecated in favor of ss
.
Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
netstat
Example:¶
netstat -tuln
ifconfig
¶
Deprecated in favor of the ip
command.
Configures network interfaces.
It can display information about the current network interface configuration or set up an interface.
ifconfig
Example:¶
ifconfig eth0
ip
¶
This utility is used to show and manipulate routing, devices, policy routing, and tunnels.
ip has largely replaced ifconfig.
ip
Example:¶
ip addr show
To show a more brief output:
ip -br addr
ip route
# or
ip r
ethtool
¶
ethtool
is used to query or control network driver and hardware settings.
nmap
¶
Network exploration tool and security scanner.
It's used to discover hosts and services on a computer network, thus building a "map" of the network.
nmap
Example:¶
nmap -p 22,80,443 192.168.1.1
Scan a Range of IP addresses with nmap¶
You can use nmap to map a network.
Mapping a network with nmap can look something like this:
nmap -sP 192.168.200.100-254 # Scan only 100-254
nmap -sP 192.168.200.0/24 # Scan the whole range 1-254
-sP
(or -sn
) option does not use a port scan. This only checks if the hosts are responding.Say that command specified that three hosts were responding.
Run an aggressive scan on those three hosts:
nmap -A 192.168.200.101-103
tcpdump
¶
A network traffic analyzer or sniffer.
It captures packets off a network interface and interprets them for you.
tcpdump
Example:¶
tcpdump -i eth0 port 80
wget
/curl
¶
Command-line utilities for downloading files from the web.
curl is also capable of uploading data and supports a wide variety of protocols.
Example with curl
:¶
curl -o example.html http://example.com
ssh
¶
Secure Shell is a protocol used to securely log onto remote systems.
It's the command-line tool for accessing remote machines.
ssh
Example:¶
ssh user@192.168.1.10
telnet
¶
A network protocol used on the Internet or local area networks to provide
a bidirectional interactive text-oriented communication facility using a virtual terminal connection.
Not secure compared to SSH but useful for troubleshooting.
telnet
Example:¶
telnet example.com 80
mtr
¶
Combines the functionality of traceroute and ping into one diagnostic tool.
It displays the route and measures each hop's transit delays.
mtr
Example:¶
mtr google.com
Each of these tools has multiple flags and options you can use to refine your commands according to your specific needs.
Exercises¶
- Use
ping
to check the connectivity to a local and remote server. - Use
traceroute
to see the path taken to an external website. - Run
nslookup
to find out the authoritative DNS servers for a domain. - Explore
nmap
by scanning your local network for open ports. - Capture HTTP traffic with
tcpdump
.
Many of these tools can be misused for probing networks without permission, which could be illegal and unethical.
Always have proper authorization before scanning networks and hosts.
Questions¶
How can you use nmap to scan for a specific service running on a range of IP addresses?
* You can scan for a specific service with nmap by specifying the service's port number and a CIDR notation to denote the IP range (a subnet).
* For example, if you want to scan for SSH servers running on the IP range 192.168.1.0/24,
you could use:
nmap -p 22 192.168.1.0/24