Linux uses iptables to limit multiple IPs from accessing your server

Linux uses iptables to limit multiple IPs from accessing your server

Preface

In the Linux kernel, netfilter is a subsystem responsible for packet filtering, network address translation (NAT), and connection tracking based on protocol types. This subsystem consists of some packet filtering tables, which contain the rule sets used by the kernel to control packet filtering processing. iptables is a tool for managing netfilter.

Multiple consecutive IP operations

1. Split into multiple commands to run

iptables -A INPUT 192.168.122.2 -j ACCEPT 
iptables -A INPUT 192.168.122.3 -j ACCEPT 
iptables -A INPUT 192.168.122.4 -j ACCEPT 
iptables -A INPUT 192.168.122.5 -j ACCEPT 
....

This method requires writing many commands, and will make the iptables table very long and difficult to manage. Moreover, a large number of commands will have a small (negligible) impact on performance.

2. Access control can be performed on the IP of an IP segment in the form of IP/MASK

iptables -A INPUT 192.168.122.0/24 -j ACCEPT

This method requires calculating the specified source code for the IP range, which is not flexible. (Although many users use this method for convenience, excessive authorization will pose a security risk)

3. iptables has many modules, among which iprange is used to specifically handle access control of continuous IP segments

iptables -A INPUT -m iprange --src-range 192.168.122.2-192.168.122.34 -j ACCEPT #match source IP
iptables -A INPUT -m iprange --dest-range 8.8.8.2-8.8.8.22 -j DROP #match the target IP

This method is more flexible. There is no need to calculate the mask, just give the range directly.

Summarize

Currently, the official does not seem to support discontinuous IPs, but some people have added modules to support discontinuous IPs.

Personally, I think that if you want to manage the iptables list well, you still have to organize it first and then restrict it. If you need to use continuous IPs, use the above method. If they are not continuous, you should write multiple commands honestly. Moreover, if there are more machines, you have to install modules, which may affect the stability of the system.

recommend:

Interested friends can follow the editor’s WeChat public account [ Coder’s Stuff ] for more web page production special effects source code and learning materials! ! !

The above is what I introduced to you about using iptables in Linux to limit multiple IPs from accessing your server. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to use firewall iptables strategy to forward ports on Linux servers
  • Detailed explanation of Linux iptables common firewall rules
  • Basic usage tutorial of IPTABLES firewall in LINUX
  • Detailed explanation of Linux iptables command
  • Summary of how to view, add, delete and modify iptables rules of Linux firewall
  • Detailed explanation of the common commands for banning and unblocking IPs in Linux firewall iptables
  • Examples of iptables blocking and opening ports in Linux
  • Detailed explanation of Docker using Linux iptables and Interfaces to manage container networks
  • Linux vps server common service iptables strategy
  • How to use iptables to configure Linux to prohibit all port logins and open specified ports
  • Solution to the lack of iptables files in the /etc/sysconfig directory of the newly installed Linux system
  • How to use iptables to set security policies on Alibaba Cloud Linux servers
  • Linux defends against DDOS attacks by limiting TCP connections and frequencies through iptables
  • Configuration method of resisting brute force cracking through iptables+Denyhost on Linux server
  • Linux firewall iptables introductory tutorial
  • Example of adding iptables firewall rules in Linux
  • Linux firewall iptables detailed introduction, configuration method and case

<<:  MySQL Optimization: Cache Optimization

>>:  MySQL optimization connection optimization

Recommend

Detailed troubleshooting of docker.service startup errors

Execute the following command to report an error ...

MySQL 8.0 user and role management principles and usage details

This article describes MySQL 8.0 user and role ma...

Several common methods for passing additional parameters when submitting a form

When submitting a form, you may encounter situatio...

How to deploy LNMP & phpMyAdmin in docker

Environmental preparation: Deploy lnmp on a host ...

Summary of MySQL commonly used type conversion functions (recommended)

1. Concat function. Commonly used connection stri...

Display special symbols in HTML (with special character correspondence table)

Problem Reproduction When using HTML for editing,...

Implementation of services in docker accessing host services

Table of contents 1. Scenario 2. Solution 3. Conc...

Practical operation of using any font in a web page with demonstration

I have done some research on "embedding non-...

Sqoop export map100% reduce0% stuck in various reasons and solutions

I call this kind of bug a typical "Hamlet&qu...

How to use JSX in Vue

What is JSX JSX is a syntax extension of Javascri...

MySQL InnoDB row_id boundary overflow verification method steps

background I talked to my classmates about a boun...

Detailed tutorial on downloading mysql on Windows 10

MySQL versions are divided into Enterprise Editio...

Implementation of react routing guard (routing interception)

React is different from Vue. It implements route ...

Linux installation MySQL5.6.24 usage instructions

Linux installation MySQL notes 1. Before installi...