Home  >  Article  >  System Tutorial  >  How to disable and enable IP address in CentOS7?

How to disable and enable IP address in CentOS7?

WBOY
WBOYforward
2024-01-04 08:16:311637browse

1. Block ip

I haven’t logged into my VPS for a long time. Today I used Xshell to log in and saw the Last Failed Login. After a closer look, I saw an unknown IP trying to crack my VPS. After confirming with my partner that it was not his IP, I decided to fix this ip is blocked.

CentOS7如何封停 解封IP?

(Picture 1: An unknown IP tried to log in to my VPS)

CentOS7 command to block ip: iptables

Usage (note case-sensitive):

iptables -I INPUT -s ***.***.***.*** -j DROP

CentOS7如何封停 解封IP?

(Figure 2: Usage of iptables blocking IP)

Parameter -I means Insert (add), followed by rules, INPUT means inbound, ***.***.***.*** means the IP to be blocked, DROP means giving up the connection . After successfully executing the command, there will be no prompt. To view the blocked IP list, execute the command:

iptables --list

CentOS7如何封停 解封IP?

(Figure 3: Use the list parameter to view the IP addresses blocked by DROP. The blocked IP addresses are below the source)

2. Unblock ip

1. To unblock, replace -I with -D. The premise is that iptables already has this record:

iptables -D INPUT -s ***.***.***.*** -j DROP

2. If you want to clear the blocked IP address, you can enter:

iptables --flush

The above is the detailed content of How to disable and enable IP address in CentOS7?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete