Budget-friendly, full-performance, fully equipped servers in any desired location.
ExploreBudget-friendly, full-performance, fully equipped servers in any desired location.
ExploreFirewall configuration should allow only the traffic you need instead of opening every connection on the server at random. On a Linux server with administrative access, first record the existing rules and the provider-level layer, verify the SSH connection, and then open necessary services such as the web service one by one. After changing a rule, retry the same connection and check new timestamped logs; if access is interrupted, use the console or the provider’s recovery access to restore the previous setting.
This guide is for a Linux server where you can manage a firewall at the operating-system level and where you have administrator or sudo privileges. On a shared hosting account, you cannot change the operating system firewall; in that case, you are limited to the IP blocking, WAF, or security settings available in the hosting panel. The provider’s network firewall may also operate before the operating-system firewall. A rule block in the panel can make a correct server-side rule appear ineffective.
Before making changes, export the current rule list or save a screenshot. Note which port SSH is listening on, whether your administrator IP address is static, and, if you use a web server, whether ports 80 and 443 are genuinely required. Changing the SSH port is not a mandatory part of firewall setup; changing a working access path at the same time as an uncertain firewall configuration makes troubleshooting more difficult.
First, divide the workload by connection type. On a server that only publishes a website, HTTP and HTTPS plus administrative SSH access may be sufficient. If the database is not used externally, do not expose its port to the internet; if the application and database are on the same server, a local-access design is generally more appropriate. If a monitoring service connects from a fixed source, consider restricting the relevant port to that source’s IP range rather than exposing it to the entire internet.
The decision should be based on whether the service genuinely needs to be reachable from outside: if external users must connect, define permission for the relevant port; if the connection is used only by an application on the server, do not add an external-access rule. If you have a static administrator IP, restricting SSH access to that IP is a more controlled option. If your IP address changes frequently, an incorrect restriction can cut off your own access; in that case, do not apply the rule until the provider’s console access is ready.
sudo ufw status numbered displays the current rules. In an example output, a line such as 22/tcp ALLOW indicates that SSH permission exists, but it does not cover the provider firewall. If there is no SSH line, prepare the access rule before moving to the next step.For example, suppose that on a hypothetical web server, the administrator uses SSH only from a static office IP, while visitors need to reach the website from anywhere. The SSH rule can be restricted to the office IP, while ports 80 and 443 remain open to general access; the database port stays closed to the outside. If it becomes clear that the office internet connection uses a different IP after switching to a backup connection, it is safer to keep the provider console ready and add the trusted new IP rather than broadening the original SSH rule. This prevents the observed problem from being confused with web access.
If the SSH session closes after the change or all new connections are rejected, do not continue adding rules. If the provider offers a browser console, serial console, or recovery access, restore the firewall’s saved previous state from there. If no such access exists, do not send credentials in a support request; provide the server address, the change time, the port used, and the scope of the applied rule. For security, reverting only the last change is safer than disabling the firewall entirely or opening all ports.
After the initial setup, keep the rule list together with a change record. When the server’s role grows, reassess whether external access is required before opening a new service. To review other topics related to general server security, you can look at the relevant guides on İyibirNet.
Copyright © 2026 All Rights Reserved
