Press "Enter" to skip to content

阿里云/京东云等进行端口转发

假设我们有个应用建立在国外的某个服务器上(如8.8.8.8:443端口上),现在希望使用阿里云/京东云等作为跳板来转发一下这个端口

开启端口转发

vim /etc/sysctl.conf
将 net.ipv4.ip_forward=0
修改成 net.ipv4.ip_forward=1

编辑后使用命令让配置马上生效
sysctl -p

相同端口的转发(将阿里云的443端口转发到8.8.8.8的443端口)

iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 8.8.8.8
iptables -t nat -A PREROUTING -p udp --dport 443 -j DNAT --to-destination 8.8.8.8

iptables -t nat -A POSTROUTING -p udp -d 8.8.8.8 --dport 443 -j SNAT --to-source 192.168.0.3
iptables -t nat -A POSTROUTING -p tcp -d 8.8.8.8 --dport 443 -j SNAT --to-source 192.168.0.3

请注意:一般来说,阿里云/京东云有个内网IP和公网IP,我们假设这里的192.168.0.3是阿里云/京东云的内网IP,这里不能写公网IP

不同端口的转发(将阿里云的5270端口转发到8.8.8.8的443端口)

iptables -t nat -A PREROUTING -p udp --dport 5270 -j DNAT --to-destination 8.8.8.8:443
iptables -t nat -A PREROUTING -p udp --dport 5270 -j DNAT --to-destination 8.8.8.8:443

iptables -t nat -A POSTROUTING -p udp -d 8.8.8.8 --dport 443 -j SNAT --to-source 192.168.0.3
iptables -t nat -A POSTROUTING -p tcp -d 8.8.8.8 --dport 443 -j SNAT --to-source 192.168.0.3

One Comment

  1. 微型隔膜泵 2017-12-18

    博主,阿里云ECS美国空间,1核2G内存1M带宽,一般企业 网站,速度如何?

Leave a Reply to 微型隔膜泵 Cancel reply

Your email address will not be published. Required fields are marked *