# Configure a VPS firewall and keep remote access

Always open the browser Console and allow your actual SSH or RDP port before enabling UFW, firewalld or Windows Firewall rules. Test a second login in a new window before closing your existing session, and use Console to fix the rule if you get locked out.

Last updated: 2026-10-28

## 1. Check your SSH or RDP port and open Console

In the [client area](<https://my.virtarix.com/>), select your VPS on **Dashboard** and open **Console**. Keep both **Console** and your existing SSH or RDP session open while editing firewall rules.

Check which TCP port your SSH or RDP service is actually listening on. Use Administrator PowerShell for the Windows check:

**Inside the VPS · Find the ports used by SSH and RDP — Ubuntu / Debian · Bash**

```sh
sudo ss -lntp
```

**Inside the VPS · Find the ports used by SSH and RDP — Windows · PowerShell**

```powershell
Get-NetTCPConnection -State Listen |
    Sort-Object LocalPort |
    Format-Table LocalAddress, LocalPort, OwningProcess
```

SSH normally uses TCP `22` and RDP uses TCP `3389`, but always allow your configured port. Use whichever firewall manager is already active on Linux—never enable **UFW** and **firewalld** together. Also check **Additional Tools → Firewall** in the client area.

## 2. Allow SSH or RDP through your OS firewall

On Ubuntu or Debian with **UFW**, allow your SSH port (and any needed app ports) **before** running `ufw enable`. Replace `22` with your actual SSH port. For Windows, run the rule in Administrator PowerShell and replace `3389` and `198.51.100.25` with your RDP port and your own public IP address:

**Inside the VPS · Allow SSH or RDP access through the firewall — Ubuntu / Debian · Bash**

```sh
sudo ufw allow 22/tcp
sudo ufw status numbered
sudo ufw enable
sudo ufw status verbose
```

**Inside the VPS · Allow SSH or RDP access through the firewall — Windows · PowerShell**

```powershell
New-NetFirewallRule -DisplayName "RDP from admin IP" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 3389 -RemoteAddress 198.51.100.25
```

See the [Ubuntu UFW guide](<https://ubuntu.com/server/docs/how-to/security/firewalls/>) for more syntax.

## 3. firewalld: allow access in the correct zone

On Linux servers running **firewalld**, check the active zone assigned to your interface first:

**Inside the VPS · Check the zone assigned to your network interface — Ubuntu / Debian · Bash**

```sh
sudo firewall-cmd --get-active-zones
```

Add your SSH port to the **runtime** configuration first. Replace `public` with the active zone you found above and `22` with your actual SSH port:

**Inside the VPS · Add an access rule to the runtime configuration — Ubuntu / Debian · Bash**

```sh
sudo firewall-cmd --zone=public --add-port=22/tcp
```

Test a **second** SSH connection, then save the tested rule permanently in the same verified zone and port ([firewall-cmd manual](<https://firewalld.org/documentation/man-pages/firewall-cmd.html>)). The runtime rule is already active, so no reload is needed for this step:

**Inside the VPS · Save the access rule after testing a new connection — Ubuntu / Debian · Bash**

```sh
sudo firewall-cmd --permanent --zone=public --add-port=22/tcp
```

## 4. Windows Firewall: allow RDP and test a second session

Use the Windows PowerShell rule in Step 2 ([`New-NetFirewallRule`](<https://learn.microsoft.com/en-us/powershell/module/netsecurity/new-netfirewallrule?view=windowsserver2025-ps>)), replacing the example IP and port. On any OS, always open a **second** SSH or RDP session to confirm your rules work before closing the first session.

## 5. Use Console to repair blocked remote access

If you get locked out, sign in through **Console** on the service page and fix the blocking rule in your OS firewall or **Additional Tools → Firewall**. Do not flush all rules or disable the firewall completely, and remember that guest rules cannot override our network-level [port 25 policy](<https://virtarix.com/docs/help/port-25-email/>).

![Console is the rightmost control on this service toolbar. Use it to inspect the guest firewall without relying on SSH or RDP access.](<https://virtarix.com/_reader-media/9e14afe53b39b54f77e26726da312e3b89f1418f7a4b32efd70bcb13ae2dbcd7/657fa775462598cb2a75210ca183a57420688b004bb9c6b3dbe835bcd9a8aae8/client-area-power-console.png>)

Console is the rightmost control on this service toolbar. Use it to inspect the guest firewall without relying on SSH or RDP access.

## Frequently asked questions

### How can I avoid losing SSH or RDP access?

Keep **Console** and your current session open, check and allow your actual SSH or RDP port before enabling the firewall, and test a **second** login before closing your original session.

### Can I enable both UFW and firewalld?

No. Running both creates conflicting firewall rules. Use only the firewall manager already active on your Linux server.

> **Still stuck?** Open a support ticket with your server IP, hostname, invoice number and what you have already tried.
