Blog | G5 Cyber Security

Safe Network Ports: A Quick Guide

TL;DR

Generally, keep only the ports you *need* open. More open ports mean more chances for attackers. This guide helps you check what’s open and understand if they’re a risk.

Checking Open Ports

  1. Use netstat (Windows) or ss/nmap (Linux/macOS): These tools show active network connections, including listening ports.
    • Windows: Open Command Prompt as Administrator and run
      netstat -ano | findstr LISTENING

      . This shows listening ports and the process ID (PID) using them.

    • Linux/macOS: Use
      ss -tulnp

      or

      sudo nmap -p 1-65535 localhost

      . ss is generally faster and more modern; nmap provides a detailed port scan.

  2. Understand the Output: Look for ports listening on `0.0.0.0` or specific IP addresses. Ports listening only on `127.0.0.1` (localhost) are usually safe as they’re only accessible from your machine.

Common Ports & Their Safety

Here’s a breakdown of common ports, ranked roughly by risk level. Remember that *any* open port is a potential target; minimising them is best.

Generally Safe (If Used as Expected)

Potentially Risky

High Risk – Close Immediately

Steps to Secure Your Ports

  1. Firewall Configuration: Use your operating system’s firewall (Windows Firewall, iptables on Linux, macOS Firewall) to block unwanted incoming connections.
    • Windows: Search for ‘Windows Defender Firewall with Advanced Security’. Create inbound rules to allow only necessary ports.
    • Linux: Use
      sudo ufw allow 22/tcp

      (example allowing SSH) and

      sudo ufw deny 139/tcp

      (example denying NetBIOS). Remember to enable the firewall with

      sudo ufw enable

      .

  2. Keep Software Updated: Regularly update your operating system and all applications. Updates often include cyber security patches for vulnerabilities.
  3. Use Strong Passwords/Key-Based Authentication: For services like SSH, use strong passwords or, better yet, key-based authentication.
  4. Consider a VPN: Use a Virtual Private Network (VPN) to access remote resources instead of exposing ports directly to the internet.
Exit mobile version