显示标签为“Proxy”的博文。显示所有博文
显示标签为“Proxy”的博文。显示所有博文

2011年12月2日星期五

用Squid在SSH开启个Tunnel代理


用Squid在SSH开启个Tunnel代理

2011年12月2日 | 分类: 代理工具 | 标签: , , , , 
这是icyboy自己想出来的想法,并在google和一些国外大神的帮助下,总算搞清楚了如何操作。
总所周知,squid是一个非常出色的HTTP代理软件,常用于用于CDN分发、Load Balance等高端服务器操作。现在,我们大材小用,把它用来钻洞翻墙。据身在国内的icyboy说,他测试下来的结果,squid使用效率比ssh动 态转发高效得多,当然这得归功于squid本身了。
首先,我们需要一台能在国内访问的国外VPS或者独立主机,日美韩三国的速度比较不错。博客里有很多卖vps的商家推荐,建议自己去看看。
第二,VPS需是Linux系统,Windows配置这里不讲。原理是通过SSH映射本机一个端口到服务器上squid的一个端口,这样,我们的代理就直接通过了SSH的加密,省下了不少GFW关键字重置的麻烦。
配置过程:
使用SSH命令安装squid,本例只拿Debian做一个例子。
apt-get install squid
安装好后直接修改/etc/squid/squid.conf的配置文件,如下内容:

# Recommended minimum configuration:
#
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
acl all src 0.0.0.0/0.0.0.0
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
#acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
#acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
#acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
#acl localnet src fc00::/7 # RFC 4193 local private network range
#acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access deny manager
# Deny requests to certain unsafe ports
#http_access deny !Safe_ports
# Deny CONNECT to other than secure SSL ports
#http_access deny CONNECT !SSL_ports
# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on “localhost” is a local user
#http_access deny to_localhost
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
#http_access allow localnet
http_access allow localhost
acl INTRANET dstdomain .intranet.example.com critical.example.com
http_access allow INTRANET
append_domain .domainname.com
# And finally deny all other access to this proxy
http_access deny all
# Squid normally listens to port 3128
http_port 3128
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 800 16 256
cache_mem 500 MB
# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid
# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320

其实最复杂的部分就是配置squid的过程,现在已经简化好了。这个配置里需要重点注意的是三行:
acl INTRANET dstdomain .intranet.example.com critical.example.com
http_access allow INTRANET
http_access deny all
除了本机,拒绝其他任何形式的连接。小老外在第三行这里吃过亏,deny all机器认不出来。我就在上面的配置文件里加上了一行acl all src 0.0.0.0/0.0.0.0就能用了。icyboy的配置并没有这一行。如果你最后的测试结果有问题,可以试着把这行去掉。Squid的端口可以自己 改,不一定要默认的3128。记得修改完配置后/etc/init.d/squid restart重启一下squid。
好了之后,下载plink.exe,在相同文件夹下创建一个bat批处理,命令行如下:
plink.exe -2 -P 22 -pw sshpassword -L localhost:9090:localhost:3128 username@serverIPaddress
命令中-p是端口号,如果你的SSHd端口被修改过,请自己更改。sshpassword是你的ssh密码,最后一个username@serverIPaddress我不多讲了吧。9090是本机映射的端口,3128是服务器squid端口。
然后是本机设置。
Firefox可以通过插件或者直接设置,通过HTTP代理来获得翻墙功能。Chrome建议大家装个Switchy!中文汉化版,在里面新建一个squid的配置。具体也不多讲了吧,这步是最简单的了。
其实Squid除了用SSH加密之外,还可以用SSL加密,具体操作类似,配置不同而已。在服务器443端口开个squid,把所有流量都代理出去。想试试的就直接Google吧。

2011年11月27日星期日

使用免费的amazon EC2 服务部署SSH翻墙

使用免费的amazon EC2 服务部署SSH翻墙

原文:http://lianlay.com/?p=128

在开始阅读本篇文章的时候我假定你已经成功注册了amazon ec2的服务,并且开启了一个免费的实例。
这方面在网上的现成的教程比较多,请同学们自行查找。
下面是如何利用这个免费的实例搭建一个ssh代理服务从而实现翻墙。
第一步: 登陆到你的ec2服务器修改sshd配置文件
cd /etc/ssh //进到ssh目录
cp sshd_config sshd_config.bak //备份一下一下源配置文件
sudo vi sshd_config //修改配置文件
找到AllowTcpForwarding 改为yes 允许TCP转发
AllowTcpForwarding yes //允许TCP转发
因为Amazon默认使用比较安全证书方式进行登陆, 但是如果大家自己aws的免费配额使用不完希望分配其他的同学使用,
那么再让那些同学密码进行登录是个比较省事儿的方法.
如果如果你想这么做的话,可以在里面修改成为密码登陆方式,但是你必须知道密码登陆方式没有密钥方式相对安全。
在配置文件里面找到PasswordAuthentication 项改为yes 就可以改为密码登录方式
PasswordAuthentication yes //LL就是采用的这种方式,可以省掉不少麻烦
保存退出sshd文件
执行下面这行代码重启sshd服务使之生效
sudo /etc/init.d/sshd restart
第二步: 建立一个专门用于链接ssh的账户组
sudo groupadd ec2ssh //建立ec2ssh用户组
sudo useradd -d /home/ec2ssh -m -g ec2ssh -s /bin/false ec2ssh //增加用户ec2ssh并且创建一个ec2ssh的目录并且属于组ec2ssh并且禁止shell
这里一定要禁掉shell以降低安全问题,以后给自己的同学和朋友建立账户的时候就可以了。
当然要记得给你新建的账户改密码
sudo passwd ec2ssh
第三步: 客户端配置
推荐下载一个客户端Tunnelier http://www.bitvise.com/
填入host和端口号: 就是你部署的ssh服务器地址
右面填入用户名
initial method 选择password 填入密码

再到option选项卡,勾掉Open Terminal 和 Open SFTP




在到service里面 enable proxy forwarding 设置interface和port

在这里设置的127.0.0.1:8888就是对应要设置到浏览器里面的值。
设置好后,点击界面最低端的login可以查看是否可以成功连接到服务器。
然后通过设置好的浏览器就可以上网了。
这里提一句请选择可以支持socks5的代理。Tunnelier 官方说对http代理支持的有问题。
这方面在网上的现成的教程也比较多,请同学们自行查找。
PS: 由于国情所致,从国内的部分网络到aws有时候会不稳定。
建议这种方式配合之前文章介绍的Goagent共同使用。
AWS Free Tier正好补足了GAE流量上的限制。GAE也弥补了AWS时而不稳定的缺陷。
查看GAE翻墙教程 http://lianlay.com/?p=123
一些注意事项
AWS Free Usage Tier (Per Month):
750 hours of Amazon EC2 Linux Micro Instance usage (613 MB of memory and 32-bit 
and 64-bit platform support) – enough hours to run continuously each month
* 750 hours of an Elastic Load Balancer plus 15 GB data processing
* 10 GB of Amazon Elastic Block Storage, plus 1 million I/Os and 1 GB of snapshot 
storage
* 5 GB of Amazon S3 standard storage, 20,000 Get Requests, and 2,000 Put
 Requests
* 15 GB of bandwidth out aggregated across all AWS services
* 25 Amazon SimpleDB Machine Hours and 1 GB of Storage** 100,000 Requests of 
Amazon Simple Queue Service
* 100,000 Requests, 100,000 HTTP notifications and 1,000 email 
notifications for Amazon Simple Notification Service*
* 10 Amazon Cloudwatch metrics, 10 alarms, and 1,000,000 API requests**  
针对于我们使用的EC2重点如下:
对于Amazon EC2的free tier包括每月750小时的micro instance(linux) micro内存。24*31=744 正好是一个月。
Free Tier包含每月各15GB的上传下载
免费EBS容量为10GB 含1 GB 快照容量,1百万次I/Os
详细内容这里看 http://aws.amazon.com/free/