Posted in linux
136
6:42 am, August 19, 2025
 

blocking ip range with ufw

You can block an entire IP range using CIDR (Classless Inter-Domain Routing) notation with ufw. To block all addresses under 57.141.2.x, you'd specify the network as 57.141.2.0/24.1

 

 

Here is the command:

Bash
 
sudo ufw deny from 57.141.2.0/24

 

## 💡 How it Works

 

The /24 is CIDR notation that defines the size of the network block. Think of an IP address as being made of four 8-bit blocks, totaling 32 bits.

  • /24 means the first 24 bits (57.141.2) are fixed.

  • The remaining 8 bits (32 - 24 = 8) can be any value.

  • This effectively blocks the entire range from 57.141.2.0 to 57.141.2.255.

You can also block larger or smaller ranges:

  • Block a larger range (e.g., 57.141.0.0 to 57.141.255.255):

    Bash
     
    sudo ufw deny from 57.141.0.0/16
    
  • Block a specific port from that range:

    Bash
     
    sudo ufw deny from 57.141.2.0/24 to any port 443
    

 

## 🛡️ Managing Your Rules

 

After adding a rule, it's a good idea to check your firewall status.

  • Check the status and see rule numbers:

    Bash
     
    sudo ufw status numbered
    
  • Delete a rule by its number (if you make a mistake):

    Bash
     
    # Replace '5' with the actual rule number from the command above
    sudo ufw delete 5
    

This semi worked but the order was wrong, so it was still allowing traffic. needed to delete the rune and recreate it. 

sudo ufw delete [number] on the below list
 
then
 
sudo ufw status numbered
 
and then add it again as number 1
 
sudo ufw insert 1 deny from 57.141.2.0/24
 
then on the status list we get new ip addresses. 
 
 

View Statistics
This Week
1
This Month
1
This Year
136

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Items in linux
php error feed errors: XML or PCRE extensions not loaded! Identify which IPs are driving connections: check nginx access logs for bots show established connections in linux ubuntu check connetions in linux every 10 seconds loop Fatal error: Uncaught Error: Call to undefined function mb_strlen() blocking ip range with ufw check and block connections script block ip address ranges on ubuntu linux with UFW list all network connections linux show all connections on linux command line add ssh keys on your linux box in 10 seconds Install PHP without Apache on Ubuntu add a user and add the user to sudo group add user to sudo group in ubuntu simple backup to google drive fron linux backup script to google drive that can be used for multiple directories start ssh and add key git play youtube videos on firefox in ubuntu 18 Creating a chart about charts.css with charts.css from the command line linux mount a drive manually installing exfat and ntfs drivers to enable reading of these filesystems linux list all drives and partitions how to check the temperature of the pi using command line how to check linux kernel version on rasberry pi rasberian how to find what version pi you are using change file permissions to -rw-rw-r-- install atom editor on ubuntu Enabling SSH on Ubuntu certbot add a certificate for one domain renew all SSL certificates with certbot To make Ubuntu do nothing when laptop lid is closed add a user to a group loop through each directory in a target directory and compress them loop through each directory in a target directory tar.gz to compress a directory in linux and then decompress it Find Disk Space Usage using DU how to unzip in linux
Related Search Terms
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

Do you want to be right or happy? You can’t be both.

Suggests that in many situations - especially in relationships or arguments - insisting on being right can come at the cost of harmony or peace of mind. It implies that prioritizing your ego or the need to win an argument may damage relationships or personal contentment, whereas letting go of that need (even if you’re technically right) may lead to greater happiness.


Gerald Jampolsky
Random CSS Property

mask-image

The mask-image CSS property sets the image that is used as mask layer for an element. By default this means the alpha channel of the mask image will be multiplied with the alpha channel of the element. This can be controlled with the mask-mode property.
mask-image css reference