System Status
Buy Now
  • Email & Apps
  • Office 365
Login
  • MyRackspace Portal
  • Cloud Control Panel
  • Rackspace Webmail Login
  • Cloud Office Control Panel
  • Support Home
  • How-To
  • Developer Documentation
  •  Blogs 
    • Expert Insights Tech Blog
    • Rackspace Blog
    • Solve: Thought Leadership

Support Network

End-to-End Multicloud Solutions.   Solving Together.™   Learn more at Rackspace.com

How–To Home

Cloud Servers

  • Introduction
  • FAQ
  • All Articles

Block an IP address on a Linux server

Last updated on:  2021-05-05

Authored by:  Morgan Marion


A large number of requests from one IP address can deplete the server of available resources. This article provides the commands to block an IP address on three common Linux® software firewalls.

Prerequisites

  • Basic understanding of commands in a Linux operating system.
  • Basic understanding of Secure Shell (SSH).
  • Administrative access to your server by using the sudo command.

NOTE: These steps are for servers that are not RackConnect® cloud servers. For RackConnect, make changes in the dedicated firewall.

Log on to the server by using SSH and then complete the steps in the following sections.

firewalld tool

firewalld is available on the following Linux versions:

  • Red Hat® Enterprise Linux 7 and later.

  • CentOS® 7 and later.

  • Fedora® 18 and later.

  1. To ensure that firewalld is running on your server, run the following command. If firewalld is not running, go to the iptables section.

    sudo systemctl status firewalld
    
  2. Run the following command to block the IP address and to add the rule to the permanent set:

    sudo firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='xxx.xxx.xxx.xxx' reject"
    
  3. Run the following command to reload the firewalld rules:

    sudo firewall-cmd --reload
    
  4. Run the following command to list and verify the new rule:

    sudo firewall-cmd --list-all
    

Uncomplicated Firewall (UFW)

The UFW tool is available on the Ubuntu® operating system 8.04 LTS and later.

  1. To ensure that UFW is running on your server, run the following command. If UFW is not running, go to the iptables section.

    sudo systemctl status ufw
    
  2. Run the following command to block the IP address:

    sudo ufw deny from xxx.xxx.xxx.xxx to any
    
  3. Run the following command to list and verify the new rule:

    sudo ufw status
    

iptables tool

iptables is commonly pre-installed on all Linux operating systems.

  1. Run the following command to block the IP address:

    sudo iptables -I INPUT -s xxx.xxx.xxx.xxx -j DROP
    
  2. Run the following command to save the settings. The settings persist after the server reboots.

    sudo service iptables save
    
  3. Run the following command to list and verify the new rule:

    sudo iptables -L
    

Use the Feedback tab to make any comments or ask questions. You can also start a conversation with us.

Share this information:

©2020 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER

About Rackspace
  • About
  • Customer Stories
  • Events
  • Programs
Blogs
  • The Rackspace Blog
  • Expert Insights Tech Blog
  • Solve: Thought Leadership
  • News
  • Contact Information
  • Legal
  • Careers
Site Information
  • Style Guide for Technical Content
  • Trademarks
  • Privacy Statement
  • Website Terms
Support Network
  • Support Network Home
  • Rackspace How-To
  • API Documentation
  • Developer Center
  • ©2020 Rackspace US, Inc.