$npx -y skills add chaterm/terminal-skills --skill network-toolsLinux network tools and diagnostics
| 1 | # Network Tools and Diagnostics |
| 2 | |
| 3 | ## Overview |
| 4 | Linux network diagnostics, port scanning, traffic analysis and other tool usage skills. |
| 5 | |
| 6 | ## Network Configuration |
| 7 | |
| 8 | ### View Configuration |
| 9 | ```bash |
| 10 | # IP address |
| 11 | ip addr |
| 12 | ip a |
| 13 | ifconfig # Legacy command |
| 14 | |
| 15 | # Routing table |
| 16 | ip route |
| 17 | route -n |
| 18 | netstat -rn |
| 19 | |
| 20 | # DNS configuration |
| 21 | cat /etc/resolv.conf |
| 22 | systemd-resolve --status |
| 23 | ``` |
| 24 | |
| 25 | ### Configure Network |
| 26 | ```bash |
| 27 | # Temporary IP configuration |
| 28 | ip addr add 192.168.1.100/24 dev eth0 |
| 29 | ip addr del 192.168.1.100/24 dev eth0 |
| 30 | |
| 31 | # Enable/Disable interface |
| 32 | ip link set eth0 up |
| 33 | ip link set eth0 down |
| 34 | |
| 35 | # Add route |
| 36 | ip route add 10.0.0.0/8 via 192.168.1.1 |
| 37 | ip route del 10.0.0.0/8 |
| 38 | ``` |
| 39 | |
| 40 | ## Connectivity Testing |
| 41 | |
| 42 | ### ping |
| 43 | ```bash |
| 44 | ping hostname |
| 45 | ping -c 4 hostname # Send 4 packets |
| 46 | ping -i 0.2 hostname # 0.2 second interval |
| 47 | ping -s 1000 hostname # Specify packet size |
| 48 | ``` |
| 49 | |
| 50 | ### traceroute |
| 51 | ```bash |
| 52 | traceroute hostname |
| 53 | traceroute -n hostname # Don't resolve hostnames |
| 54 | traceroute -T hostname # Use TCP |
| 55 | mtr hostname # Real-time trace |
| 56 | ``` |
| 57 | |
| 58 | ### DNS Query |
| 59 | ```bash |
| 60 | nslookup hostname |
| 61 | dig hostname |
| 62 | dig +short hostname |
| 63 | dig @8.8.8.8 hostname # Specify DNS server |
| 64 | host hostname |
| 65 | ``` |
| 66 | |
| 67 | ## Ports and Connections |
| 68 | |
| 69 | ### ss Command (Recommended) |
| 70 | ```bash |
| 71 | # Listening ports |
| 72 | ss -tlnp # TCP listening |
| 73 | ss -ulnp # UDP listening |
| 74 | ss -tlnp | grep :80 |
| 75 | |
| 76 | # All connections |
| 77 | ss -tanp # TCP connections |
| 78 | ss -s # Statistics |
| 79 | |
| 80 | # Filter |
| 81 | ss -t state established |
| 82 | ss -t dst 192.168.1.1 |
| 83 | ss -t sport = :80 |
| 84 | ``` |
| 85 | |
| 86 | ### netstat Command |
| 87 | ```bash |
| 88 | netstat -tlnp # TCP listening |
| 89 | netstat -ulnp # UDP listening |
| 90 | netstat -anp # All connections |
| 91 | netstat -s # Statistics |
| 92 | ``` |
| 93 | |
| 94 | ### lsof Network |
| 95 | ```bash |
| 96 | lsof -i # All network connections |
| 97 | lsof -i :80 # Specific port |
| 98 | lsof -i tcp # TCP connections |
| 99 | lsof -i @192.168.1.1 # Specific host |
| 100 | ``` |
| 101 | |
| 102 | ## HTTP Tools |
| 103 | |
| 104 | ### curl |
| 105 | ```bash |
| 106 | # Basic request |
| 107 | curl http://example.com |
| 108 | curl -I http://example.com # Headers only |
| 109 | curl -v http://example.com # Verbose output |
| 110 | |
| 111 | # POST request |
| 112 | curl -X POST -d "data=value" http://example.com |
| 113 | curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://example.com |
| 114 | |
| 115 | # Download |
| 116 | curl -O http://example.com/file.zip |
| 117 | curl -o output.zip http://example.com/file.zip |
| 118 | |
| 119 | # Authentication |
| 120 | curl -u user:pass http://example.com |
| 121 | curl -H "Authorization: Bearer token" http://example.com |
| 122 | ``` |
| 123 | |
| 124 | ### wget |
| 125 | ```bash |
| 126 | wget http://example.com/file.zip |
| 127 | wget -c http://example.com/file.zip # Resume download |
| 128 | wget -r http://example.com # Recursive download |
| 129 | wget --mirror http://example.com # Mirror site |
| 130 | ``` |
| 131 | |
| 132 | ## Packet Capture |
| 133 | |
| 134 | ### tcpdump |
| 135 | ```bash |
| 136 | # Basic capture |
| 137 | tcpdump -i eth0 |
| 138 | tcpdump -i any |
| 139 | |
| 140 | # Filter |
| 141 | tcpdump -i eth0 port 80 |
| 142 | tcpdump -i eth0 host 192.168.1.1 |
| 143 | tcpdump -i eth0 'tcp port 80 and host 192.168.1.1' |
| 144 | |
| 145 | # Save/Read |
| 146 | tcpdump -i eth0 -w capture.pcap |
| 147 | tcpdump -r capture.pcap |
| 148 | |
| 149 | # Display content |
| 150 | tcpdump -i eth0 -A port 80 # ASCII |
| 151 | tcpdump -i eth0 -X port 80 # Hexadecimal |
| 152 | ``` |
| 153 | |
| 154 | ### Traffic Monitoring |
| 155 | ```bash |
| 156 | # Real-time traffic |
| 157 | iftop |
| 158 | iftop -i eth0 |
| 159 | |
| 160 | # By process |
| 161 | nethogs |
| 162 | nethogs eth0 |
| 163 | |
| 164 | # Bandwidth test |
| 165 | iperf3 -s # Server |
| 166 | iperf3 -c server_ip # Client |
| 167 | ``` |
| 168 | |
| 169 | ## Common Scenarios |
| 170 | |
| 171 | ### Scenario 1: Troubleshoot Port Usage |
| 172 | ```bash |
| 173 | # Check port usage |
| 174 | ss -tlnp | grep :8080 |
| 175 | lsof -i :8080 |
| 176 | |
| 177 | # Find process and handle |
| 178 | kill -9 PID |
| 179 | # Or |
| 180 | fuser -k 8080/tcp |
| 181 | ``` |
| 182 | |
| 183 | ### Scenario 2: Test Service Connectivity |
| 184 | ```bash |
| 185 | # TCP port test |
| 186 | nc -zv hostname 80 |
| 187 | telnet hostname 80 |
| 188 | |
| 189 | # HTTP service test |
| 190 | curl -I http://hostname |
| 191 | curl -w "HTTP Code: %{http_code}\nTime: %{time_total}s\n" -o /dev/null -s http://hostname |
| 192 | ``` |
| 193 | |
| 194 | ### Scenario 3: Network Performance Diagnosis |
| 195 | ```bash |
| 196 | # Latency test |
| 197 | ping -c 100 hostname | tail -1 |
| 198 | |
| 199 | # Route analysis |
| 200 | mtr --report hostname |
| 201 | |
| 202 | # Bandwidth test |
| 203 | iperf3 -c server -t 30 |
| 204 | ``` |
| 205 | |
| 206 | ## Troubleshooting |
| 207 | |
| 208 | | Problem | Solution | |
| 209 | |---------|----------| |
| 210 | | Network unreachable | `ping`, `traceroute`, check routing | |
| 211 | | DNS resolution failed | `dig`, `nslookup`, check resolv.conf | |
| 212 | | Port unreachable | `ss -tlnp`, check firewall | |
| 213 | | Connection timeout | `mtr`, `tcpdump` packet capture | |
| 214 | | Insufficient bandwidth | `iftop`, `iperf3` test | |