A web server may need to accept HTTPS connections from customers. Its database usually has no reason to accept connections from the entire internet. A firewall can allow traffic to the web service while blocking connections to the database port from untrusted networks. That will not fix weaknesses in either application, but it limits which connections can reach them.
What a firewall actually decides
A firewall examines traffic at a network boundary and follows a policy to allow, reject, or silently drop it. That boundary could sit between a laptop and the internet, between office and guest networks, or between application and database servers. The firewall itself might be a dedicated device, a cloud network control, or software running on a host.
Basic rules commonly use source and destination IP addresses, transport protocols, and port numbers. For example, a rule might allow TCP connections to a web server on port 443 while denying other unsolicited inbound connections. Addresses identify network endpoints; ports identify services on those endpoints. Neither tells you whether a user or application is trustworthy.
Most modern firewalls are stateful: they track established connections, allowing replies to an approved outbound request without a separate rule for every inbound response. A firewall that treats each packet independently lacks that connection context. State tracking makes ordinary browsing practical under a restrictive inbound policy, but it cannot make an unsafe destination safe.

Where firewalls fit in a network
Network-edge and internal controls
An edge firewall filters traffic entering or leaving an organization’s network. It can block unsolicited access to internal services and limit which systems communicate outward. But placement matters: traffic between two machines on the same internal segment may never cross the edge firewall.
Internal firewalls can separate those machines into network zones. Public-facing services might sit in one zone, application systems in another, and databases in a more restricted one. Rules can then allow an application server to reach a database port while keeping a guest device out. This limits exposure if a device is compromised, provided the rules match how the applications actually communicate.
Host and cloud controls
A host firewall runs on an individual computer or server. If its policy is configured and active, it can protect a service even when another device on the local network is untrusted. Cloud platforms offer virtual network firewalls and instance-level traffic controls with similar aims, but their scope varies. One may filter at a subnet boundary; another may apply to a particular workload. Check where each policy takes effect rather than assuming the controls are interchangeable.
Remote laptops need their own protection, too. An edge firewall at headquarters cannot filter a laptop’s direct connection to a café network.
Filtering approaches and their trade-offs
Firewalls vary in what they inspect. Packet-filtering rules use network and transport details such as addresses and ports. Stateful inspection adds connection context. Application-aware firewalls can recognize some protocols and restrict specific request patterns. A web application firewall (WAF) focuses on HTTP requests aimed at a web application; it does not replace network rules around non-web services.
More inspection is not always better. Encrypted traffic can hide application content unless an organization deliberately deploys inspection that can decrypt it, bringing privacy, certificate-management, and operational concerns. Application-aware controls need tuning as well: an overbroad rule can interrupt legitimate traffic, while a narrow signature may miss new behavior.
Direction matters, too. Inbound rules govern connections initiated toward a protected system; outbound rules govern connections it initiates. Outbound restrictions can stop a server from contacting destinations it never needs, but maintaining them calls for an accurate inventory of dependencies, including update services and external APIs.
What firewalls do not solve
A firewall allowing HTTPS to a website cannot tell from the port number whether every request is authorized or whether the application has a bug. It cannot replace software updates, secure code, strong authentication, or controls over sensitive data. Malware can travel through an allowed connection, and someone with access to an approved device may be able to use permitted paths.
IP-based rules have limits. Cloud workloads change addresses, multiple users may share an address, and an infected machine may sit on a trusted subnet. A firewall is one layer of access control, not proof of identity. Where appropriate, pair network restrictions with application authorization and service-to-service authentication.
Building a useful rule set
Start with the communication each service requires, not a list of ports copied from a template. Identify who initiates each connection, where it must go, which protocol and port it uses, and whether those needs differ between development and production.
- Set a clear default. Deny unsolicited inbound traffic unless a documented service requires it. Restrict outbound traffic where you understand the system’s dependencies well enough to maintain the rules.
- Keep permissions narrow. Limit database access to the application servers that need it, rather than opening it to an entire corporate network.
- Account for administration. Restrict remote management to approved paths and administrators. A public service does not require a public management interface.
- Document the reason. Record the owner, purpose, and review date for exceptions so temporary access does not become permanent by accident.
- Check rule order and scope. Some firewalls process rules in sequence; others combine policies differently. A rule that looks correct may be overridden or applied to the wrong interface.
In a small application with a public web server and a private database, users need inbound HTTPS access to the web server. Only the application component that needs the database should connect to its configured port. Administrative access should follow a separate approved path. The exact ports and sources depend on the deployment; publishing the website does not mean publishing its database.

Verify changes without losing access
A firewall change can cut off the connection you use to manage a server. Before changing remote-access rules, confirm a recovery route, such as console access, and know how to revert the change. Make a small change, then test both sides: required traffic still gets through, and traffic meant to be denied is blocked. Run connection tests only on systems you own or are authorized to assess.
Logs provide clues, but a denied connection is not necessarily an attack. It could be a mistyped address, an outdated dependency, or a misconfigured application. Compare repeated denies with service logs and expected traffic patterns. An allowed connection, meanwhile, confirms only that the network path works—not that the application accepted or authorized the request.
When you deploy a new application component, compare its documented network dependencies with the active rules. If it needs database access, record the specific source, destination, protocol, and port before adding the exception. Then test that connection and confirm unrelated hosts still cannot use it.
