Iptables 防火墙常用规则

本文详细介绍了如何安装和配置iptables防火墙服务。包括安装软件包、设置开机启动、保存规则、清除原有规则以及设置基本的网络流量策略。此外还具体说明了如何开放特定端口如SSH(22端口)、DNS(53端口)、HTTP(80端口)等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装ip tables-service*.rpm
关闭selinux
#设置开机启动
Systemctl enable ip tables.service
#保存iptables
Service iptables save

#删除原有的规则
Iptables -F
Iptables -X

#允许所有
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
#限制所有
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
#在所有网卡上打开ping功能,便于维护和检测
iptables -A INPUT -p icmp –icmp-type 8 -j ACCEPT
iptables -A OUTPUT -p icmp –icmp-type 0 -j ACCEPT

#打开22端口,允许远程管理。
iptables -A INPUT -p tcp –dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp –sport 22 -j ACCEPT
#对其他主要允许的端口的 OUTPUT设置:
#DNS
iptables -A OUTPUT -p TCP –dport 53 -jACCEPT
iptables -A OUTPUT -p UDP –sport 53 -jACCEPT

#HTTP
iptables -A OUTPUT -p TCP –dport 80 -jACCEPT
#HTTPS
iptables -A OUTPUT -p TCP –dport 443 -jACCEPT

#Email 接受 和发送
iptables -A OUTPUT -p TCP –dport 110 -jACCEPT
iptables -A OUTPUT -p TCP –sport 25 -jACCEPT

# FTP 数据和控制
iptables -A OUTPUT -p TCP –dport 20 -jACCEPT
iptables -A OUTPUT -p TCP –sport 21 -jACCEPT

#DHCP
iptables -A OUTPUT -p TCP –dport 68 -jACCEPT
iptables -A OUTPUT -p UDP –sport 68 -jACCEPT

#POP3S Email安全接收
iptables -A OUTPUT -p TCP –dport 995 -jACCEPT

#时间同步服务器 NTP
iptables -A OUTPUT -p TCP –dport 123 -jACCEPT

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值