Lewati ke konten
Kembali ke Blog

Panduan Lengkap Troubleshooting Jaringan Linux: Ping, Netstat, Nmap, dan Tools Lainnya

· · 9 menit baca

Troubleshooting jaringan adalah skill esensial untuk sysadmin dan developer. Linux menyediakan berbagai tools command line yang powerful untuk diagnose masalah network. Artikel ini membahas penggunaan ping, netstat, nmap, dan tools troubleshooting lainnya secara comprehensive.

Basic Connectivity Test

1. Ping Command

Ping adalah tool paling dasar untuk test connectivity.

# Ping ke host/domain
ping google.com

Ping dengan count spesifik

ping -c 4 google.com

Ping dengan interval

ping -i 2 google.com # Setiap 2 detik

Ping dengan timeout

ping -w 10 google.com # Stop setelah 10 detik

Ping dengan packet size

ping -s 1024 google.com

Flood ping (root only)

sudo ping -f localhost

Audible ping (bunyi beep saat reply)

ping -a google.com

2. Traceroute

Traceroute melacak route yang dilalui packets.

# Basic traceroute
traceroute google.com

Traceroute dengan ICMP (bukan UDP)

traceroute -I google.com

Traceroute dengan TCP port

traceroute -T -p 443 google.com

Limit hops

traceroute -m 15 google.com

Atau gunakan tracepath

tracepath google.com

3. MTR (My Traceroute)

MTR menggabungkan ping dan traceroute.

# Install mtr
sudo apt install mtr    # Debian/Ubuntu
sudo dnf install mtr    # Fedora

Run mtr

mtr google.com

MTR dengan report mode

mtr --report --report-cycles 10 google.com

MTR dengan TCP

traceroute -T google.com

Network Interface Tools

4. ifconfig / ip

# List interfaces (modern)
ip addr show

Atau dengan ifconfig (legacy)

ifconfig

Detail interface spesifik

ip addr show eth0

Statistik interface

ip -s link show eth0

Enable/disable interface

sudo ip link set eth0 up sudo ip link set eth0 down

Set IP address

sudo ip addr add 192.168.1.100/24 dev eth0 sudo ip addr del 192.168.1.100/24 dev eth0

Flush IP addresses

sudo ip addr flush dev eth0

5. ethtool

# Install
sudo apt install ethtool

Cek link status

sudo ethtool eth0

Cek statistics

sudo ethtool -S eth0

Test cable

sudo ethtool -t eth0

Set speed dan duplex

sudo ethtool -s eth0 speed 1000 duplex full autoneg off

Network Connection Tools

6. netstat

# List semua connections
netstat -a

List TCP connections

netstat -at

List UDP connections

netstat -au

List listening ports

netstat -tulpn

List dengan PID

sudo netstat -tulpn | grep :80

Statistics

netstat -s

Routing table

netstat -r

atau:

route -n

Interface statistics

netstat -i

7. ss (Socket Statistics) – Modern Alternative

# List all sockets
ss -a

List TCP sockets

ss -t -a

List UDP sockets

ss -u -a

List listening sockets

ss -tlnp

List dengan process

ss -tlnp | grep :80

Summary

ss -s

Filter by state

ss -t state established

Filter by connection to specific port

ss -t dst :443

Show timer info

ss -t -o

8. lsof (List Open Files)

# List network connections
sudo lsof -i

List TCP

sudo lsof -i TCP

List specific port

sudo lsof -i :80 sudo lsof -i :443

List listening ports

sudo lsof -i -P -n | grep LISTEN

List connections by process

sudo lsof -i -P -n | grep nginx

List IPv4/IPv6 only

sudo lsof -i 4 sudo lsof -i 6

Port Scanning dan Discovery

9. Nmap

Nmap adalah network scanner yang powerful.

# Install
sudo apt install nmap

Scan single host

nmap 192.168.1.1

Scan multiple hosts

nmap 192.168.1.1 192.168.1.2

Scan range

nmap 192.168.1.1-254

Scan subnet

nmap 192.168.1.0/24

Scan dengan port range

nmap -p 1-65535 192.168.1.1

Scan specific ports

nmap -p 22,80,443 192.168.1.1

Scan dengan service detection

nmap -sV 192.168.1.1

OS detection

sudo nmap -O 192.168.1.1

Aggressive scan

sudo nmap -A 192.168.1.1

Stealth scan

sudo nmap -sS 192.168.1.1

UDP scan

sudo nmap -sU 192.168.1.1

Fast scan (100 ports paling umum)

nmap -F 192.168.1.1

Scan dari file

nmap -iL hosts.txt

Output ke file

nmap -oN scan.txt 192.168.1.1 nmap -oX scan.xml 192.168.1.1

Scan dengan script

nmap --script vuln 192.168.1.1

10. nc (Netcat)

Netcat adalah “Swiss Army Knife” untuk networking.

# Test port connectivity
nc -zv hostname 80
nc -zv google.com 443

Test multiple ports

nc -zv google.com 80 443 8080

Create listener

nc -l 8080

Create reverse shell (hati-hati!)

nc -e /bin/bash -l 8080

Send file

nc -w 3 hostname 8080 < file.txt

Receive file

nc -l 8080 > received_file.txt

Port scan

nc -zv 192.168.1.1 1-1024

DNS Tools

11. nslookup

# Query DNS
nslookup google.com

Query specific record

nslookup -query=MX google.com nslookup -query=NS google.com

Query specific nameserver

nslookup google.com 8.8.8.8

12. dig

# Basic query
dig google.com

Query specific record

dig google.com MX dig google.com NS dig google.com TXT

Query dengan detail

dig +trace google.com

Reverse DNS

dig -x 8.8.8.8

Query specific nameserver

dig @8.8.8.8 google.com

Short output

dig +short google.com

Query semua records

dig google.com ANY

13. host

# Simple DNS lookup
host google.com

Lookup specific type

host -t MX google.com

Reverse lookup

host 8.8.8.8

14. whois

# Install
sudo apt install whois

Lookup domain info

whois google.com

Lookup IP info

whois 8.8.8.8

Advanced Network Tools

15. tcpdump

# Install
sudo apt install tcpdump

Capture semua packets

sudo tcpdump

Capture di interface spesifik

sudo tcpdump -i eth0

Capture dengan filter

sudo tcpdump -i eth0 port 80 sudo tcpdump -i eth0 host 192.168.1.100 sudo tcpdump -i eth0 src 192.168.1.100 sudo tcpdump -i eth0 dst 192.168.1.100

Capture dan save ke file

sudo tcpdump -w capture.pcap

Read dari file

sudo tcpdump -r capture.pcap

Capture dengan verbose

sudo tcpdump -v sudo tcpdump -vv sudo tcpdump -vvv

Capture limit

sudo tcpdump -c 100

Capture dengan timestamp

sudo tcpdump -tttt

Filter protocol

sudo tcpdump icmp sudo tcpdump tcp sudo tcpdump udp

Complex filter

sudo tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'

16. Wireshark / tshark

# Install
sudo apt install wireshark tshark

Capture dengan tshark

sudo tshark -i eth0

Capture dengan filter

sudo tshark -i eth0 port 80

Capture ke file

sudo tshark -w capture.pcap

Read file

sudo tshark -r capture.pcap

17. nload

# Install
sudo apt install nload

Monitor traffic

sudo nload

Monitor interface spesifik

sudo nload eth0

18. iftop

# Install
sudo apt install iftop

Monitor bandwidth usage

sudo iftop

Monitor interface spesifik

sudo iftop -i eth0

Monitor port spesifik

sudo iftop -f "port 80"

19. bmon

# Install
sudo apt install bmon

Monitor dengan grafik

sudo bmon

Export ke file

sudo bmon -o ascii > bandwidth.log

Routing Tools

20. route / ip route

# Show routing table
ip route show
# atau:
route -n

Add route

sudo ip route add 192.168.2.0/24 via 192.168.1.1

Delete route

sudo ip route del 192.168.2.0/24

Default route

sudo ip route add default via 192.168.1.1

Show specific route

ip route get 8.8.8.8

21. arp

# Show ARP table
ip neigh show
# atau:
arp -a

Delete ARP entry

sudo ip neigh del 192.168.1.100 dev eth0

Flush ARP cache

sudo ip neigh flush all

Firewall Tools

22. iptables

# List rules
sudo iptables -L
sudo iptables -L -v -n

List dengan line numbers

sudo iptables -L --line-numbers

List specific table

sudo iptables -t nat -L sudo iptables -t mangle -L

Monitor packets

sudo iptables -A INPUT -j LOG

Clear all rules

sudo iptables -F sudo iptables -X sudo iptables -t nat -F sudo iptables -t nat -X

23. nftables

# List ruleset
sudo nft list ruleset

List table spesifik

sudo nft list table inet filter

Monitor

sudo nft monitor

WiFi Tools

24. iw / iwconfig

# List wireless devices
iw dev

Scan networks

sudo iw dev wlan0 scan

Connect (gunakan NetworkManager atau wpa_supplicant untuk full connection)

Show wireless link

iw dev wlan0 link

Legacy: iwconfig

iwconfig iwconfig wlan0

25. wavemon

# Install
sudo apt install wavemon

Monitor WiFi signal

sudo wavemon

Network Testing Scripts

Script: Complete Network Diagnose

#!/bin/bash
# network-diagnose.sh

HOST="$1"

if [ -z "$HOST" ]; then echo "Usage: $0 <hostname/IP>" exit 1 fi

echo "========================================" echo "Network Diagnose Report for: $HOST" echo "Date: $(date)" echo "========================================"

echo -e "\n--- Basic Connectivity ---" ping -c 4 "$HOST"

echo -e "\n--- Route Trace ---" traceroute -m 15 "$HOST" 2>/dev/null || tracepath "$HOST" 2>/dev/null

echo -e "\n--- DNS Resolution ---" dig +short "$HOST"

echo -e "\n--- Port Scan (Top 20) ---" nmap -F "$HOST" 2>/dev/null || echo "nmap not installed"

echo -e "\n--- Report Complete ---"

Script: Monitor Network Health

#!/bin/bash
# network-monitor.sh

LOGFILE="/var/log/network-health.log" HOSTS=("8.8.8.8" "1.1.1.1" "google.com")

for host in "${HOSTS[@]}"; do if ping -c 1 -W 2 "$host" > /dev/null 2>&1; then echo "[$(date)] $host: UP" >> "$LOGFILE" else echo "[$(date)] $host: DOWN" >> "$LOGFILE" fi done

Troubleshooting Common Network Issues

1. No Internet Connectivity

# 1. Cek interface
ip addr show

2. Cek gateway

ip route | grep default

3. Test gateway

ping $(ip route | grep default | awk '{print $3}')

4. Test DNS

ping 8.8.8.8

5. Cek DNS resolution

dig google.com

6. Cek resolv.conf

cat /etc/resolv.conf

7. Restart networking

sudo systemctl restart NetworkManager

atau:

sudo systemctl restart networking

2. Slow Network

# 1. Test speed dengan iperf3
sudo apt install iperf3
iperf3 -c iperf.he.net

2. Cek bandwidth usage

sudo iftop -i eth0

3. Cek errors

ip -s link show eth0

4. Test dengan mtr

mtr --report google.com

5. Cek duplex/speed

sudo ethtool eth0

3. Connection Refused

# 1. Cek apakah service running
sudo systemctl status nginx

2. Cek listening ports

sudo ss -tlnp | grep :80

3. Test dengan nc

nc -zv localhost 80

4. Cek firewall

sudo iptables -L | grep 80 sudo ufw status | grep 80

5. Check logs

sudo tail -f /var/log/nginx/error.log

4. DNS Not Working

# 1. Cek resolv.conf
cat /etc/resolv.conf

2. Test dengan dig

dig @8.8.8.8 google.com

3. Cek DNS service

sudo systemctl status systemd-resolved

4. Flush DNS cache

sudo systemd-resolve --flush-caches

5. Test hosts file

ping localhost cat /etc/hosts

Kesimpulan

Troubleshooting jaringan Linux memerlukan kombinasi tools yang tepat dan pemahaman tentang networking concepts. Dengan menguasai tools di atas, Anda bisa:

  1. Diagnose connectivity issues dengan ping, traceroute, mtr
  2. Analyze network traffic dengan tcpdump, wireshark
  3. Scan dan audit network dengan nmap, nc
  4. Monitor performance dengan nload, iftop, bmon
  5. Troubleshoot DNS dengan dig, nslookup
  6. Manage firewall dengan iptables, nftables

Latihan secara regular dengan scenario troubleshooting untuk mempertajam skill Anda. Network troubleshooting adalah skill yang selalu berguna dalam karir IT apapun.

Ditulis oleh

Hendra Wijaya

Tinggalkan Komentar

Email tidak akan ditampilkan.