Firewall
A guard that inspects network traffic and lets through what matches the rules.
"Only port 22 and 443 inbound, everything else blocked" is a typical firewall rule. Exists as software in the OS, dedicated hardware at companies, or as a service in the cloud (security groups in AWS, Cloudflare WAF).
Modern versions inspect not just the port but also the content — a Web Application Firewall can block SQL injection attempts or XSS attacks.