ssh 转发代理上网
这个问题困扰了我好几天,我在亚马逊开了一台云服务器,linux但是搭建l2tp服务器怎么弄就是连接不上,pptp倒是可以但是mac上不支持。
今天终于发现可以使用ssh来进行代理,然后再本地做端口转发,然后再连接本地的转发端口就可以了;
要准备的东西:
1,有一台处于境外的linux服务器,且可以ssh远程登陆上去;
2,在上面创建一个无权限用户。设置好密码;
3,在本地开启一个监听端口并转发到远程服务器;
4,连接本地监听端口;
好了先来点儿理论吧!
ssh相关选项:
-
-V
显示版本:
ssh -V
OpenSSH_6.6.1p1 Ubuntu-2ubuntu2, OpenSSL 1.0.1f 6 Jan 2014
-
-f
输入密码后进入后台模式(Requests ssh to go to background just before command execution.) -
-N
不执行远程命令,用于端口转发( Do not execute a remote command. This is useful for just for warding ports (protocol version 2 only).) -
-D
socket5代理(Specifies a local “dynamic” application-level port forwarding.Currently the SOCKS4 and SOCKS5 protocols are supported, and ssh will act as a SOCKS server.) -
-L
tcp转发(Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.) -
-C
使用数据压缩,网速快时会影响速度(Compression is desirable on modem lines and other slow connections, but will only slow down things on fast networks.The compression algorithm is the same used by gzip)
建立SOCKS5代理:
ssh -qfTnN -D bindaddress:port name@server
- bindaddress: 指定绑定ip地址
- port: 指定侦听端口
- name: ssh服务器登录名
- server: ssh服务器地址
例:
ssh qfTnN -D 127.0.0.1:1080 xiaoming@158.123.45.37
这样就建立SOCKS5代理。
使用SOCKS5代理
例:
-
chrome:
chrome需要使用命令指定SOCKS5代理:
google-chrome --proxy-server="socks://127.0.0.1:1080"
-
firefox:
在preferences=>advanced=> Network->connection->Settings里,勾选Manual proxy configuration,并将其它项清空,SOCKS Host设置为127.0.0.1,port设置为1080, 并勾选Remote DNS(勾选后可防止本地DNS污染),如图。
-
其它,请搜索具体关于各自配置的文章:
-
使用代理插件switchysharp等
-
在系统自带的代理设置全局代理
-
使用其它SOCKS客户端实现代理,比如redsocks
这样你的浏览器就可以进行代理上网了;
实现终端代理上网;
在终端执行:
export http_proxy=socks5://127.0.0.1:1080 export https_proxy=socks5://127.0.0.1:1080
如果是http的代理:
export http_proxy=http://127.0.0.1:1080/ export https_proxy=http://127.0.0.1:1080/
这样在终端访问网络的时候就会自动进行代理了 如果系统重启了代理就失效了
上面是针对mac系统的,其他linux系统没有试过,有兴趣可以试试;
最后不得不说中国网络与外界联系封锁的太厉害了,好的技术性的东西不翻墙都拿不到;
哎。。。。