WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Tutorials» How to Block IP Addresses in WordPress

How to Block IP Addresses in WordPress

Last updated on May 8th, 2017 by Editorial Staff
160 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How to Block IP Addresses in WordPress

Do you want to block specific IP addresses from accessing your WordPress site? Blocking IP addresses is used as a solution to block spam and hacking attacks on your website. In this article, we will show you how to block IP addresses in WordPress, and we will also show you how to find out which IP addresses needs to be blocked.

How to Block IP Addresses in WordPress

What is an IP Address?

If internet was a physical world, then think of IP addresses as country, street, and house numbers. They are basically 4 sets of numbers from 0-255 separated by dots and look like this:

172.16.254.1

Each computer connected to the internet has an IP address assigned to them by their internet service provider.

All visitors to your website have an IP address which is stored in your website’s access log files. This means that all websites that you visit also stores your IP address.

You can hide this information by using a VPN service. This allows you to hide your IP address and other personal information.

Why & When You Need to Block IP Addresses?

Blocking an IP address from accessing your website is an effective way to deal with unwanted visitors, comment spam, email spam, hacking attempts, and DDOS (denial of service) attacks.

The most common sign that your website is under a DDOS attack is that your website will frequently become inaccessible or your pages will start taking forever to load.

The other attacks are more obvious such as when you start getting spam comments or a lot of spam emails from your contact form. We have a list of ways to fight spam comments, but the last solution is to block IP addresses.

Finding Out IP Addresses You Want to Block in WordPress

WordPress stores an IP addresses for users that leave a comment on your website. You can see their IP address by visiting the comments page in your WordPress admin area.

IP addresses stored in WordPress comments

If your website is under DDOS attack, then the best way to locate the IP addresses is by checking your server’s access log.

To see those logs, you will need to login to the cPanel dashboard of your WordPress hosting account. Next, locate the ‘logs’ section and click on the ‘Raw Access Logs’ icon.

Raw access logs

This will take you to the access logs page where you need to click on your domain name to download the access logs file.

Download access log file

Your access log file will be inside a .gz archive file. Go ahead and extract the file by clicking on it. If your computer does not have a program to handle .gz archive files, then you will need to install one. Winzip or 7-zip are two popular choices among Windows users.

Inside the archive, you will see your access log file which you can open in a plain text editor like Notepad or TextEdit.

The access log file contains raw data of all requests made to your website. Each line begins with the IP address making that request.

IP addresses in access log file

You need to make sure that you don’t end up blocking yourself, legit users, or search engines from accessing your website. Copy a suspicious looking IP address and use online IP lookup tools to find out more about it.

You will have to carefully look at your access logs for suspicious unusually high number of requests from a particular IP address. Tip: there’s a way to automate this that we share at the bottom of this article.

Once you have located those IP addresses, you need to copy and paste them in a separate text file.

Blocking IP Addresses in WordPress

If you just want to stop users with a specific IP address from leaving a comment on your site, then you can do that inside your WordPress admin area.

Head over to Settings » Discussion page and scroll down to ‘Comment Blacklist’ text box.

Blacklist IP addresses in WordPress comments

Copy and paste the IP addresses that you want to block and then click on the save changes button.

WordPress will now block users with these IP addresses from leaving a comment on your website. These users will still be able to visit your website, but they will see an error message when they try to submit a comment.

Blocking an IP Address Using cPanel

This method completely blocks an IP address from accessing or viewing your website. You should use this method when you want to protect your WordPress site from hacking attempts and DDOS attacks.

First, you need to login to cPanel dashboard of your hosting account. Now scroll down to the security section and click on ‘IP Address Deny Manager’ icon.

IP Address Deny Manager tool in cPanel

This will take you to the IP Address Deny Manager tool. Here you can add the IP addresses you want to block. You can add a single IP address or an IP range and then click on the add button.

Blocking IP addresses in cPanel

You can come back to the same page again if you ever need to unblock those IP addresses.

When IP Address Blocking Doesn’t Work – Automate It!

Blocking an IP address would work if you are just blocking some basic hacking attempts, specific users, or users from specific regions or countries.

However, many hacking attempts and attacks are made using a wide range of random IP addresses from all over the world. It is impossible for you to keep up with all those random IP addresses.

That’s when you need a Web Application Firewall (WAF). For the WPBeginner website, we use Sucuri. It is a website security service that protects your website against such attacks using a website application firewall.

Basically, all your website traffic goes through their servers where it is examined for suspicious activity. It automatically blocks suspicious IP addresses from reaching your website altogether. See how Sucuri helped us block 450,000 WordPress attacks in 3 months.

We hope this article helped you learn how to easily block IP addresses in WordPress. You may also want to see our ultimate step by step WordPress security guide for beginners.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

160 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • Google Analytics in WordPress

    How to Install Google Analytics in WordPress for Beginners

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

26 Comments

Leave a Reply
  1. Borundebnath says:
    Dec 31, 2020 at 12:12 am

    My Wifi IP address is block in my own site for my mistake but I can log in my site by using another wifi, how to unblock my IP address with WordPress?

    Reply
    • WPBeginner Support says:
      Dec 31, 2020 at 9:52 am

      You would remove the IP from the tool you blocked the IP from.

      Reply
  2. Gbengard says:
    Nov 16, 2020 at 7:49 am

    Hi there,

    I blocked an IP Address from visiting my blog, the visitor still finds a way to visit my blog with the same IP Address.

    What would you advise?

    Reply
    • WPBeginner Support says:
      Nov 17, 2020 at 12:43 pm

      In these situations, we would recommend checking with your hosting provider to ensure there are no conflicts on their end.

      Reply
  3. Mira khan says:
    Nov 4, 2020 at 10:37 pm

    bro, i dont fine option commenting blacklist ? help

    Reply
    • WPBeginner Support says:
      Nov 5, 2020 at 9:50 am

      You would want to look for Disallowed Comment Keys on the discussion page due to a more recent update for where to add the IPs :)

      Reply
    • zanuda says:
      Nov 6, 2020 at 7:29 am

      From left menu (rather then comments) choose Settings -> Disussions and scroll down until you see line “Disallowed Comment Keys” and the box under. IP to blocked goes in the box, one per line.

      Reply
  4. Azra Noir says:
    Oct 4, 2020 at 10:54 am

    Thanks ^^ This helped me find what I was looking for to block an ip address from commenting on my articles.

    Reply
    • WPBeginner Support says:
      Oct 5, 2020 at 11:37 am

      Glad our guide was helpful :)

      Reply
  5. Ammar says:
    Jul 31, 2020 at 2:51 am

    Thanks alot. These really help.

    Reply
    • WPBeginner Support says:
      Jul 31, 2020 at 10:33 am

      You’re welcome :)

      Reply
  6. Gaurav Ramani says:
    May 24, 2020 at 10:59 am

    One website is copying my whole content without leaving any comment .
    What can I do. help me please

    Reply
    • WPBeginner Support says:
      May 27, 2020 at 8:35 am

      To prevent content scraping, you would want to take a look at our article below.
      https://www.wpbeginner.com/beginners-guide/beginners-guide-to-preventing-blog-content-scraping-in-wordpress/

      Reply
  7. Francesco Aulisi says:
    Mar 28, 2020 at 7:49 am

    I LOVE YOU this is so useful for blocking Spam! Wow Thank you.

    Reply
    • WPBeginner Support says:
      Mar 30, 2020 at 9:07 am

      You’re welcome, glad our guide was helpful :)

      Reply
  8. zanuda says:
    Feb 5, 2020 at 4:52 am

    How do I block a range of IPs (subnet)? I’m getting spam from the same subnet, let.s say ABC.CDE.*.* First part is the same, the last varies. At the moment I wrote in the blacklist section that way: ABC.CDE , but I’m not sure it’s the right way. I’ve seen this as an advice somewhere ages ago. Now one of the anti-spam plugin died out and I started to look, I’ve got another info. like this: ABC.CDE.* or like this ABC.CDE.*.* So are all those ways are Ok or only one of them? And which one?

    Reply
    • WPBeginner Support says:
      Feb 5, 2020 at 8:34 am

      It would depend on what method you are using to block the IPs but normally you would want to use the second option with two *s

      Reply
      • zanuda says:
        Feb 5, 2020 at 11:03 am

        Method – the same as in the article above, going to Discussion settings and putting IP address over there. It’s just there are no way to double check which one is working because I don’t have access to different IP…

        Thanks, I’ll change everything to ABC.CDE.*.*

        Reply
  9. iptv says:
    Feb 13, 2019 at 1:56 am

    I have recently started a blog, the information you offer on this web site has helped me tremendously. Thank you for all of your time & work.

    Reply
    • WPBeginner Support says:
      Feb 13, 2019 at 11:40 am

      Glad our content could help :)

      Reply
  10. Rajender Singh Bisht says:
    Aug 16, 2018 at 4:47 am

    Useful Information for Beginner.

    Reply
  11. Leon Mufaya says:
    Jul 20, 2018 at 10:04 am

    Thanks a lot for the information, ever since I came across WPBeginner, my WordPress life has been extremely easy and stress-free and I hope you guys keep up the great work.

    Reply
  12. Anna says:
    May 22, 2018 at 3:22 pm

    This worked for exactly what I needed it for and it was easy peasy!
    Thank you!

    Reply
  13. Gurpreet Kaur says:
    Oct 13, 2017 at 1:44 am

    this solution is great. thanks alot

    Reply
  14. dorian says:
    Aug 14, 2017 at 5:37 am

    I was looking to this answer since my site was getting so much hits and spam from particular IP addresses. I am disabling that now. Thanks!

    Reply
  15. Joe says:
    Aug 8, 2017 at 8:54 am

    The comment still ends up in the spam folder making this option useless.

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
Smash Balloon
Smash Balloon
Add Custom Social Media Feeds in WordPress. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2020 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2020)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2020)
    • SiteGround Reviews from 4196 Users & Our Experts (2020)
    • Bluehost Review from Real Users + Performance Stats (2020)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2020 – Step by Step Guide
Deals & Coupons (view all)
Complianz
Complianz GDPR Coupon
Get 15% OFF on Complianz GDPR premium WordPress privacy suite plugin.
Connections Pro
Connections Pro Coupon
Get 15% OFF on Connections Pro WordPress directory plugin.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).
Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress CDN by MaxCDN | WordPress Security by Sucuri.