2

linux下增、删、查本地端口映射

 2 years ago
source link: https://www.zoucz.com/blog/2020/07/22/b19e87a0-cc2e-11ea-90b5-eb40e9720ed0/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

linux下增、删、查本地端口映射

作者: 邹成卓 2020-07-22 23:19:10 分类: linux

标签: linux

评论数:

鹅厂呆久了难免给各种网络策略坑。之前遇到用了很久的端口突然被封掉,只开放部分安全端口的问题,后来只好自己一个个做端口映射,来规避这个问题。 我要说话

增加端口映射

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080 我要说话

service iptables save 我要说话

service iptables restart 我要说话

将本机的80端口映射到8080端口。 我要说话

这个例子有个神坑是如果有其它机器的网络代理到本机80端口,那么这个代理也会被映射掉。我刚好因为可用安全端口不多而踩过这个神坑,记忆犹新难以忘怀,特此记录。 我要说话

同理,此坑适用于443端口。80和443是比较常见的,映射其它常用软件/协议端口时,也要一定要考虑清楚后果,例如把ssh使用的端口给代理走了。。。 我还没试过,应该有解吧。我要说话

参考文章 我要说话

查找端口映射

iptables -t nat -L -n | grep 8080 我要说话

删除端口映射

iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 我要说话

service iptables save 我要说话

service iptables restart 我要说话

参考文章 我要说话

本文链接:https://www.zoucz.com/blog/2020/07/22/b19e87a0-cc2e-11ea-90b5-eb40e9720ed0/我要说话

☞ 参与评论我要说话


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK