Skip to content

Instantly share code, notes, and snippets.

@hsupu
Last active December 15, 2019 16:06
Show Gist options
  • Save hsupu/be65e69a391ecd5766c28de540067d43 to your computer and use it in GitHub Desktop.
Save hsupu/be65e69a391ecd5766c28de540067d43 to your computer and use it in GitHub Desktop.
不同 IP 协议间的端口转发

所用工具:

  • Linux MacOS 使用 socat,需要从包管理器安装;
  • Windows 使用系统自带的 netsh;

4to6

使用 SOCAT

socat TCP4-LISTEN:7777,bind=127.0.0.1,reuseaddr,fork TCP6:[目标地址]:7778

使用 NETSH

开启:

netsh interface portproxy add v4tov6 listenaddress=127.0.0.1 listenport=7777 connectaddress=[目标地址] connectport=7778

注意,这里的监听地址不能使用 any 这个值,而只能使用 0.0.0.0 [::] 这样的值。

关闭:

netsh interface portproxy delete v4tov6 listenaddress=127.0.0.1 listenport=7777

如果没有生效,那么需要去开启“IP Helper”服务。

如果监听的是非环回地址,那么还需要增加防火墙规则:

netsh advfirewall firewall add rule name=4to6_7777 protocol=TCP dir=in localip=any localport=7777 action=allow

注意,防火墙里的地址是可以使用 any 的。

6to4

与之相对,把 4 6 对换即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment