端口转发(Port Forwarding)
CentOS网络配置工具
firewalld
(默认防火墙工具) iptables
(传统防火墙,CentOS 7/8仍支持) nftables
(CentOS 8+推荐替代iptables) systemctl start firewalld systemctl enable firewalld firewall-cmd --state
firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toaddr=192.168.1.100:toport=8080 firewall-cmd --reload
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf sysctl -p
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.1.100:8080 iptables -t nat -A POSTROUTING -j MASQUERADE service iptables save
nft add table nat nft add chain nat prerouting { type nat hook prerouting priority 0 \; } nft add rule nat prerouting tcp dport 80 dnat to 192.168.1.100:8080
ss -tulnp | grep <端口号> 或 firewall-cmd --list-all
SELinux
未阻止转发(可临时设置为permissive
模式测试)。 --permanent
参数保存规则。 firewalld
+iptables
。 nftables
后端。 本文由 江邈 于2025-07-31发表在【云服务器提供商】,文中图片由(江邈)上传,本平台仅提供信息存储服务;作者观点、意见不代表本站立场,如有侵权,请联系我们删除;若有图片侵权,请您准备原始证明材料和公证书后联系我方删除!
本文链接:https://vps.7tqx.com/wenda/492740.html
发表评论