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防火墙常用规则
基础教程推荐
- Docker容器操作方法详解 2022-11-13
- windows环境下apache-apollo服务器搭建 2023-09-10
- 通过StatefulSet部署有状态服务应用实现方式 2022-10-01
- Apache Kafka 2.5 稳定版发布,新特性抢先看 2023-09-11
- Centos 安装Django2.1 2023-09-24
- Apache CarbonData 1.0.0发布及其新特性介绍 2023-09-11
- Centos7 nginx的安装以及开机自启动的设置 2023-09-22
- RFO SIG之openEuler AWS AMI 制作详解 2022-12-28
- P3 利用Vulnhub复现漏洞 - Apache SSI 远程命令执行漏洞 2023-09-10
- 为Win2003服务器打造铜墙铁壁的方法步骤 2022-09-01
