- Command:
ip a
orifconfig
- Purpose: Display all network interfaces and their IP addresses.
- Purpose: Advanced IP address and routing configuration.
- Add an IP Address:
sudo ip addr add 192.168.1.100/24 dev eth0
- Add a Route:
sudo ip route add 192.168.2.0/24 via 192.168.1.1
- Delete a Route:
sudo ip route del 192.168.2.0/24
- Command: Edit
/etc/network/interfaces
: or usenmcli
- Purpose: Configure a static IP address.
- Example:
Edit
/etc/network/interfaces
:Add:sudo nano /etc/network/interfaces
auto eth0 iface eth0 inet static address 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.1
- Command**:
ping <URL>
- Purpose**: Test connectivity to a remote host.
- Example: To stop after 5 packets:
ping -c 5 google.com #-c = count
- Command:
traceroute <URL>
ortracepath <URL>
- Purpose: Trace the path packets take to reach a destination.
- Command:
nslookup <URL>
ordig <URL>
- Purpose: Query DNS records for a domain.
- Command:
sudo systemd-resolve --flush-caches
- Purpose: Clear the local DNS cache.
- Purpose: Monitor DNS queries in real-time.
- Command:
sudo dnstop eth0
- Command:
netstat -tuln
orss -tuln
- Purpose: Display open ports and listening services.
- Purpose: Advanced socket statistics.
- Command:
ss -tulnp
- Advanced Options:
- Show established connections:
ss -tun state established
- Filter by port:
ss -tun sport = :80
- Show established connections:
- Command:
nmap
- Purpose: Scan a network for active hosts and open ports.
- Example:
Scan a specific IP for open ports:
nmap -sP 192.168.1.0/24 #-Sp (scan port) <ipv4/netmask>
nmap 192.168.1.1
- Purpose: Perform detailed network discovery and vulnerability scanning.
- Command:
sudo nmap -A -T4 <target>
-A
: Enable OS detection, version detection, script scanning, and traceroute.-T4
: Aggressive timing template.
- Advanced Examples:
- Scan for UDP services:
sudo nmap -sU <target>
- Scan with a specific NSE script:
sudo nmap --script=http-title <target>
- Scan for UDP services:
- Command:
ip route
orroute -n
- Purpose: Display the routing table.
- Command:
tcpdump -i eth0
- Purpose: Capture and analyze network packets.
- Example:
`` `
Capture only HTTP traffic:
tcpdump -i eth0 port 80
- Advanced Usage: Save packets to a file and analyze them later.
- Command:
sudo tcpdump -i eth0 -w capture.pcap
-i eth0
: Capture on interfaceeth0
.-w capture.pcap
: Save packets tocapture.pcap
.
- Analyze the file:
tcpdump -r capture.pcap
- Purpose: Simulate network latency, packet loss, and bandwidth limits.
- Add Latency:
sudo tc qdisc add dev eth0 root netem delay 100ms
- Add Packet Loss:
sudo tc qdisc add dev eth0 root netem loss 10%
- Limit Bandwidth:
sudo tc qdisc add dev eth0 root tbf rate 1mbit burst 32kbit latency 400ms
- Remove Rules:
sudo tc qdisc del dev eth0 root
- Purpose: Check SSL/TLS certificates and connections.
- Command:
openssl s_client -connect google.com:443
- Advanced Options:
- Check certificate expiration:
openssl s_client -connect google.com:443 2>/dev/null | openssl x509 -noout -dates
- Test specific TLS version:
openssl s_client -connect google.com:443 -tls1_2
- Check certificate expiration:
- Purpose: Automate interactive network commands (e.g., SSH, Telnet).
- Example Script:
#!/usr/bin/expect spawn ssh [email protected] expect "password:" send "your_password\r" interact
- Save and run:
./script.exp
- Purpose: Measure raw network throughput.
- Server Side:
nc -l -p 5000 > /dev/null
- Client Side:
dd if=/dev/zero bs=1M count=100 | nc <server_ip> 5000
- Purpose: Analyze NetFlow data.
- Command:
nfdump -r <flow_file>
- Advanced Options:
- Filter by IP:
nfdump -r <flow_file> 'host 192.168.1.1'
- Filter by IP:
- Command:
iftop -i eth0
- Purpose: Monitor real-time bandwidth usage.
- Purpose: Real-time bandwidth monitoring.
- Command:
sudo iftop -i eth0
- Advanced Options:
- Filter by IP:
sudo iftop -F 192.168.1.0/24 -i eth0
- Display port numbers:
sudo iftop -P -i eth0
- Filter by IP:
-
Command:
curl -I <https://<url>
-
Purpose: Test HTTP/HTTPS connectivity and fetch web content.
-
Example:
Fetch full content:
curl https://google.com
- Purpose: Filter and capture HTTP traffic.
- Command:
sudo ngrep -d eth0 -W byline "GET|POST"
- Advanced Options:
- Capture HTTPS traffic (decrypt with SSL key):
sudo ngrep -d eth0 -W byline -q "GET|POST" port 443
- Capture HTTPS traffic (decrypt with SSL key):
- Command:
arp -a
- Purpose: Display the ARP table (IP to MAC address mappings).
- Command:
sudo systemctl restart networking
- Purpose: Restart the network service to apply changes.
- Command:
speedtest-cli
- Purpose: Test internet speed.
- Command:
sudo ufw status
orsudo iptables -L
- Purpose: Display firewall rules.
- Command:
mtr <URL>
- Purpose: Combine
ping
andtraceroute
to measure latency.
- Purpose: Combine
ping
andtraceroute
for advanced latency analysis. - Command:
mtr --report <target>
- Advanced Options:
- Set packet size:
mtr --psize 128 <target>
- Use TCP instead of ICMP:
mtr --tcp <target>
- Set packet size:
- Command:
ssh user@<ipv4 IP address>
- Purpose: Connect to a remote server via SSH.
- Purpose: Securely forward traffic through an SSH tunnel.
- Command:
ssh -L <local_port>:<remote_host>:<remote_port> user@<ssh_server>
- Example: Forward local port 8080 to
google.com:80
via an SSH server:ssh -L 8080:google.com:80 [email protected]
- Access
google.com
locally viahttp://localhost:8080
.
- Command:
netstat -s
- Purpose: Display network statistics (e.g., packets, errors).
- Command:
ip link show
- Purpose: Display MAC addresses of network interfaces.