创建IPIP隧道

将国内的服务器Gooth,和国外的服务器WendangKu,通过IPIP隧道连接起来,以穿透墙的屏蔽。 国内服的公网IP地址是218.244.133.124,国外服的公网IP地址是192.81.133.165。

IPIP隧道名为gooth2wdk。 隧道两端的IP地址分别是: Gooth: 192.168.168.1 WendangKu: 192.168.168.2

国内服(Gooth)设置

  • 设置IPIP隧道 ip tunnel add gooth2wdk mode ipip remote 192.81.133.165 local 218.244.133.124
  • 手动配置隧道接口IP ifconfig gooth2wdk 192.168.168.1 netmask 255.255.255.0

国外服(WendangKu)设置

  • 设置IPIP隧道 ip tunnel add gooth2wdk mode ipip remote 218.244.133.124 local 192.81.133.165
  • 手动配置隧道接口IP ifconfig gooth2wdk 192.168.168.2 netmask 255.255.255.0
  • 开启转发 sysctl -w net.ipv4.ip_forward=1 sed -i '/net.ipv4.ip_forward/ s/0/1/' /etc/sysctl.conf
  • 设置隧道端来源为NAT网络,使得国内服的请求可以被NAT iptables -t nat -A POSTROUTING -s 192.168.168.1 -j MASQUERADE

##创建VPN

VPN网段是10.8.2.0/32

##修改国内服路由表 将来自VPN的所有流量,路由经IPIP隧道到国外服务器。

  • 创建新的IP路由表2,优先级1500(仅次于local路由表),用于路由来自VPN的请求 ip rule add from 10.8.0.0/16 table 2 pref 1500
  • 设置IP路由表2的默认路由设置到IPIP隧道对端的国外服192.168.168.2 ip route add default via 192.168.168.2 table 2