使用v2ray+TLS+cloudflare连接另一个局域网

本文搭建的服务器,可以用于连接公司、学校的内网。比如进学习内网查成绩、免费下载论文、连接公司内网服务器之类的。请勿用于其他用途。

事情是这样的,本来我使用了多年的ss,但是ss的问题很大,尤其是运营商的qos策略,导致丢包严重,体验一直很差。不过有一天我看到了v2ray这个东西。发现还挺好用,而且可以直接走websocket,这样就可以直接利用cloudflare来规避服务器ip被屏蔽的问题了,甚至可以让已经被屏蔽的服务器起死回生。
我这里使用的就是一个ip已经被屏蔽了的服务器,通过cloudflare使其复活。

本文方法基本参考了https://toutyrater.github.io(这个站在墙外)的内容

前期准备

首先要连上服务器,我只能用另一条服务器来连这台壮烈牺牲的服务器了:

root@ubuntu:~# ssh root@xxx.xxx.xxx.xxx
The authenticity of host 'xxx.xxx.xxx.xxx' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'xxx.xxx.xxx.xxx' (ECDSA) to the list of known hosts.
root@xxx.xxx.xxx.xxx's password: 
Welcome to Ubuntu 16.04 LTS (GNU/Linux 2.6.32-042stab125.5 x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Sun Feb  3 04:54:09 2019 from 97.64.17.72
root@ho:~# 

由于这台服务器还装了apache,我要先把它卸载掉:

sudo apt-get –purge remove apache2
sudo apt-get –purge remove apache2-common
sudo apt-get –purge remove apache2-utils
sudo apt-get autoremove apache2

校准时间,一般没什么问题:

root@ho:~# date -R
Sun, 03 Feb 2019 08:36:35 -0500
root@ho:~# sudo date --set="2017-01-22 16:16:23"
Sun 22 Jan 16:16:23 GMT 2017

安装、配置v2ray

然后直接用一键脚本:

root@ho:~# wget https://install.direct/go.sh
--2019-02-03 08:38:00--  https://install.direct/go.sh
Resolving install.direct (install.direct)... 104.27.174.71, 104.27.175.71, 2606:4700:30::681b:af47, ...
Connecting to install.direct (install.direct)|104.27.174.71|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: 'go.sh'

go.sh                        [ <=>                              ]  13.34K  --.-KB/s    in 0s      

2019-02-03 08:38:01 (30.5 MB/s) - 'go.sh' saved [13661]
root@ho:~# bash go.sh
Installing V2Ray v4.14.0 on x86_64
Downloading V2Ray.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   608    0   608    0     0   1122      0 --:--:-- --:--:-- --:--:--  1123
100 11.5M  100 11.5M    0     0  3682k      0  0:00:03  0:00:03 --:--:-- 4590k
Extracting V2Ray package to /tmp/v2ray.
Archive:  /tmp/v2ray/v2ray.zip
  inflating: /tmp/v2ray/config.json  
   creating: /tmp/v2ray/doc/
  inflating: /tmp/v2ray/doc/readme.md  
  inflating: /tmp/v2ray/geoip.dat    
  inflating: /tmp/v2ray/geosite.dat  
   creating: /tmp/v2ray/systemd/
  inflating: /tmp/v2ray/systemd/v2ray.service  
   creating: /tmp/v2ray/systemv/
  inflating: /tmp/v2ray/systemv/v2ray  
  inflating: /tmp/v2ray/v2ctl        
 extracting: /tmp/v2ray/v2ctl.sig    
  inflating: /tmp/v2ray/v2ray        
 extracting: /tmp/v2ray/v2ray.sig    
  inflating: /tmp/v2ray/vpoint_socks_vmess.json  
  inflating: /tmp/v2ray/vpoint_vmess_freedom.json  
PORT:21806
UUID:08c2a320-6485-495f-80a7-d12ff7400512
Created symlink from /etc/systemd/system/multi-user.target.wants/v2ray.service to /etc/systemd/system/v2ray.service.
V2Ray v4.14.0 is installed.

接着更改配置:

root@ho:~# vi /etc/v2ray/config.json

把文件内容全部删掉。
我推荐的配置如下:

{
    "log": {
        "loglevel": "warning", 
        "access": "/var/log/v2ray/access.log", 
        "error": "/var/log/v2ray/error.log"
    }, 
    "inbounds": [
        {
            "port": 10000, 
            "listen": "127.0.0.1", 
            "protocol": "vmess", 
            "settings": {
                "clients": [
                    {
                        "id": "你设置的uuid", 
                        "alterId": 64
                    }, 
                    {
                        "id": "你设置的uuid", 
                        "alterId": 64
                    }
                ]
            }, 
            "streamSettings": {
                "network": "ws", 
                "wsSettings": {
                    "path": "/vpath"
                }
            }
        }
    ], 
    "outbounds": [
        {
            "protocol": "freedom", 
            "settings": { }
        }
    ]
}

配置里的uuid就是相当于每个账号的链接密码,uuid可以去这个网站生成
配置里可以加入多个uuid设置

配置完了就可以启动v2ray了:

root@ho:~# sudo systemctl start v2ray

配置caddy

这里用到的服务器代理是caddy,为什么用它?因为方便呀

打开官网下载页面(https://caddyserver.com/download),选好你适合的版本,复制链接,用wget扔到服务器上:

root@ho:~# wget https://caddyserver.com/download/linux/amd64?license=personal&telemetry=on

解压:

root@ho:~# tar -zxvf amd64\?license\=personal 
README.txt
LICENSES.txt
CHANGES.txt
EULA.txt
init/
init/README.md
init/freebsd/
init/freebsd/caddy
init/linux-systemd/
init/linux-systemd/README.md
init/linux-systemd/caddy.service
init/linux-sysvinit/
init/linux-sysvinit/README.md
init/linux-sysvinit/caddy
init/linux-upstart/
init/linux-upstart/README.md
init/linux-upstart/caddy.conf
init/linux-upstart/caddy.conf.centos-6
init/linux-upstart/caddy.conf.ubuntu-12.04
init/mac-launchd/
init/mac-launchd/README.md
init/mac-launchd/com.caddyserver.web.plist
caddy
root@ho:~# 

啊。。解压到根目录了。。
算了不管了,能跑起来就行(懒

接着新建一个配置文件:

root@ho:~# vi Caddyfile

文件内容如下:

你绑定的域名
{
  log ./caddy.log
  proxy /vpath localhost:10000 {
    websocket
    header_upstream -Origin
  }
}

保存,跑起来试一试,运行前记得把域名指向该服务器,
如果已经套用了cloudflare,请把加速暂时关掉,改为直连服务器:

root@ho:~# ./caddy 
Activating privacy features... 

Your sites will be served over HTTPS automatically using Let's Encrypt.
By continuing, you agree to the Let's Encrypt Subscriber Agreement at:
  https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf
Please enter your email address to signify agreement and to be notified
in case of issues. You can leave it blank, but we don't recommend it.
  Email address: 填上你的邮箱
2019/02/03 09:20:32 [INFO] acme: Registering account for lolicon@papapoi.com
2019/02/03 09:20:32 [INFO] [你的域名] acme: Obtaining bundled SAN certificate
2019/02/03 09:20:32 [INFO] [你的域名] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz/xxxxxxx-xxxx_xxx-xxxxxx
2019/02/03 09:20:32 [INFO] [你的域名] acme: use tls-alpn-01 solver
2019/02/03 09:20:32 [INFO] [你的域名] acme: Trying to solve TLS-ALPN-01
2019/02/03 09:20:38 [INFO] [你的域名] The server validated our request
2019/02/03 09:20:38 [INFO] [你的域名] acme: Validations succeeded; requesting certificates
2019/02/03 09:20:40 [INFO] [你的域名] Server responded with a certificate.
done.
https://你的域名
http://你的域名
WARNING: File descriptor limit 1024 is too low for production servers. At least 8192 is recommended. Fix with `ulimit -n 8192`.

成功运行,可以先退出了

按照提示,我们可以把端口限制开放:

root@ho:~# ulimit -n 8192

这时最好准备一个网页,静态的html就够了,用来作为网站打开后显示的内容,蒙混过关用233
index.html和其他文件或文件夹放到和caddy运行程序同级的目录就可以了

直接把caddy扔到screen(如果没有screen,记得装上):

root@ho:~# screen -dmS caddy ./caddy

cloudflare的配置

cloudflare上面只需要更改一项设置就可以了,CryptoSSL改成Full,等到状态变为证书激活,就可以访问了:

END

这样,服务端就配置完了,客户端按上面服务端的配置来连接就行了

后来补充:客户端配置

这部分主要是填之前的坑,同时也为各位提供一个良好、方便的使用工具建议。

在这里推荐的pc客户端工具就是:V2RayGCon

方便快捷、自动下载v2 core文件,全自动一键更新v2 core文件、自带插件功能:自带pac服务器、插件能跑lua

这个工具之前的项目被删掉了,现在的新项目也不知是原作者还是他人接手(原作者可能性较大)

我们可以从这里下载客户端:
https://github.com/UudrSgMEZ/V2RayGCon/releases/latest

下载最新版里的那个V2RayGCon-box.zip就行了,解压打开V2RayGCon.exe

按菜单里的文件添加mess客户端,按之前部署v2服务器端的选项填写即可:

接着推荐把这两个勾上,一方面方便后面的设置开机自启和设置pac,另外也能节省你的服务器流量;同时保证设置http模式代理;最后打开这个客户端连接:

客户端pac设置

pac的好处是,开着软件不用管,自动给你过滤需要代理的网站,其他网站正常直连,完全不影响你的使用

打开菜单里的窗口选项,选择插件选项卡,把proxysetter使用打上勾,保存设置:

右击任务栏小图标,按图示打开这个插件的设置:

下载我推荐的pac文件(就是我正在用的,下载后记得解压):
https://www.chenxublog.com/wp-content/uploads/2019/06/black.7z

按下图左边的进行设置,并点击保存,即可完成设置:

开机自启

开机自启的方法这是基本常识了

按下windows徽标键+r

输入:%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

回车会出来启动项文件夹

把快捷方式扔到文件夹,完事了

True End

这回是真的结束了

6 Comments

  1. Google Chrome 55.0.2883.87 Google Chrome 55.0.2883.87 Windows 10 x64 Edition Windows 10 x64 Edition
    Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36

    image.src=”https://youtube.com/favicon.ico”太坏了

    1. Vivaldi 2.2.1388.37 Vivaldi 2.2.1388.37 Android 8.0.0 Android 8.0.0
      Mozilla/5.0 (Linux; Android 8.0.0; MIX 2 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 Vivaldi/2.2.1388.37

      完美禁止小白查看文章🌸🐓
      查看文章的都是已经会这个技术的人,逻辑完美

  2. Google Chrome 72.0.3626.105 Google Chrome 72.0.3626.105 Android 9 Android 9
    Mozilla/5.0 (Linux; Android 9; Pixel 2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.105 Mobile Safari/537.36

    厉害了,还能检测机型系统

    1. Vivaldi 2.2.1388.37 Vivaldi 2.2.1388.37 Android 8.0.0 Android 8.0.0
      Mozilla/5.0 (Linux; Android 8.0.0; MIX 2 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 Vivaldi/2.2.1388.37

      显示ua而已,另外我手机的ua末尾的vivaldi是假的。。

  3. Vivaldi 2.5.1525.48 Vivaldi 2.5.1525.48 Windows 10 x64 Edition Windows 10 x64 Edition
    Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.172 Safari/537.36 Vivaldi/2.5.1525.48

    神秘代码(滑稽

    j("article").css("visibility","visible");
    isNotInChina = true;
    image.onerror = function(){alert("ok");}

  4. Google Chrome 74.0.3729.169 Google Chrome 74.0.3729.169 Windows 10 x64 Edition Windows 10 x64 Edition
    Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36

    神秘代码我抱走啦

发表评论

电子邮件地址不会被公开。 必填项已用*标注