国内中转高性价比方案:NAT VPS+iptables端口流量转发

3、开启转发

echo 1 > /proc/sys/net/ipv4/ip_forward
echo "net.ipv4.ip_forward = 1" > /etc/sysctl.conf
sysctl -p

4、安装iptables,并添加规则

yum install -y iptables-services

开启端口的UDP转发

iptables -t nat -A PREROUTING -p udp --dport 中转端口 -j DNAT --to-destination 目的ip:目的端口
iptables -t nat -A POSTROUTING -p udp -d 目的ip --dport 目的端口 -j SNAT --to-source NAT内网ip

开启端口的TCP转发

iptables -t nat -A PREROUTING -p tcp --dport 中转端口 -j DNAT --to-destination 目的ip:目的端口
iptables -t nat -A POSTROUTING -p tcp -d 目的ip --dport 目的端口 -j SNAT --to-source NAT内网ip

5、端口转发完毕,以wireguard为例,修改客户端配置文件的Endpoint选项为NAT VPS的外网ip和监听的端口即可。

注意:这家NAT VPS的公网ip是提供的域名,你可以ping一下这个域名,获得真实的ip地址。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注