此解决方案能搞定大多数有限制的网络环境,但有些防火墙会对外部流量调用 深度包检查 ,它们时常能屏蔽掉用本篇文章里的方式传输的信息。不过我到目前为止还没在这样的防火墙后测试过。同时,尽管我使用了很多基于密码学的工具(OpenVPN,HTTPS,SSH),我并没有非常严格地审计过这套配置方案(LCTT 译注:作者的意思是指这套方案能帮你绕过端口限制,但不代表你的活动就是完全安全的)。有时候甚至 DNS 服务都会泄露你的信息,很可能在我没有考虑周到的角落里会有遗漏。我强烈不推荐把此跳板配置方案当作是万无一失的隐藏网络流量的办法,此配置只是希望能绕过一些端口限制连上网络,而不是做一些危险的事情。
起步
让我们先从你需要什么说起,我用的是树莓派 2,装载了最新版本的 Raspbian,不过这个配置也应该能在树莓派 Model B 上运行;512MB 的内存对我们来说绰绰有余了,虽然性能可能没有树莓派 2这么好,毕竟相比于四核心的树莓派 2, Model B 只有一颗单核心 CPU。我的树莓派放置在家里的防火墙和路由器的后面,所以我还能用这个树莓派作为跳板访问家里的其他电子设备。同时这也意味着我的流量在互联网上看起来仿佛来自我家的 ip 地址,所以这也算某种意义上保护了我的匿名性。如果你没有树莓派,或者不想从家里运行这个服务,那你完全可以把这个配置放在一台小型云服务器上(LCTT 译注:比如 IPS )。你只要确保服务器运行着基于 Debian 的 Linux 发行版即可,这份指南依然可用。
root@test:~# apt-get install bind9 Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: bind9utils Suggested packages: bind9-doc resolvconf ufw The following NEW packages will be installed: bind9 bind9utils 0 upgraded, 2 newly installed, 0 toremoveand 0 not upgraded. Need toget 490 kB of archives. After this operation, 1,128 kB of additional disk space will be used. Do you want to continue [Y/n]? y
在我们把 BIND 作为缓存域名服务器之前,还有一些小细节需要配置。两个修改都在/etc/bind/named.conf.options里完成。首先你要取消注释掉 forwarders 这一节内容,同时你还要增加一个可以转发域名请求的目标服务器。作为例子我会用 Google 的 DNS 服务器(8.8.8.8)(LCTT 译注:国内的话需要找一个替代品);文件的 forwarders 节看上去大致是这样的:
上面那行配置会允许此 DNS 服务器接收来自其所在的网络(在本例中,我的网络就在我的防火墙之后)和本机的请求。下一步,你需要重启一下 BIND 的服务:
1 2 3 4 5 6
root@test:~# /etc/init.d/bind9 restart [....] Stopping domain name service...: bind9 waiting for pid 13209 to die . ok [ ok ] Starting domain name service...: bind9.
root@test:~# apt-get install openvpn Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: liblzo2-2 libpkcs11-helper1 Suggested packages: resolvconf The following NEW packages will be installed: liblzo2-2 libpkcs11-helper1 openvpn 0 upgraded, 3 newly installed, 0 toremoveand 0 not upgraded. Need toget 621 kB of archives. After this operation, 1,489 kB of additional disk space will be used. Do you want to continue [Y/n]? y
root@test:/etc/openvpn/easy-rsa# ./clean-all root@test:/etc/openvpn/easy-rsa# ./build-ca Generating a 4096 bit RSAprivate key ...................................................++ ...................................................++ writing new private key to 'ca.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a DistinguishedNameor a DN. There are quite a few fields but you can leave some blank. For some fields there will be a default value, If you enter '.', the field will be left blank. ----- CountryName (2 letter code) [US]: StateorProvinceName (full name) [CA]: LocalityName (eg, city) [SiliconValley]: OrganizationName (eg, company) [LinuxJournal]: OrganizationalUnitName (eg, section) [changeme]:SecTeam CommonName (eg, your name or your server's hostname [changeme]:test.linuxjournal.com Name [changeme]:test.linuxjournal.com Email Address [bill.childers@linuxjournal.com]:
root@test:/etc/openvpn/easy-rsa# ./build-key-server test.linuxjournal.com Generating a 4096 bit RSA privatekey ...................................................++ writing newprivatekeyto'test.linuxjournal.com.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank. For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [US]: State or Province Name (full name) [CA]: Locality Name (eg, city) [Silicon Valley]: Organization Name (eg, company) [Linux Journal]: Organizational Unit Name (eg, section) [changeme]:SecTeam Common Name (eg, your name or your server's hostname) [test.linuxjournal.com]: Name [changeme]:test.linuxjournal.com Email Address [bill.childers@linuxjournal.com]:
Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'US' stateOrProvinceName :PRINTABLE:'CA' localityName :PRINTABLE:'Silicon Valley' organizationName :PRINTABLE:'Linux Journal' organizationalUnitName:PRINTABLE:'SecTeam' commonName :PRINTABLE:'test.linuxjournal.com' name :PRINTABLE:'test.linuxjournal.com' emailAddress :IA5STRING:'bill.childers@linuxjournal.com' Certificate isto be certified until Sep 106:23:592025 GMT (3650 days) Sign the certificate? [y/n]:y
1 out of1 certificate requests certified, commit? [y/n]y Write out database with1new entries Data Base Updated
下一步需要用掉一些时间来生成 OpenVPN 服务器需要的 Diffie-Hellman 密钥。这个步骤在一般的桌面级 CPU 上会需要几分钟的时间,但在 ARM 构架的树莓派上,会用掉超级超级长的时间。耐心点,只要终端上的点还在跳,那么一切就在按部就班运行(下面的示例省略了不少的点):
1 2 3 4 5 6 7
root@test:/etc/openvpn/easy-rsa# ./build-dh GeneratingDH parameters, 4096 bit long safe prime, ↪generator 2 This is going to take a long time ....................................................+ <省略了不少的点>
root@test:/etc/openvpn/easy-rsa# ./build-key bills-computer Generating a 4096 bit RSAprivate key ...................................................++ ...................................................++ writing new private key to 'bills-computer.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a DistinguishedNameor a DN. There are quite a few fields but you can leave some blank. For some fields there will be a default value, If you enter '.', the field will be left blank. ----- CountryName (2 letter code) [US]: StateorProvinceName (full name) [CA]: LocalityName (eg, city) [SiliconValley]: OrganizationName (eg, company) [LinuxJournal]: OrganizationalUnitName (eg, section) [changeme]:SecTeam CommonName (eg, your name or your server's hostname) [bills-computer]: Name [changeme]:bills-computer Email Address [bill.childers@linuxjournal.com]:
Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf Check that the request matches the signature Signature ok The Subject's DistinguishedName is as follows countryName :PRINTABLE:'US' stateOrProvinceName :PRINTABLE:'CA' localityName :PRINTABLE:'Silicon Valley' organizationName :PRINTABLE:'Linux Journal' organizationalUnitName:PRINTABLE:'SecTeam' commonName :PRINTABLE:'bills-computer' name :PRINTABLE:'bills-computer' emailAddress :IA5STRING:'bill.childers@linuxjournal.com' Certificate is to be certified untilSep107:35:072025GMT (3650 days) Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries DataBaseUpdated root@test:/etc/openvpn/easy-rsa#
port 1194 proto tcp dev tun ca easy-rsa/keys/ca.crt cert easy-rsa/keys/test.linuxjournal.com.crt ## or whatever your hostname was key easy-rsa/keys/test.linuxjournal.com.key ## Hostname key- This file should be kept secret management localhost 7505 dh easy-rsa/keys/dh4096.pem tls-auth /etc/openvpn/certs/ta.key 0 server 10.8.0.0255.255.255.0# The server will use this subnet for clients connecting to it ifconfig-pool-persist ipp.txt push "redirect-gateway def1 bypass-dhcp"# Forces clients to redirect all traffic through the VPN push "dhcp-option DNS 192.168.1.1"# Tells the client to use the DNS server at 192.168.1.1 for DNS - replace with the IP address of the OpenVPN machine and clients will use the BIND server setup earlier keepalive 30240 comp-lzo # Enable compression persist-key persist-tun status openvpn-status.log verb 3
最后,你将需要在服务器上启用 IP 转发,配置 OpenVPN 为开机启动,并立刻启动 OpenVPN 服务:
root@test:/etc/openvpn/easy-rsa/keys# apt-get install sslh Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libconfig9 Suggestedpackages: apache2-doc apache2-suexec apache2-suexec-custom openbsd-inetd inet-superserver The following NEW packages will be installed: apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libconfig9 sslh 0 upgraded, 11 newly installed, 0 to remove and0not upgraded. Need to get 1,568 kB of archives. After this operation, 5,822 kB of additional disk space will be used. Do you want to continue [Y/n]? y
[....] Starting ssl/ssh multiplexer: sslhsslh disabled, please adjust the configuration to your needs [FAIL] and then setRUNto'yes'in /etc/default/sslh toenable it. ... failed! failed!
# Default options for sslh initscript # sourced by /etc/init.d/sslh
# Disabled by default, to force yourself # to read the configuration: # - /usr/share/doc/sslh/README.Debian (quick start) # - /usr/share/doc/sslh/README, at "Configuration" section # - sslh(8) via "man sslh" for more configuration details. # Once configuration ready, you *must* set RUN to yes here # and try to start sslh (standalone mode only)
RUN=yes
# binary to use: forked (sslh) or single-thread (sslh-select) version DAEMON=/usr/sbin/sslh