1

Consider the following cases.

A vps running a selfhosted service which is listening on port 1234.

Case 1: There is firewall configured that blocks all incoming connections by default. Now port 1234 has to be explicitly opened in the firewall configuration. When a client tries to access a different port, firewall blocks it.

Case 2: There is no firewall configured. Client can access port 1234 by default. When a client tries to access a different port, kernel would find no process is listening on the port and just close the connection.

If there was a rogue process in the host, it can listen on a random port and let anyone in. But even if firewall blocks incoming connections, it can still make external connections and setup a reverse tunnel.

Only case I can think of is if a miss-configured non-malicious process happens to listen on random port and bind to all interfaces '0.0.0.0', then firewall would help block.

Is there anything else I am missing? It just appears unnecessary extra configuration for no practical benefit.


Update

Thank you for answers. I do understand firewall can do advanced things mentioned. I am trying to find out for the simple use-case. If I just have a simple VPS running some services listening on few ports. Is it better to configure a firewall and then open only the required ports, or just don't have any firewall at all.

I think the answer comes to if I can be sure there is no unintentional listener on the external interface. e.g. a service may have an api/admin port opened different from main web port. Any decent app should not listen on the external interface by default but misconfiguration do occur.

0

4 Answers 4

1

You seem to focus on the simplest packet filter firewall which just restricts incoming traffic by port and might restrict outgoing traffic. Even this kind of firewall can already be used as an effective line of defense.

As a line of defense the firewall can restrict which ports are accessible from the outside in the first place, thus protecting applications which insecurely listen on the public accessible IP, even if they should not be accessed from the public. This might be due to misconfiguration, but also due to limits in the application itself.

Additionally a firewall can restrict access to certain source IP, thus limiting exposure of the application. Depending on the capabilities of the firewall these might be static allow or deny lists, dynamic deny lists based on external threat intelligence or dynamic allow lists based for example on external authentication or things like port-knocking or single packet authentication.

Even simple firewalls might also allow rate limits, which can protect the internal service from a denial of service attack.

But a stateful firewall can also limit outgoing communications. For example a web server usually just has incoming communications, i.e. TCP connections are established from the outside and any outgoing packets should belong to an established incoming TCP connection. Thus it makes sense to limit any outgoing traffic to this (and maybe allow DNS if needed). This can be a valuable defense in cases of vulnerabilities in the server, since it restricts the communication an attacker could establish to load further stages of the attack and to control the server. For example in case of the Log4Shell vulnerability restricting outgoing communications could prevent an attacker to exploit the vulnerability, even if it wasn't patched yet.

2

There's one important scenario missing from your analysis: consider if you accidentally start a service that isn't supposed to be accessible from the Internet. You aren't being malicious, so you aren't going to do the reverse tunnel trick, so the firewall will save you from the consequences of that mistake.

2
  • 1
    "Only case I can think of is if a miss-configured non-malicious process happens to listen on random port"
    – schroeder
    Commented Jul 3 at 21:17
  • How about updating your OS (linux) accidentally installls a new package (SSHD), and is installed and lauched increasing the attack surface. A long time ago the iPhones were commonly jailbroken, and the common jailbreak method enabled the SSHD on all phones. And the default root password was known and exploited. wired.com/2009/11/iphone-worm Commented Jul 4 at 5:11
1

This isn’t an accurate description of how real-world firewalls work. A firewall doesn’t just either deny or accept all traffic to a specific port. It can decide which traffic is acceptable and which isn’t. This decision may be based on, for example, the source or destination IP address (or both). Stateful firewalls can even take previous interactions into account.

You should look at common firewalls like iptables for Linux or pf for BSD to get a basic understanding of what modern firewalls are capable of.

-1

Even if your VPS (Virtual Private Server) runs just one service, it's wise to use a firewall for several reasons:

  1. Enhanced Security: A firewall monitors and controls incoming and outgoing traffic, helping to prevent unauthorized access and attacks.

  2. Control Access: You can set rules to allow only specific users or locations to access your service, enhancing security.

  3. Traffic Monitoring: Firewalls log traffic, which is helpful for identifying and mitigating potential threats.

  4. Multiple Defense Layers: Adding a firewall provides an extra layer of security, crucial for protecting sensitive data.

  5. Regulatory Compliance: Depending on your industry, a firewall might be required to meet legal and regulatory standards.

  6. DDoS Protection: Firewalls can help mitigate Distributed Denial of Service (DDoS) attacks by controlling the rate of incoming requests.

Overall, a firewall is a critical component for securing your VPS, regardless of the number of services it hosts.

2
  • 1
    This looks ChatGPT-generated and doesn't add anything relevant.
    – Ja1024
    Commented Jul 4 at 4:33
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Jul 4 at 8:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .