Linux系统firewalld防火墙的应用实操(禁止屏蔽海外国外IP访问)
文章目录
- 一、前文
- 二、ipset知识点
- 2.1 ipset的增删查
- 2.2 ipset的ip地址修改
- 2.3 ipset的其他查询
- 三、应用实操
- 3.1 下载国内ip网段
- 3.2 新建ip集合
- 3.3 添加规则
- 3.4 有点耐心
- 四、测试验证
一、前文
本文直接进行Linux系统firewalld防火墙的应用实操(禁止屏蔽海外国外IP访问)
基础知识请查阅:Linux系统firewalld防火墙的基本操作
进阶知识请查阅:Linux系统firewalld防火墙的进阶操作(日志保存 IP网段 ssh服务)
应用实操请查阅:Linux系统firewalld防火墙的应用实操(对外端口开放使用,对内端口限制ip地址使用,不使用端口默认关闭)
应用实操请查阅:Linux系统firewalld防火墙的应用实操(禁止屏蔽海外国外IP访问)
二、ipset知识点
- ipset是ip地址的集合。
- firewalld使用ipset可以在一条规则中处理多个ip地址,执行效果更好,管理更方便。
- firewalld的ipset会记录到/etc/firewalld/ipsets/目录下
2.1 ipset的增删查
#新建一个ip集合,--type=hash:ip 指定类型为 hash:ip,不允许重复ip
firewall-cmd --permanent --new-ipset=china_ip --type=hash:ip#删除一个ip集合
firewall-cmd --permanent --delete-ipset=china_ip#查询所有ip集合
firewall-cmd --permanent --get-ipsets
2.2 ipset的ip地址修改
#ipset添加ip
firewall-cmd --permanent --ipset=china_ip --add-entry=121.122.123.105#从文件中添加ip到ipset
firewall-cmd --permanent --ipset=china_ip --add-entries-from-file=china_ip_list.txt#ipset删除ip
firewall-cmd --permanent --ipset=china_ip --remove-entry=121.122.123.105#判断ip是否存在ipset中
firewall-cmd --permanent --ipset=china_ip --query-entry=121.122.123.105firewall-cmd --reload
2.3 ipset的其他查询
more /etc/firewalld/ipsets/china_ip.xml#打印ipset的路径
firewall-cmd --path-ipset=china_ip --permanent#打印ipset的内容
firewall-cmd --info-ipset=china_ip --permanent#打印ipset的所有entry
firewall-cmd --ipset=china_ip --get-entries --permanent
三、应用实操
- 禁止屏蔽海外国外IP访问有两种方法
- 允许所有IP,禁止国外IP
- 禁止所有IP,允许国内IP
- 相对而言,禁止所有IP,允许国内IP更容易些。
- 因为,相比收集国内IP集合会更加容易些。
3.1 下载国内ip网段
[root@iZ2ze30dygwd6yh7gu6lskZ home]# wget https://www.isres.com/china_ip_list.txt
--2022-08-15 11:46:01-- https://www.isres.com/china_ip_list.txt
Resolving www.isres.com (www.isres.com)... 45.136.15.104
Connecting to www.isres.com (www.isres.com)|45.136.15.104|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 95267 (93K) [text/plain]
Saving to: ‘china_ip_list.txt’china_ip_list.txt 100%[==================================================================================================================>] 93.03K 419KB/s in 0.2s 2022-08-15 11:46:02 (419 KB/s) - ‘china_ip_list.txt’ saved [95267/95267]
3.2 新建ip集合
firewall-cmd --permanent --new-ipset=china_ip --type=hash:netfirewall-cmd --permanent --ipset=china_ip --add-entries-from-file=china_ip_list.txt
3.3 添加规则
firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" source ipset="china_ip" port port=80 protocol=tcp accept'
firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" source ipset="china_ip" port port=8080 protocol=tcp accept'
firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" source ipset="china_ip" port port=443 protocol=tcp accept'
firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" source ipset="china_ip" port port=8443 protocol=tcp accept'
firewall-cmd --reload
3.4 有点耐心
- firewall处理大量IP的时候,会卡住,需要点耐心
ERROR:dbus.proxies:Introspect error on :1.32902:/org/fedoraproject/FirewallD1/config: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
- 如果遇到报错,那就升级下firewalld试试
[root@iZ2ze30dygwd6yh7gu6lskZ home]# firewall-cmd --reload
Error: COMMAND_FAILED: '/usr/sbin/nft insert rule inet firewalld raw_PREROUTING_ZONES iifname "eth0" goto raw_PRE_public' failed: Error: Could not process rule: No such file or directory
insert rule inet firewalld raw_PREROUTING_ZONES iifname "eth0" goto raw_PRE_public
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[root@iZ2ze30dygwd6yh7gu6lskZ home]# systemctl stop firewalld
[root@iZ2ze30dygwd6yh7gu6lskZ home]# yum install firewalls
CentOS-8 - AppStream 764 kB/s | 4.3 kB 00:00
CentOS-8 - Base 148 kB/s | 3.9 kB 00:00
CentOS-8 - Extras 55 kB/s | 1.5 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 135 kB/s | 4.7 kB 00:00
No match for argument: firewalls
Error: Unable to find a match: firewalls
[root@iZ2ze30dygwd6yh7gu6lskZ home]# yum install firewalld
Last metadata expiration check: 0:00:04 ago on Wed 17 Aug 2022 12:23:38 AM CST.
Package firewalld-0.7.0-5.el8.noarch is already installed.
Dependencies resolved.
=============================================================================================================================================================================================================================================================================Package Architecture Version Repository Size
=============================================================================================================================================================================================================================================================================
Upgrading:firewalld noarch 0.9.3-7.el8 BaseOS 502 kfirewalld-filesystem noarch 0.9.3-7.el8 BaseOS 77 klibnftnl x86_64 1.1.5-4.el8 BaseOS 83 knftables x86_64 1:0.9.3-21.el8 BaseOS 321 kpython3-firewall noarch 0.9.3-7.el8 BaseOS 432 k
Installing dependencies:python3-nftables x86_64 1:0.9.3-21.el8 BaseOS 29 kTransaction Summary
=============================================================================================================================================================================================================================================================================
Install 1 Package
Upgrade 5 PackagesTotal download size: 1.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/6): python3-nftables-0.9.3-21.el8.x86_64.rpm 334 kB/s | 29 kB 00:00
(2/6): firewalld-filesystem-0.9.3-7.el8.noarch.rpm 853 kB/s | 77 kB 00:00
(3/6): firewalld-0.9.3-7.el8.noarch.rpm 4.5 MB/s | 502 kB 00:00
(4/6): libnftnl-1.1.5-4.el8.x86_64.rpm 1.2 MB/s | 83 kB 00:00
(5/6): python3-firewall-0.9.3-7.el8.noarch.rpm 5.1 MB/s | 432 kB 00:00
(6/6): nftables-0.9.3-21.el8.x86_64.rpm 2.7 MB/s | 321 kB 00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 6.8 MB/s | 1.4 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing : 1/1 Running scriptlet: libnftnl-1.1.5-4.el8.x86_64 1/1 Upgrading : libnftnl-1.1.5-4.el8.x86_64 1/11 Running scriptlet: libnftnl-1.1.5-4.el8.x86_64 1/11 Upgrading : nftables-1:0.9.3-21.el8.x86_64 2/11 Running scriptlet: nftables-1:0.9.3-21.el8.x86_64 2/11 Installing : python3-nftables-1:0.9.3-21.el8.x86_64 3/11 Upgrading : python3-firewall-0.9.3-7.el8.noarch 4/11 Upgrading : firewalld-filesystem-0.9.3-7.el8.noarch 5/11 Upgrading : firewalld-0.9.3-7.el8.noarch 6/11
warning: /etc/firewalld/firewalld.conf created as /etc/firewalld/firewalld.conf.rpmnewRunning scriptlet: firewalld-0.9.3-7.el8.noarch 6/11 Running scriptlet: firewalld-0.7.0-5.el8.noarch 7/11 Cleanup : firewalld-0.7.0-5.el8.noarch 7/11 Running scriptlet: firewalld-0.7.0-5.el8.noarch 7/11 Cleanup : firewalld-filesystem-0.7.0-5.el8.noarch 8/11 Cleanup : python3-firewall-0.7.0-5.el8.noarch 9/11 Running scriptlet: nftables-1:0.9.0-14.el8.x86_64 10/11 Cleanup : nftables-1:0.9.0-14.el8.x86_64 10/11 Running scriptlet: nftables-1:0.9.0-14.el8.x86_64 10/11 Cleanup : libnftnl-1.1.1-4.el8.x86_64 11/11 Running scriptlet: libnftnl-1.1.1-4.el8.x86_64 11/11 Verifying : python3-nftables-1:0.9.3-21.el8.x86_64 1/11 Verifying : firewalld-0.9.3-7.el8.noarch 2/11 Verifying : firewalld-0.7.0-5.el8.noarch 3/11 Verifying : firewalld-filesystem-0.9.3-7.el8.noarch 4/11 Verifying : firewalld-filesystem-0.7.0-5.el8.noarch 5/11 Verifying : libnftnl-1.1.5-4.el8.x86_64 6/11 Verifying : libnftnl-1.1.1-4.el8.x86_64 7/11 Verifying : nftables-1:0.9.3-21.el8.x86_64 8/11 Verifying : nftables-1:0.9.0-14.el8.x86_64 9/11 Verifying : python3-firewall-0.9.3-7.el8.noarch 10/11 Verifying : python3-firewall-0.7.0-5.el8.noarch 11/11 Upgraded:firewalld-0.9.3-7.el8.noarch firewalld-filesystem-0.9.3-7.el8.noarch libnftnl-1.1.5-4.el8.x86_64 nftables-1:0.9.3-21.el8.x86_64 python3-firewall-0.9.3-7.el8.noarch Installed:python3-nftables-1:0.9.3-21.el8.x86_64 Complete!
四、测试验证
搞个国外的IP测试一下~
Linux系统firewalld防火墙的应用实操(禁止屏蔽海外国外IP访问)相关推荐
- linux 配置防火墙 firewalld 屏蔽海外国外IP访问(服务器受到外网未知用户攻击,通过设置防火墙隔绝) 仅允许中国国内ip访问自己在公网上的服务器
需求:屏蔽海外国外IP访问 wget https://www.isres.com/china_ip_list.txt 确定防火墙状态开启 systemctl status firewalld 防火墙开 ...
- Linux系统firewalld防火墙的进阶操作(日志保存 IP网段 ssh服务)
文章目录 一.前文 二.打开日志 2.1 修改配置 2.2 测试验证 2.3 日志保存到本地 三.允许IP网段 四.关闭ssh 一.前文 基础知识请查阅:Linux系统firewalld防火墙的基本操 ...
- 《网络安全入门到精通》-1.2 - Linux系统 - firewalld防火墙iptables防火墙
「作者简介」:CSDN top100.阿里云博客专家.华为云享专家.网络安全领域优质创作者 「订阅专栏」:此文章已录入专栏<网络安全入门到精通> Linux防火墙 Frewalld 1.常 ...
- Linux LCD屏幕驱动调参实操
Linux LCD屏幕驱动调参实操 初探 Linux下的 LCD 驱动文中提到过, IMX6ULL的 eLCDIF接口驱动程序已经有半导体厂家NXP编写好了,并且不同分辨率LCD屏的eLCDIF接口驱 ...
- Linux系统关闭防火墙命令
Linux系统关闭防火墙命令 下面是red hat/CentOs7关闭防火墙的命令! 1:查看防火状态 systemctl status firewalld service iptables stat ...
- 2020A证(安全员)模拟考试系统及A证(安全员)实操考试视频
题库来源:安全生产模拟考试一点通公众号小程序 2020A证(安全员)模拟考试系统及A证(安全员)实操考试视频,包含A证(安全员)模拟考试系统答案解析及A证(安全员)实操考试视频练习.由安全生产模拟考试 ...
- inurl+:php?id,实操:SQL注入国外xx网站
原标题:实操:SQL注入国外xx网站 来自公众号:孑蝉 前言: 学了SQL注入一段时间了,也在顺利通关过墨者靶场.不过,靶场哪有真实网站好玩? 何为sql注入? SQL注入就是SQL+注入,不清楚可以 ...
- 理论+实操: linux中firewalld防火墙基础讲解(转载)
前言 firewalld概述.firewalld 中的d代表服务 firewalld 和 iptables 的关系 firewalld 网络区域 firewalld 防火墙的配置方法 firewall ...
- Linux系统firewall防火墙策略
目录 一,防火墙介绍 二,firewall-cmd命令 1.系统firewall服务 2.禁用firewalld 3.获取预定义信息 三,区域管理 1.显示当前系统中的默认区域 2.显示默认区域的所有 ...
- 如何搭建AIoT智能对话交互系统:技术解析和实操分享
早些年,拥有一个足够智能的对话系统似乎是一件很虚幻的事情,可能只在科幻电影中存在.但到如今,人机智能对话因其日益增长的需求和巨大的商业价值而受到越来越多的关注. 百度大脑UNIT也因此应运而生,UNI ...
最新文章
- laravel数据库操作
- 点星 (。*)表示任意数量的字符(不包括换行符)
- 记录JS event Loop机制及Node v8事件执行机制
- 差分隐私 python_主要开发语言为 Python/Rust:微软与哈佛大学合作开源差分隐私平台...
- Decorator pattern
- 转.h和.cpp文件的区别
- 开源免费的.NET图像即时处理的组件ImageProcessor
- 表单中的日期 字符串和Javabean中的日期类型的属性自动转换
- Ext 学习之 Store
- zend studio 8使用感受
- Java基础IDEA快捷键
- 大话西游版《我叫小沈阳》
- 卸载IE8 恢复IE6 的两种方法
- C/C++ isalpha、isalnum、islower、isupper函数详解
- 怎么把图片的边缘弄圆_如何PS制做出边缘清晰或虚化的圆角照片
- S7-PLCSIM Advance ,解决 Error Code: -30,LicenseNotFound问题解决和期限21天限制的问题,对版本V1.0 V2.0 V3.0有效
- Captain Flint and Crew Recruitment
- 过零检测法MATLAB仿真,过零检测
- MATLAB Simulink
- MathWorks 中国
- 二次型如何快速转化为矩阵?
- IMS 会话过程 响应180还是183?