Get a Pentest and security assessment of your IT network.

Cyber Security

Port Blocking: Security Basics

TL;DR

Blocking unused network ports significantly improves your domain’s security by reducing potential entry points for attackers. However, it’s not a complete solution – you also need firewalls, strong passwords, regular updates, and other cybersecurity measures.

Understanding Ports & Security

Think of your server as a building with many doors (ports). Each port is used for a specific service. If a door is open, someone can try to enter. Blocking unused ports closes those unnecessary doors, making it harder for attackers to get in.

Step-by-Step Guide: Blocking Ports

  1. Identify Open Ports: First, you need to know which ports are currently open on your server. You can use a network scanning tool like nmap.
    nmap -p 1-65535 your_server_ip

    This command scans all 65535 ports and shows you which ones are open, filtered, or closed.

  2. Determine Necessary Ports: List the services running on your server (e.g., web server – port 80/443, SSH – port 22, email – port 25/110/143/993/995). Only keep ports open that are absolutely required.
    • Web Server: Ports 80 (HTTP) and 443 (HTTPS) are essential for a website.
    • SSH: Port 22 is commonly used for remote access, but consider changing it to a non-standard port for added security.
    • Email: Ports vary depending on the email protocol (SMTP, POP3, IMAP).
  3. Use a Firewall: A firewall is your primary tool for blocking ports.
    • iptables (Linux): This is a powerful command-line firewall. Here’s how to block port 8080:
      sudo iptables -A INPUT -p tcp --dport 8080 -j DROP

      Remember to save your rules after making changes (e.g., using iptables-save).

    • ufw (Linux): A simpler firewall interface for iptables.
      sudo ufw deny 8080/tcp
    • Windows Firewall: Access through Control Panel > System and Security > Windows Defender Firewall. Create inbound rules to block specific ports.
  4. Configure Your Cloud Provider’s Firewall (if applicable): Most cloud providers (AWS, Azure, Google Cloud) have their own firewall services (Security Groups, Network Security Groups). Configure these firewalls in addition to the server-level firewall.
    • AWS Security Groups: Edit inbound rules for your EC2 instance.
    • Azure Network Security Groups: Create security rules to allow/deny traffic on specific ports.
  5. Test Your Changes: After blocking ports, verify that the necessary services still work correctly. Use online port scanning tools (e.g., YouGetSignal) to confirm that blocked ports are no longer accessible.
  6. Regularly Review and Update: Periodically review your open ports and firewall rules. As your services change, update the configuration accordingly. Also, keep your operating system and firewall software up to date with the latest security patches.

Important Considerations

  • Don’t Block Ports Without Understanding Them: Blocking essential ports will break your services.
  • Firewall is Not Enough: Port blocking is just one layer of cybersecurity. You also need strong passwords, multi-factor authentication, regular backups, malware scanning, and intrusion detection systems.
  • SSH Security: If you use SSH, consider disabling password authentication and using SSH keys instead. Also, changing the default port can reduce automated attacks.
Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation