侧边栏壁纸
博主头像
MicroMatrix 博主等级

明月别枝惊鹊,清风半夜鸣蝉

  • 累计撰写 135 篇文章
  • 累计创建 41 个标签
  • 累计收到 2 条评论

目 录CONTENT

文章目录

Linux服务器使用代理

David
2022-08-19 / 0 评论 / 0 点赞 / 23 阅读 / 0 字
  1. 首先你需要一个能使用的代理节点,我这里是 xray 的 vless 节点,所以我安装 xray-core 的内核。

这里提供xray 的 x86 服务器下载地址

第一步获取你节点信息,我这里是用了第三方客户端的 JSON 信息,直接复制出来的

写入到 config.json文件中,下面的 xray 启动需要这个配置文件

{
  "log": {
    "access": "/dev/stdout",
    "error": "/dev/stderr",
    "loglevel": "debug"
  },
  "dns": {
    "servers": [
      "1.1.1.1",
      "8.8.8.8",
      "localhost"
    ]
  },
  "inbounds": [
    {
      "tag": "socks-in",
      "listen": "0.0.0.0",
      "port": 1089,
      "protocol": "socks",
      "settings": {
        "auth": "noauth",
        "udp": true
      },
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      }
    },
    {
      "tag": "http-in",
      "listen": "0.0.0.0",
      "port": 8123,
      "protocol": "http",
      "settings": {
        "timeout": 300
      },
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      }
    }
  ],
  "outbounds": [
    {
      "tag": "proxy",
      "protocol": "vless",
      "settings": {
        "vnext": [
          {
            "address": "xxxx.org",
            "port": 22222,
            "users": [
              {
                "id": "xxxxxx",
                "encryption": "none",
                "flow": ""
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "tcp",
        "security": "reality",
        "tcpSettings": {
          "header": {
            "type": "none"
          }
        },
        "realitySettings": {
          "show": false,
          "fingerprint": "chrome",
          "serverName": "xxxx.xxxx.com",
          "publicKey": "xxxxx",
          "shortId": "xxxxx",
          "spiderX": "xxxxxx"
        }
      },
      "mux": {
        "enabled": false
      }
    },
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {
        "domainStrategy": "UseIP"
      }
    },
    {
      "tag": "block",
      "protocol": "blackhole",
      "settings": {
        "response": {
          "type": "http"
        }
      }
    }
  ],
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "rules": [
      {
        "type": "field",
        "inboundTag": [
          "socks-in",
          "http-in"
        ],
        "outboundTag": "proxy"
      },
      {
        "type": "field",
        "ip": [
          "geoip:private"
        ],
        "outboundTag": "direct"
      }
    ]
  },
  "stats": {}
}
  1. 下载最新的 xray-core 内核
mkdir /root/xray

cd /root/xray

## 下载最新的xray内核

wget https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-64.zip

## 解压文件

unzip Xray-linux-64.zip

## 运行,自己可以用systemd或者screen等等后台运行

/root/xray/xray run -c /root/xray/config.json  // 这里的配置文件就是上面的配置文件

如果不提示什么错误,至少表明软件的运行没什么问题

systemd 后台运行

#编辑配置文件,输入i,进行编辑,按esc退出编辑,:wq保存退出

vim /etc/systemd/system/xray.service
#添加下面内容

[Unit]

Description=xray Service

After=network.target nss-lookup.target

[Service]

User=root

CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE

AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE

NoNewPrivileges=true

ExecStart=/root/xrayu/xray run -c /root/xray/config.json

Restart=on-failure

RestartPreventExitStatus=23

[Install]

WantedBy=multi-user.target

#以上
#开机自启

systemctl enable xray

#启动

systemctl start xray

#停止

systemctl stop xray

#查看运行状态

systemctl status xray

终端设置代理:

#添加环境变量

vim ~/.bashrc
#或者.zshrc或者/etc/profile
#添加,http和socks5这两个选一个,添加或者删掉#注释即可。

export http_proxy="http://127.0.0.1:8080"

export https_proxy="https://127.0.0.1:8080"

#export http_proxy="socks5://127.0.0.1:1080"

#export https_proxy="socks5://127.0.0.1:1080"
#生效

source ~/.bashrc

#或者

source .zshrc

source /etc/profile

#测试

#不管是http还是socks5都是ping不了的。

curl google.com
0

评论区