前言:

本教程仅适用于局端(墙外服务器)混淆协议为tcp,加密可选是否加tls。其余加密协议均不适用。
不必担心tcp+tls的安全问题,经过博主验证,稳定运行4个多月没有问题,前提是不要公开分享。如果只用于一台国内中转服务器连接,更不用担心了!

要搭建墙内中转mtp,首先要一台墙内的服务器,当然如果你家里的网路有公网ip,你甚至可以在家里搭建!墙内的服务器价格普遍较高,不过电报只是一个聊天软件,几M的网速就可以满足正常的使用的啦!如果你是学生,去买一个阿里云学生机吧,一个月9.5就可以买得到!( https://promotion.aliyun.com/ntms/act/campus2018.html )

除了墙内的服务器,你还需要一个v2ray账号。要获得v2ray账号,首先就要去搭建一个v2ray服务器,搭建方法可以去看官网 www.v2ray.com 。

有了服务器还有v2ray,现在就一起搭建更稳定的墙内中转mtp吧。

如果你用的是阿里云,就必须要把内置的安骑士给干掉,否则几天后你会看到这样一封邮件:
您好 ,接主管部门通知,您的主机存在通过技术手段使其成为境内获取境外非法信息的途径等行为,根据《互联网信息服务管理办法》第十五条规定九不准内容及阿里云服务条款3.1.3.11.请您在二十四小时内停止上述行为,并做好自查。如逾期未处理或再次收到通知,阿里云将按要求及规定停止对您提供服务。

使用XShell登陆上你的服务器,然后输入下面的代码:

wget http://update.aegis.aliyun.com/download/uninstall.sh
chmod +x uninstall.sh
./uninstall.sh
wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh
chmod +x quartz_uninstall.sh
./quartz_uninstall.sh
pkill aliyun-service
rm -fr /etc/init.d/agentwatch /usr/sbin/aliyun-service
rm -rf /usr/local/aegis*

上面的代码是用来删除云服务器里面的安骑士软件,防止被封号。

把偷窥狂魔剔除出服务器之后就可以去安装v2ray了。

v2ray的安装很简单,下载 https://github.com/v2ray/v2ray-core/releases/download/v4.18.0/v2ray-linux-64.zip 然后解压,把里面的v2ray v2ctl两个文件上传到服务器里面,或者在服务器里面执行代码:

mkdir mtp
cd mtp
wget https://github.com/v2ray/v2ray-core/releases/download/v4.18.0/v2ray-linux-64.zip
unzip v2ray-linux-64.zip

ps: 如果下载太慢,可以试一下x-air的镜像:

https://xairforge.cloudns.asia/v2client/lix/v2ray-linux-64.zip

之后输入 ls 命令,你就可以看到文件夹里面已经有v2ray 和 v2ctl 两个文件了。

出现 -bash: unzip: command not found , 这该怎么办呢?
需要先安装unzip。执行代码:

apt-get install unzip (ubuntu等系统)
yum install unzip (centos等系统)

接下来我们需要替换掉原来的配置文件config.json。先把下面的配置文件复制到文本编辑器里面。

{
  "policy": {
    "levels": {
      "0": {
        "uplinkOnly": 0
      }
    }
  },
  "dns": {
    "servers": [
      "1.1.1.1"
    ]
  },
  "outboundDetour": [
    {
      "tag": "tg-out",
      "protocol": "mtproto",
      "settings": {},
      "proxySettings": {
        "tag": "v2-out"
      }
    }
  ],
  "inbound": {
    "tag": "tg-in",
    "port": 2333,//这个是MTP代理的端口
    "protocol": "mtproto",
    "settings": {
      "users": [
        {
          "secret": "23333333333333333333333333333333"//这个是mtp代理的密码,格式是32位的使用阿拉伯数字和字母abcdef组成的密码
        }
      ]
    }
  },
  "log": {
    "loglevel": "debug"
  },
  "routing": {
    "strategy": "rules",
    "settings": {
      "domainStrategy": "IPIfNonMatch",
      "rules": [
        {
          "type": "field",
          "inboundTag": [
            "tg-in"
          ],
          "outboundTag": "tg-out"
        }
      ]
    }
  },
  "outbound": {
    "tag":"v2-out",
    "sendThrough": "0.0.0.0",
    "mux": {
      "enabled": false,
      "concurrency": 8
    },
    "protocol": "vmess",
    "settings": {
      "vnext": [
        {
          "address": "www.baidu.com",//v2ray服务器的地址
          "port": 23333,//v2ray服务器的端口
          "users": [
            {
              "id": "00000000-0000-0000-0000-000000000000",//你的uuid
              "alterId": 2,
              "security": "auto",
              "level": 2
            }
          ],
          "remark": "NodeName"
        }
      ]
    },
    "streamSettings": {
      "network": "tcp",//这个是传输协议,tcp或者ws
      "security": ""
    }
  }
}

在文本编辑器里面替换掉上面的配置信息(mtp代理的端口密码,你的v2ray账号信息等),然后保存为config.json

接下来使用把config.json上传到刚刚的mtp文件夹里面,替换掉原来的。

现在已经配置好了,可以运行了,请执行

chmod +x v2ray
chmod +x v2ctl
./v2ray

如果没有发现什么报错,配置就是成功的了。为了让他在后台执行,我们可以先按ctrl+c,退出当前程序,执行下面的代码:

nohup ./v2ray >> /dev/null 2>&1 &

这样就可以让他在后台运行了。
在电报客户端里面,新建一个mtp代理:

发现连不上?原来忘记关掉防火墙或者安全组了!关掉之后就可以正常用啦!

关闭防火墙代码:

systemctl disable firewalld
systemctl stop firewalld