CentOS 端口映射
配置端口映射
将80端口映射到8080端口(就是访问80端口时自动访问7026端口下的程序)
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
配置完成后==一定要保存==:
service iptables save
在保存时如果报错:The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.那就说明==没有该命令==(就离谱,没有该命令,但是设置完事不保存的话,还能生效一段时间,令人崩溃,诡异的BUG)
安装 iptables services
yum install iptables-services- 设置开机启动:
systemctl enable iptables - 重启 iptables service命令:
ystemctl restart iptables
删除端口映射
iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
==和新增的区别就是-A 变成了-D==
端口映射失效
可能的原因是端口映射配置多个或者没有配置成功

- 查看端口配置情况:
iptables -t nat -L -n | grep 80- 如果同样的映射关系出现了多条就会出现问题,导致映射失败,此时删除映射关系并重新配置即可
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 程序员小航
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果