VPS Linux

How to Block an IP Address on Your Linux VPS

Block an IP address on your Winheberg VPS with UFW, firewalld, or iptables depending on your distribution, and learn how to identify suspicious IPs.

July 24, 2026 Winheberg
DocumentationVPS LinuxHow to Block an IP Address on Your Linux VPS

Context

You manage a Winheberg VPS and spotted a suspicious IP address in your logs? A bot spamming your contact form, a script trying to log in via SSH hundreds of times, or simply an unwanted visitor you want to keep out? Blocking an IP on your VPS is a simple and effective operation that takes less than a minute.

This guide walks you through the three most common methods for blocking an IP on a Linux VPS, depending on the firewall installed on your system.

Prerequisites

  • An active Winheberg VPS with root SSH access
  • The IP (or IP range) you want to block, identified in your logs

Which method should you choose based on your distribution?

The right tool depends on the firewall already installed on your VPS.

Recommended firewall by distribution
Distribution Recommended firewall
Ubuntu UFW
Debian UFW (installable)
AlmaLinux, Rocky Linux, Fedora firewalld
All distributions, including Alpine iptables
  • UFW is the default firewall on Ubuntu, and the simplest to use. It's also easy to install on Debian
  • firewalld is the default firewall on AlmaLinux, Rocky Linux, and Fedora. It offers advanced zone-based management
  • iptables is the low-level tool that works on every Linux distribution, including Alpine. It's the universal solution if you don't want to install an extra firewall

Use the firewall already installed on your system rather than stacking several. Mixing UFW with manual iptables rules can create conflicts that are hard to diagnose.

Block an IP based on your firewall

UFW (Uncomplicated Firewall) is by far the simplest solution. The syntax is clear and readable.

Install UFW (if not already done)

On Ubuntu, UFW is usually already installed. On Debian, add it with this command.

apt install ufw -y

Block a single IP

To block a specific IP address.

ufw deny from 203.0.113.42

Replace 203.0.113.42 with the IP you want to block. The rule applies immediately.

Block an entire IP range

If you want to block a whole block (for example, an entire range used by an attacker), use CIDR notation.

ufw deny from 203.0.113.0/24

This command blocks the 256 addresses from 203.0.113.0 to 203.0.113.255.

Block an IP on a specific port only

If you want to block an IP only for a specific service (for example, blocking SSH access but leaving port 80 open).

ufw deny from 203.0.113.42 to any port 22

Check active rules

To see all the UFW rules currently in place.

ufw status numbered

You'll see something like this.

Status: active

     To                         Action      From
     --                         ------      ----
[ 1] Anywhere                   DENY        203.0.113.42
[ 2] 22/tcp                     ALLOW       Anywhere

Remove a blocking rule

To remove a rule, use its number.

ufw delete 1

Or directly by specifying the IP.

ufw delete deny from 203.0.113.42

How do you find the IP to block?

Before blocking an IP, you first need to know which one to block. Here are the most common sources.

In the SSH logs

To see recent SSH connection attempts and identify malicious IPs.

# Debian, Ubuntu
journalctl -u ssh -n 100 | grep "Failed password"

# AlmaLinux, Rocky, Fedora
journalctl -u sshd -n 100 | grep "Failed password"

# Alpine
tail -n 100 /var/log/messages | grep "Failed password"

In a web server's logs

To identify IPs spamming your site (Nginx as an example).

tail -n 1000 /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head

This command shows the 10 most active IPs over the last 1000 requests. An IP showing up hundreds of times is likely a bot or an attacker.

Checking an IP's reputation

Before blocking, you can check an IP's reputation on online services like AbuseIPDB or VirusTotal. If the IP has been reported by many users, blocking it is generally justified.

These services aren't foolproof. An IP can be wrongly flagged, or may have been used by an attacker in the past and later reassigned to a legitimate user (a common case with dynamic ISP IPs, shared VPNs, or Tor exit nodes). Before blocking an entire range, check your own logs to confirm the IP actually shows suspicious behavior on your end. Don't rely solely on AbuseIPDB to decide on a block.

A more automated approach, CrowdSec

If you want to automatically block IPs attacking your server, without having to hunt them down by hand, we recommend installing CrowdSec. It analyzes logs in real time, detects malicious behavior, and blocks IPs automatically. It's also a modern alternative to Fail2Ban.

To learn more, check our guide on securing a Linux VPS, which covers the full CrowdSec installation.

Need help?

If you accidentally blocked your own IP (yes, it happens 😅) and can no longer connect to your VPS, our team is here. Open a ticket in the Technical department from your client area and fill in the Related Product field with the VPS in question, we can help you access your server through the rescue console to undo the block.

You now know how to block an IP on your Linux VPS, whatever your system 🛡️

Need a VPS Linux server?

Discover our offers tailored to your needs and get started now.

View offers