2009-10-29 00:51:34 +0000 2009-10-29 00:51:34 +0000
120
120
Advertisement

如何通过SSH对所有的网络流量进行隧道处理?

Advertisement

每当我从一个不安全的地方(比如公共wifi)使用互联网时,我喜欢使用ssh隧道(ssh -D port host)来确保我的流量不能被嗅探。不幸的是,似乎有许多应用程序不提供指定代理的方法(Flash是一个主要的例子)。

感觉应该有某种方法可以为我的计算机的所有网络流量使用隧道,但我完全不知道如何做到这一点。如果有任何帮助,我将非常感激。

Advertisement
Advertisement

答案 (7)

65
65
65
2014-05-23 16:08:57 +0000

要做到你想要的,我推荐 sshuttle

你可以这样使用它。

./sshuttle -r username@sshserver 0.0.0.0/0 -vv

它将自动为你隧道所有的TCP流量。你可以添加--dns参数来让它也隧道你的DNS流量。远程服务器只需要安装Python即可。

如果你只想隧道特定的程序,我会推荐 proxychains

安装完毕后,像这样启动ssh socks代理。

ssh -fNTD 127.0.0.1:<local port> username@sshserver

这样就会启动一个 “SOCKS "代理服务器 在上监听.

然后编辑/etc/proxychains.conf,将其指向与相同的端口。

最后启动你想要代理的程序,就像这样。

proxychains <program name>

应该就可以了。然而,有一些程序在使用代理链时可能会出现问题。此外,请记住,在Firefox中,你必须更改关于:config下的附加项目,以迫使它通过代理进行DNS查询,而不是绕过它。

补充一点,在网页浏览器上。如果他们支持socks代理,你不需要做任何额外的事情来让他们使用上面提到的,ssh隧道,只需要输入127.0.0.1作为socks代理服务器,输入<local port>作为代理端口。

EDIT 3/29/16

由于这个帖子还是有一些涨粉,我想我应该更新一下。Proxychains仍然在大多数Linux仓库中,并且仍然在Linux上工作。然而,这个项目实际上已经被放弃了,而且在OSX上也不能工作。对于Linux或OSX,我强烈建议升级到一个仍在维护的fork:proxychains-ng。 https://github.com/rofl0r/proxychains-ng

除了可以在Linux和OSX中使用,它还很容易编译,而且对DNS隧道的支持也更好。

我还应该提到另一个选项,那就是redsocks。它的工作原理和proxychains(-ng)类似,也可能在你的distrepo中。 https://github.com/darkk/redsocks

EDIT 11/27/19 如果你选择代理链,请使用代理链-ng。与传统版本相比,有一些严重的bug修复,比如。 https://github.com/rofl0r/proxychains-ng/issues/292

50
50
50
2011-07-18 10:24:01 +0000

man ssh给出的例子正是如此。一个基于ssh的vpn。

SSH-BASED VIRTUAL PRIVATE NETWORKS
     ssh contains support for Virtual Private Network (VPN) tunnelling using
     the tun(4) network pseudo-device, allowing two networks to be joined
     securely. The sshd_config(5) configuration option PermitTunnel controls
     whether the server supports this, and at what level (layer 2 or 3 traf-
     fic).

     The following example would connect client network 10.0.50.0/24 with
     remote network 10.0.99.0/24, provided that the SSH server running on the
     gateway to the remote network, at 192.168.1.15, allows it:

       # ssh -f -w 0:1 192.168.1.15 true
       # ifconfig tun0 10.0.50.1 10.0.99.1 netmask 255.255.255.252

snip

Since a SSH-based setup entails a fair amount of overhead, it may be more
     suited to temporary setups, such as for wireless VPNs. More permanent
     VPNs are better provided by tools such as ipsecctl(8) and isakmpd(8).

一旦你有了新的接口,你只需要把它变成默认路由,这是一个不同的问题。

6
Advertisement
6
6
2009-11-01 17:40:29 +0000
Advertisement

在ssh中寻找 “隧道 "选项。这将创建一个隧道设备,你可以给它分配一个IP地址,然后你改变默认路由来使用该隧道。

4
4
4
2011-07-18 08:55:38 +0000

我已经开发了一个软件,可以让你通过SOCKS5代理转发所有TCP和可选的UDP,全系统。 http://code.google.com/p/badvpn/wiki/tun2socks

它甚至可以安装在路由器上,转发局域网内计算机的所有连接。

0
Advertisement
0
0
2013-03-12 22:57:21 +0000
Advertisement

SSH-BASED VIRTUAL PRIVATE NETWORKS ssh 包含了对使用 tun(4) 网络伪设备进行虚拟专用网络 (VPN) 隧道的支持,允许两个网络安全地连接。sshd_config(5) 配置选项 PermitTunnel 控制了服务器是否支持这个功能,以及支持的级别 (第 2 层或第 3 层 traf- fic)。

The following example would connect client network 10.0.50.0/24 with
 remote network 10.0.99.0/24 using a point-to-point connection from
 10.1.1.1 to 10.1.1.2, provided that the SSH server running on the gateway
 to the remote network, at 192.168.1.15, allows it.

 On the client:

       # ssh -f -w 0:1 192.168.1.15 true
       # ifconfig tun0 10.1.1.1 10.1.1.2 netmask 255.255.255.252
       # route add 10.0.99.0/24 10.1.1.2

 On the server:

       # ifconfig tun1 10.1.1.2 10.1.1.1 netmask 255.255.255.252
       # route add 10.0.50.0/24 10.1.1.1

 Client access may be more finely tuned via the /root/.ssh/authorized_keys
 file (see below) and the PermitRootLogin server option. The following
 entry would permit connections on tun(4) device 1 from user “jane” and on
 tun device 2 from user “john”, if PermitRootLogin is set to
 “forced-commands-only”:

   tunnel="1",command="sh /etc/netstart tun1" ssh-rsa ... jane
   tunnel="2",command="sh /etc/netstart tun2" ssh-rsa ... john

 Since an SSH-based setup entails a fair amount of overhead, it may be
 more suited to temporary setups, such as for wireless VPNs. More perma‐
 nent VPNs are better provided by tools such as ipsecctl(8) and
 isakmpd(8).
-2
-2
-2
2009-10-29 01:43:30 +0000

我只是想澄清一下 (ssh -D port host) 并不是一个100%安全的方法,不能让流量不被嗅探。添加 (ssh -D -c blowfish port host) 会是一个更好的选择,因为你至少给你的会话添加了加密。还有更多的选项你可以添加,但是很简单,只要在你的终端机上输入 “man ssh",或者在Google上输入 "man ssh "就可以得到完整的列表。

我想你要找的选项是建立一个VPN(虚拟专用网络)

在你建立自己的VPN之前,先看看这篇文章,了解一下两者之间的区别SSH vs. VPN) 或一个好的总结版。如果你决定走VPN路线,我推荐 OpenVPN ,它是免费的,有很多文档和支持。

-3
Advertisement
-3
-3
2009-11-01 17:47:59 +0000
Advertisement

使用这些例子。

  • 将远程主机上的80端口转发到本地主机上的8888

  • 将远程主机上的80端口转发到远程主机上的8888

干杯! :)

Advertisement

相关问题

6
10
19
12
2
Advertisement
Advertisement