How to Prevent Port Scanning
Network firewall rules control which external machines can probe your server ports. Knowing how to prevent port scanning starts with dropping unsolicited traffic by default. Attackers scan IP ranges to find open database and admin ports. When a port responds, the scanner logs the service type and version. If your team blocks public probes, scanners see nothing to attack. You can secure these endpoints by moving services to private subnets. How to prevent port scanning at the network edge Eve
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Network firewall rules control which external machines can probe your server ports. Knowing how to prevent port scanning starts with dropping unsolicited traffic by default.
Attackers scan IP ranges to find open database and admin ports. When a port responds, the scanner logs the service type and version. If your team blocks public probes, scanners see nothing to attack. You can secure these endpoints by moving services to private subnets.
How to prevent port scanning at the network edge
Every server listens on numbered ports to accept network traffic. Web apps need public ports, while databases and admin tools do not. The best defense is a deny-all inbound rule on your firewall.
This setup affects user roles, backend apps, and automated build runners. Instead of opening ports to all IP addresses, restrict them to known networks. Security groups should drop incoming packets rather than sending rejection notices. Dropping packets slows down scanners because the tool must wait for a timeout. Sending a reset packet tells the attacker that a host exists right away.
Next, place databases and internal services inside private subnets with no public IP. Workloads in private subnets cannot receive direct traffic from the public internet. Only approved internal services can talk to those database ports. You should also turn off unused network daemons on every host. If a service does not run, no port is open to respond.
How to check port rules and audit active sessions
After you set up firewall rules, test your public IP range from outside. Run a port check from an external network to see what answers. Compare the open ports against your approved list of public services. Set up alerts for spikes in dropped packets inside your network flow logs. A sudden jump in blocked requests often points to an active scan.
Infrastructure as Code Security Scanning + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, static firewall rules only filter where traffic comes from at the start. Once a user or app logs in from an allowed IP, the port keeps the session active. Network rules cannot read what queries run inside that active session. A compromised developer laptop on an approved VPN can still scan internal subnets. It can also run broad queries that pull raw phone numbers or emails. Static network blocks do not log individual database commands or mask sensitive fields.
How to limit internal lateral movement
Internal networks need strict port rules just like the public edge. Many teams allow all traffic between hosts inside the same private network. If an attacker steals one server key, they will scan neighbor hosts next.
Break your private network into smaller zones based on app roles. A web server should only reach the specific database port it needs. It should never reach admin ports on other web servers. Bind internal services to local private interfaces instead of all network interfaces. Review these internal rules every month to remove old exceptions and dead hosts.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
What is the difference between dropping and rejecting packets?
Rejecting sends an error back right away, which confirms the host is online. Dropping ignores the packet, forcing the scanner to wait for a slow timeout.
Can port knocking stop all network scanners?
Port knocking hides services from basic scans, but attackers can still sniff the knock sequence. Private subnets and outbound-only agents are much safer for admin access.
Why do internal subnets still need port filtering?
If an attacker breaches one host, they scan the local network for databases. Strict internal rules stop them from moving sideways to other servers.
Related guides
In this post