百度空间 | 百度首页 
               
 
查看文章
 
使用HTun通过http代理服务器建立vpn连接
2007-05-03 23:54

HTun 允许你把数据封装在HTTP/1.1 或者HTTP/1.0协议中再通过一个 HTTP proxy 的80端口出去,建立两台机器之间建立IP VPN连接,通过这样的办法,可以成功避免防火墙的封锁。

这个软件是对于内部网络只开通了http代理来访问外部网络(比如squid),或者内部网络对网络监管得特别严,只允许标准的http数据出去,而你又想连到外网玩CS、QQ游戏、上QQ时的穿透利器。虽然一些vpn软件也支持http代理,比如openvpn也支持http代理,但是它必须使用http代理的connect功能,很多http代理服务器就没有开通connect功能,所以openvpn在这样的网络环境下是不能连接到外部网络中的。HTun使用了标准的http中的post/get,可以成功穿透防火墙!

以上为原理示意图

HTun 建立通过一个合法的HTTP请求的数据传送来建立两台机器之间的点对点连接。HTun服务器放置在外部的Internet 网络中,它监听在80端口接受HTun客户端的连接请求。HTun客户端运行在一个内部网络中,它通过http代理连接到HTun服务器。

HTun只能在linux下运行,使用HTun,必须要求外网有一台HTun服务器正常工作,下面为安装和设置的方法:

1、你的linux内核必须支持tun,加载tun驱动。

2、下载htun的源码,解压、编译、安装

wget http://htun.runslinux.net/dist/htun-0.9.6.tar.gz

#>tar -xvzf htun-0.9.6.tar.gz

#>cd htun-0.9.6/src
#>make

#>cp htund /usr/local/bin
#>cp ../doc/htund.conf /etc

以下为网络示意图:

下面为htun服务器的配置文件:
shashank@zidler:# cat /etc/htund.conf
options {
     daemonize no                    
     logfile /var/log/htund.log      
     tunfile /dev/net/tun
     debug yes
}               

server {
     iprange 192.168.254.0/24
     server_port 8888                      #both server_port and secondary_port must be specified.
     secondary_port 8889                   #Make sure u have given access to these ports in squid.
     max_clients 10
     redirect_host mia.ece.uic.edu
     redirect_port 80
     max_pending 40
     idle_disconnect 1800
     clidata_timeout 20
     min_nack_delay 150
     packet_count_threshold 10
     packet_max_interval 10
     max_response_delay 200
}
--------------------------------------------
shashank@mia:#> cat /etc/htund.conf
options {
     daemonize no
     logfile /var/log/htund.log
     tunfile /dev/net/tun
     debug yes
}               

client {
     do_routing no
     protocol 2
     proxy_ip 131.193.50.187           #Ip address of spiff
     proxy_port 3128                   #Default port for squid

# Only uncomment proxy_user and proxy_pass if you need to authenticate with
# the proxy. Having them set unnecessarily creates extra HTTP overhead.
#    proxy_user joeblow
#    proxy_pass SuperSecret123

     server_ip 131.193.50.184
     server_port 8888
     secondary_server_port 8889

     if_name eth0
     iprange 192.168.254.0/24

     connect_tries 2
     reconnect_tries 4
     reconnect_sleep_sec 30
     channel_2_idle_allow 30
     min_poll_interval_msec 200
     max_poll_interval 30
     poll_backoff_rate 3
     ack_wait 10
}
  1. 启动 htun 服务器:
    #>htund -d
    
  2. 检查tun0界面是否启动.
    [shashank@mia shashank]# ifconfig
    --SNIP--
    tun0       Link encap:Point-to-Point Protocol   
               inet addr:192.168.254.1   P-t-P:192.168.254.0   Mask:255.255.255.255
               UP POINTOPOINT RUNNING NOARP MULTICAST   MTU:1500   Metric:1
               RX packets:6 errors:0 dropped:0 overruns:0 frame:0
               TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
               collisions:0 txqueuelen:10 
               RX bytes:504 (504.0 b)   TX bytes:504 (504.0 b)
    
  3. 然后手动添加路由表. For example, on zidler I use the command
    shashank@zidler:# route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.254.1
    
    Similarly on mia, I will use the command:
    shashank@mia:# route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.254.0
    
  4. Also check if the routes have been established properly using netstat -rn command and ping.
  5. To kill htund, just use ps -A | grep htund, look at the process number and kill -9 processNumber.
  6. 在建立了vpn以后,可以在htun客户端添加默认路由表,让除了到proxy的数据都通过vpn出去,然后使用iptables设置nat,最后将其它电脑的网关都设置为htun客户端的IP地址,这样不用代理服务器,所有的数据包都是通过vpn NAT出去,你就可以突破封锁,开心的玩游戏了!!

类别:网络工程 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu