How to Block Access to VPS by IP Address?

Virtual Private Servers (VPS) provide excellent flexibility and power for working with websites and applications. However, sometimes it is necessary to restrict access to your VPS by specific IP addresses. In this article, we’ll tell you how to do it.

There are several ways to block access to a VPS by IP. One of them is using a firewall. Below we will provide instructions on how to block IP addresses using firewall settings on the server.

1. Using IPTables

IPTables is a utility for configuring IP packet filtering rules in the Linux kernel. To block access to your VPS by specific IP addresses using IPTables, follow these steps:

  • sudo iptables -A INPUT -s IP_ADDRESS -j DROP
  • sudo iptables -A INPUT -s IP_ADDRESS -j REJECT

Where IP_ADDRESS is the IP address you want to block. After executing these commands, the IP address will be blocked and will not be able to access your VPS.

VPS хостинг

Виртуальные серверы с гарантированными ресурсами

Выбрать VPS

2. Using Fail2ban

Fail2ban is a utility for combating attacks on web servers. It can be used to automatically block IP addresses that are engaging in suspicious activity. To block access to your VPS by IP using Fail2ban, follow these steps:

  • sudo nano /etc/fail2ban/jail.local
  • Add the following lines:

[DEFAULT]

ignoreip = 127.0.0.1/8 YOUR_IP_ADDRESS

[sshd]

enabled = true

port = 22

filter = sshd

logpath = /var/log/auth.log

maxretry = 3

findtime = 600

bantime = 1800

Where YOUR_IP_ADDRESS is your IP address. After adding these lines, restart Fail2ban.

Now you know how to block access to your VPS by IP address. Follow our instructions and ensure the security of your server.