利用双栈VPS搭建6in4隧道

目的

SERVER1 只支持ipv4, SERVER2 同时支持ipv4和ipv6,构建隧道使SERVER1也能够访问ipv6网站。

部署步骤

SERVER1

1
2
3
4
ip tunnel add ipv6 mode sit remote IPV4_OF_SERVER2 local IPV4_OF_SERVER2 ttl 255
ip link set ipv6 up
ip addr add 2604:xxxx:xxxx:xxxx::xxxx:2/128 dev ipv6
ip route add ::/0 dev ipv6

SERVER2

1
2
3
4
ip tunnel add provideipv6 mode sit remote IP_OF_SERVER1 local IP_OF_SERVER2 ttl 255
ip link set proviceipv6 up
ip addr add 2604:xxxx:xxxx:xxxx::xxxx:1/128 dev provideipv6
ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

删除步骤

SERVER1

1
2
3
ip route del ::/0 dev ipv6
ip link set ipv6 down
ip tunnel del ipv6 mode

SERVER2

1
2
3
ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
ip link set proviceipv6 down
ip tunnel del provideipv6 mode sit remote IP_OF_SERVER1 local IP_OF_SERVER2 ttl 255

后记

此法只能让SERVER1支持访问ipv6的网站,外界不能通过它的ipv6地址访问SERVER1.