X
X

Select Your Currency

₺ Türk Lirası $ US Dollar
X
X

Select Your Currency

₺ Türk Lirası $ US Dollar

Firewall Configuration: A Basic Setup That Protects SSH Access

HomepageArticlesSecurityFirewall Configuration: A Basic Set...

Firewall 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.

Identify the environment and access before firewall configuration

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.

Identify required traffic and plan the permission order

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.

Apply rules in a safe order

  1. Review the current state: In the firewall management tool, view the enabled status, allowed ports, and deny policy. If UFW is installed on an Ubuntu or Debian system, the read-only command 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.
  2. Prepare a second administrator session: Do not close your current SSH session and, if possible, open a separate terminal. Define access to the SSH port you use, preferably only from the permitted administrator IP. While adding the rule, check that the port, protocol, and source address are correct. If a new session can be opened, basic access has been preserved; if it cannot, stop adding general blocking rules and restore the original list through the console.
  3. Open published services one at a time: If a web server is present, add permission for ports 80 and 443; do not open unused administration panels or database ports. After each addition, read the rule list again and verify that the expected port appears with the correct protocol. If an unexpected service appears in the port list, first determine which application is listening and whether external access is required instead of deleting it immediately.
  4. Test the connection from outside: Retry the same operation—the SSH or web connection that previously failed—using the same client and the same port. If the connection succeeds, this shows that the new rule is effective; if SSH still fails, compare new records from the same time in the operating-system log and the provider firewall. If web access has opened but SSH has not, do not change the web rule; inspect only the SSH port, source IP, and the block at the upper network layer.
  5. Verify the result with new evidence: Note the change time and locate the new accept or reject record in the firewall event log. If an accept record appears but the application does not respond, the problem may be with the web server, listening address, or TLS settings after the firewall; do not keep changing the same firewall rule. If no record appears at all, the request may be stopping before it reaches the server because of the provider network, DNS, or an incorrect IP address.

Choose the correct restriction in a concrete scenario

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.

Rollback plan if the connection is lost

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.


Top