1.防火墙常用规则systemctl start iptablessystemctl stop iptablessystemctl restart iptablesiptables -nvL1.屏蔽ip地址和解封ip地址iptables -A INPUT -s 22.22.22.22 -j DROPiptables -D INPUT -s 22.22.22....
1.防火墙常用规则
systemctl start iptables systemctl stop iptables systemctl restart iptables
iptables -nvL
1.屏蔽ip地址和解封ip地址
iptables -A INPUT -s 22.22.22.22 -j DROP
iptables -D INPUT -s 22.22.22.22 -j DROP
2.阻止端口和同意端口
阻止特定的传出连接:
iptables -A OUTPUT -p tcp --dport 80 -j DROP
同意特定的传入连接:
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
使用 multiport 我们可以一次性在单条规则中写入多个端口,例如:
iptables -A INPUT -p tcp -m multiport --dports 22,80,443 -j ACCEPT
iptables -A OUTPUT -p tcp -m multiport --sports 22,80,443 -j ACCEPT
在 IPtables 中 IP 地址范围是可以直接使用 CIDR 进行表示的,例如:
iptables -A OUTPUT -p tcp -d 192.168.100.0/24 --dport 22 -j ACCEPT
3.端口转发
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 25 -j REDIRECT --to-port 2525
4.屏蔽HTTP服务Flood攻击
命令会将连接限制到每分钟 100 个,上限设定为 200
iptables -A INPUT -p tcp --dport 80 -m limit --limit 100/minute --limit-burst 200 -j ACCEPT
5.禁止ping
iptables -A INPUT -p icmp -i eth0 -j DROP
6.允许访问回环网卡
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
12、屏蔽指定MAC地址
iptables -A INPUT -m mac --mac-source 00:00:00:00:00:00 -j DROP
13、限制并发连接数
iptables -A INPUT -p tcp --syn --dport 22 -m connlimit --connlimit-above 3 -j REJECT
以上规则限制每客户端不超过 3 个连接
14、清空IPtables规则
iptables -F
要清空特定的表可以使用 -t 参数进行指定,例如:
iptables -t nat –F
15.保存规则
iptables-save > ~/iptables.rules
iptables-restore < ~/iptables.rules
17、允许建立相关连接
随着网络流量的进出分离,要允许建立传入相关连接,可以使用如下规则:
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
允许建立传出相关连接的规则:
iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
18、丢弃无效数据包
很多网络攻击都会尝试用黑客自定义的非法数据包进行尝试,我们可以使用如下命令来丢弃无效数据包:
iptables -A INPUT -m conntrack --ctstate INVALID -j DROP
19、IPtables屏蔽邮件发送规则
如果你的系统不会用于邮件发送,我们可以在规则中屏蔽 SMTP 传出端口:
iptables -A OUTPUT -p tcp --dports 25,465,587 -j REJECT
20、阻止连接到某块网卡
如果你的系统有多块网卡,我们可以限制 IP 范围访问某块网卡:
iptables -A INPUT -i eth0 -s xxx.xxx.xxx.xxx -j DROP
21、设置默认规则
iptables -P INPUT DROP # 设置 filter 表 INPUT 链的默认规则是 DROP,如果前面没有添加允许的规则,会把自己的xshell连接DROP掉
本文标题为:centos7防火墙常用规则
- 阿里云ECS排查CPU数据分析 2022-10-06
- IIS搭建ftp服务器的详细教程 2022-11-15
- KVM虚拟化Linux Bridge环境部署的方法步骤 2023-07-11
- CentOS7安装GlusterFS集群的全过程 2022-10-10
- 【转载】CentOS安装Tomcat 2023-09-24
- nginx中封禁ip和允许内网ip访问的实现示例 2022-09-23
- 解决:apache24 安装后闪退和配置端口映射和连接超时设置 2023-09-11
- 利用Docker 运行 python 简单程序 2022-10-16
- CentOS_mini下安装docker 之 安装docker CE 2023-09-23
- 教你在docker 中搭建 PHP8 + Apache 环境的过程 2022-10-06
