


Case study on how to block malicious IP addresses in batches to prevent attacks under Linux
In many cases, you may need to block IP addresses under Linux. For example, as an end user, you may want to be protected from spyware or IP tracking. If you are a system administrator, you may want to ban spam IP addresses from accessing your corporate mail server. Or you want to ban certain countries from accessing your web service for some reason. In many cases, however, your IP address blocking list can quickly grow to tens of thousands of IPs. How to deal with this?
Solution: ipset + iblocklist2ipset
Installation:
The simplest method is to install yum, but the version of this method is relatively low and lacks some used module parameters, so it is not recommended;
yum install ipset -y
Compile and install:
1. Dependency environment:
yum install libmnl libmnl-devel kernel-devel libtool-devel -y
(Installation method of new version: git pull git://git.netfilter.org/libmnl.git run ./autogen.sh)
(Note: If only libmnl is installed, the following error will appear:
checking for libmnl... configure: error: Package requirements (libmnl >= 1) were not met: No package 'libmnl' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables libmnl_CFLAGS and libmnl_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details. )
may prompt that /lib/modules/2.6.32- cannot be found during compilation) 431.el6.x86_64/source
After investigation, it was found that this soft link/lib/modules/2.6.32-431.el6.x86_64/build -->/usr/src/kernels/2.6.32- 431.el6.x86_64 does not exist
Solution: Re-establish the soft connection
ln -sb /usr/src/kernels/2.6.32-573.3.1.el6.x86_64 /lib/modules/2.6.32-431.el6.x86_64/build
Error when running ./autogen.sh:
Cannot find /usr/share /libtool/
Solution: Install the libtool-devel tool package yum install libtool-devel
2. Compile and install ipset (linux kernel source code (version >= 2.6.32) )
wget -P /usr/local/src http://ipset.netfilter.org/ipset-6.26.tar.bz2 cd /usr/local/src && tar xjf ipset-6.26.tar.bz2 && cd ipset-6.26 ./autogen.sh ./configure make make modules make install make modules_install
Note: Different linux kernels use different versions of source code packages
Note: linux kernel source code (version >= 2.6.16 or >= 2.4.36)
Compile and install:
wget -P /usr/local/src http://ipset.netfilter.org/ipset-4.5.tar.bz2 cd /usr/local/src && tar xf ipset-4.5.tar.bz2 && cd ipset-4.5 make KERNEL_DIR=http://img.xue163.com/lib/modules/$(shell uname -r)/build #$(shell uname -r)使用shell命令获取 make KERNEL_DIR=http://img.xue163.com/lib/modules/$(shell uname -r)/build install
Commonly used commands:
ipset list 查看ip集列表信息 ipset create pythontab hash:ip maxelem 1000000 创建一个IP集pythontab,指定类型为hash:ip,设置ip集最多存储IP数为1000000 ipset add pythontab X.X.X.X 增加一个ip地址到IP集pythontab中去 ipset add pythontab X.X.X.X/24 增加一个网段到IP集pythontab中去 ipset dell pythontab X.X.X.X 删除IP集中指定的IP地址 ipset list 查看当前所有list ipset save pythontab -f pythontab.txt 将IP集pythontab中的信息保存到当前文件目录下面的文件pythontab.txt中 ipset destroy pythontab 删除指定的IP集pythontab ipset restore -f pythontab.txt 将保存的pythontab.txt文件中的IP集信息重新导入到ipset中 其他命令参考 ipset --help iptable命令参考: iptables -I INPUT -m set --match-set pythontab src -p tcp --destination-port 80 -j DROP #拒绝ipset IP集pythontab中的地址访问服务器的80端口 service iptables save service iptables restart
Automatic IP address disabling
Now you should see the power of maintaining IP blacklists. A tedious and time-consuming task. In fact, there are many free or paid services that can do this for you. As an added bonus, let's look at how to automatically add IP blacklists to the IP set. ##First let’s get a free blacklist from iblocklist.com
Next I’m going to use an open source Python tool called iblocklist2ipset to convert the blacklist into an IP set.
First, you need to install pip
Use the following command to install iblocklist2ipset.
$ pip install iblocklist2ipset
On some distributions such as Fedora, you may need to run:
$ python-pip install iblocklist2ipset
Now go to iblocklist.com and grab the URL of any P2P list (such as the "level1" list).
Download and unzip it, then save it as a txt file, for example, called pythontab.txt. Because iblocklist2ipset only supports url to obtain the list, put pythontab.txt in any directory of your website. For example: ipset directory
$ iblocklist2ipset generate --ipset pythontab "http://www.pythontab.com/ipset/pythontab.txt" > pythontab.txt
After running the above command, you will get a file named pythontab.txt. If you view its contents, you will see something like this:
create pythontab hash:net family inet hashsize 131072 maxelem 237302 add pythontab 1.2.4.0/24 add pythontab 1.2.8.0/24 add pythontab 1.9.75.8/32 add pythontab 1.9.96.105/32 add pythontab 1.9.102.251/32 add pythontab 1.9.189.65/32
You can load this file with the following ipset command:
$ ipset restore -f pythontab.txt
You can now view the automatically created IP set:
$ ipset list pythontab
This saves you the trouble of manual management.
Note that the version installed using yum under centos is not the latest version. It may not support the -f parameter and import the blacklist file, so it is recommended to use the source code package to install the latest versionThe above is the detailed content of Case study on how to block malicious IP addresses in batches to prevent attacks under Linux. For more information, please follow other related articles on the PHP Chinese website!

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

This article describes how to use TigerVNC to share files on Debian systems. You need to install the TigerVNC server first and then configure it. 1. Install the TigerVNC server and open the terminal. Update the software package list: sudoaptupdate to install TigerVNC server: sudoaptinstalltigervnc-standalone-servertigervnc-common 2. Configure TigerVNC server to set VNC server password: vncpasswd Start VNC server: vncserver:1-localhostno


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)