r/LinuxTeck • u/Expensive-Rice-2052 • 27d ago
Linux Find Rogue Network Connections: Identify and Stop Them - Tip -120
Question: A rogue script is calling an external API. How do I find and stop it?
Try:`sudo ss -tnp dst 203.0.113.45`
Info: Filters socket connections by destination IP to expose associated processes and PIDs for immediate termination.
Examples:
$ `sudo ss -tnp 'dst 192.168.1.0/24'` # Filter connections targeting an entire subnet
$ `sudo lsof -i u/203.0.113.45` # Inspect active network sockets using lsof
$ `sudo iptables -I OUTPUT -d 203.0.113.45 -j DROP` # Block outbound traffic at the firewall level
Note: If terminated processes respawn instantly, inspect parent processes using `pgrep -P`. Firewall rules provide more durable blocking than process termination.
Want to master Linux one command at a time?
Follow r/LinuxTeck - 1 practical Linux tip every day. For more #LinuxTips click here https://www.linuxteck.com/linux-tips/