Linux防火墙:iptables与nftables实战

17老师 · 2026-06-01 · 阅读约12分钟

← 返回博客列表

前言

防火墙是网络安全的第一道防线。

一、iptables基础

# 查看规则
iptables -L -n -v
# 允许HTTP/HTTPS
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# 拒绝其他
iptables -A INPUT -j DROP

二、NAT配置

# 端口转发
iptables -t nat -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80
# SNAT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

三、nftables迁移

nft add table inet filter
nft add chain inet filter input { type filter hook input priority 0 \; }
nft add rule inet filter input tcp dport {80,443} accept

总结

防火墙配置是安全运维基础。如需服务,欢迎联系17老师。

关于17老师:AI应用·数字化管理·全栈开发·网络安全全栈专家。邮箱:j.d88888888@qq.com 微信:AFIST17
上一篇
SSL/TLS指南
下一篇
入侵检测系统