目标:在公网获得台湾地区的原生公网IP,并通过VPN/代理把流量走台湾出口。须具备:能购买国外VPS的支付方式(信用卡/PayPal)、一台能SSH的本地电脑(Linux/Mac/Windows+WSL)、基础Linux命令能力。
建议选型:使用台湾Region的云服务(例如 Google Cloud asia-east1/台湾节点、台湾本地VPS商或支持台湾IP的主机商)。本文以 GCP 台湾 VM + WireGuard 为主线,提供SSH代理的补充方案。
步骤1:注册GCP账号并启用结算。步骤2:在控制台创建 VM,选择地域 asia-east1(台湾),选择 Debian/Ubuntu 镜像,2CPU/1GB 以上(根据用途增配)。
步骤3:预留静态外网IP(VPC -> External IP),绑定到该VM。步骤4:设置防火墙规则开放 SSH(22)、WireGuard UDP 51820(或自定义端口)。最后记录外网IP。
SSH 登录服务器:ssh username@台湾外网IP。更新系统:sudo apt update && sudo apt upgrade -y。设置主机名、时区。
开启内核转发:sudo sysctl -w net.ipv4.ip_forward=1,并在 /etc/sysctl.conf 中持久化:net.ipv4.ip_forward=1。
安装:sudo apt install wireguard -y(Debian/Ubuntu)。生成密钥对:wg genkey | tee /etc/wireguard/server_private.key | wg pubkey > /etc/wireguard/server_public.key。
配置 /etc/wireguard/wg0.conf(示例):
[Interface] Address = 10.10.0.1/24 ListenPort = 51820 PrivateKey = (server_private) PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
注意将 eth0 替换为实际外网接口名(ip addr 可查)。启用:sudo systemctl enable --now wg-quick@wg0。检查状态:sudo wg。
客户端生成密钥:wg genkey | tee client_private.key | wg pubkey > client_public.key。把client_public写入服务器的 Peer 配置并分配一个IP,如 10.10.0.2/32。
在服务器 wg0.conf 添加 Peer 段并重启 wg:
[Peer] PublicKey = (client_public) AllowedIPs = 10.10.0.2/32
客户端配置示例(手机/电脑):
[Interface] PrivateKey = (client_private) Address = 10.10.0.2/32 DNS = 1.1.1.1 [Peer] PublicKey = (server_public) Endpoint = 台湾外网IP:51820 AllowedIPs = 0.0.0.0/0 PersistentKeepalive = 25
服务器的 PostUp 已做 MASQUERADE,作用是把从 WireGuard 网络来的流量伪装成服务器公网IP,确保出站流量显示为台湾IP。如果使用 nftables 或 firewalld,按相应语法添加 SNAT/MASQUERADE 规则。
若需要将服务器作为路由器为 LAN 设备提供出口,需在这些设备上设置默认网关为 WireGuard 客户端或在路由器上配置 VPN 透传/Policy Routing。
如果不想安装WireGuard,可用SSH动态端口转发:ssh -D 1080 -C -f -N user@台湾外网IP。然后在本地浏览器/系统代理设置 SOCKS5 localhost:1080。
SSH 方案配置简单但效率与稳定性较 WireGuard 差,且无法直接为其他局域设备提供透明网关(除非在客户端机器上做共享)。
防火墙:建议仅开放必要端口(22, 51820),并限制 SSH 登录来源或使用非默认端口。安装 fail2ban 或配置 UFW:sudo ufw allow 51820/udp; sudo ufw allow OpenSSH; sudo ufw enable。
性能调优:调整 MTU(特殊网络场景下可能需降低到 1420),WireGuard PersistentKeepalive 保持 NAT 映射。监控带宽使用,升级实例规格满足需求。
问题1:连上后不是台湾IP?排查:在服务器上 curl ifconfig.co 确认外网IP为台湾;在客户端连接后 curl ifconfig.co 检查出口IP。若服务器不是台湾IP,需确认创建实例的地域和预留外网IP。
问题2:无法访问外网或 DNS 问题?排查:确认服务器 ip_forward 已启用,iptables MASQUERADE 规则存在,客户端 AllowedIPs=0.0.0.0/0,DNS 配置在客户端或服务器上生效(可在服务器上安装并转发 DNS)。
答:连接VPN后在客户端打开浏览器访问 https://ifconfig.co 或 https://ipinfo.io,会显示当前公网IP和地理位置;也可以在服务器上用 curl ifconfig.co 确认服务器公网IP与显示一致,即出口为台湾。
答:可选台湾本地VPS提供商或使用台湾物理服务器托管,另一种是购买台湾数据中心的 VPS 或上架台湾租户的服务;还可以通过朋友/厂商在台湾的机器做反向代理或部署 WireGuard 以获得台湾出口。但必须注意合规与服务商政策。
答:使用台湾IP本身无问题,但务必遵守当地法律与服务商条款(不得用于违法活动、滥发邮件、规避地理限制用于侵权等),并注意所用数据与业务的合规性,如公司用途请事先咨询法律/合规部门。