我已经看到这个在许多基于Android的项目,如“ProxyDroid”和“SSHTunnel”
在build立到代理或ssh隧道的连接的地方,然后使用iptables,它将通过你创build的隧道redirect所有的tcp请求。
它应该是像“-I OUTPUT -p tcp -destination-not xxx.xxx.xx.xx –redirect-to xx.xxx.xx.xx:port”,但我找不到任何例子,我不知道是否应该插入NAT或其他东西+我不知道是否应该有超过1个规则例如:一个更多的传入连接。
编辑:
似乎是不可能直接使用隧道或者我没有find如何做,而不使用代理,我不得不安装一个名为redsocks的程序作为本地服务器,使其工作。
至于这里使用的iptables命令是这样的:
# do not redirect connection sent to localhost so redirected connections can reach # its destination, otherwise we'll stuck in a loop. iptables -t nat -A OUTPUT -d 127.0.0.0/8 -j ACCEPT # Redirect all tcp connections except ones that are going to my tunnel server # to the local redsocks port iptables -t nat -A OUTPUT -p tcp ! -d tunnel.ip.goes.here -j REDIRECT --to-ports 31338
RedSocks回购: https : //github.com/darkk/redsocks
现在一切正常,但是我仍然需要知道,如果没有红袜(直接连接到隧道),这是否可以实现。
你的意思是通过SSHbuild立一个穷人的VPN? 如果是这样的话,这里有一些Ubuntu的文档:
https://help.ubuntu.com/community/SSH_VPN
基本上,您可以使用“-w”选项来设置一个新的tun0接口,并通过它开始路由。 不涉及iptables ,尽pipe你需要设置路由。
请注意,通过TCP进行TCP可能是一个坏主意 。 一个更好的select可能是一个简单的VPN,就像使用OpenVPN一样,但是这将比一个快速而又脏的ssh隧道更复杂。