Sobes.tech
Junior — Middle

How can you determine which ports are open on a server and which IP addresses are connecting to them?

sobes.tech AI

Answer from AI

To identify open ports on a server and the IP addresses connecting to them, you can use the following tools:

  • netstat: shows active connections and listening ports.

    netstat -tulnp
    

    -t — TCP, -u — UDP, -l — listening, -n — show port numbers, -p — process

  • ss — a modern alternative to netstat:

    ss -tulnp
    
  • lsof — shows open files and ports:

    lsof -i -P -n
    
  • For scanning ports from outside, you can use nmap:

    nmap -sT localhost
    

These commands will help you see which ports are open, which processes are using them, and the IP addresses of connections.