1 服务器安装
#!/bin/bash
# sudo bash install.sh 127.0.0.1 127.0.0.1
# https://github.com/v2fly/v2ray-core
# https://github.com/gfwlist/gfwlist
# https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt
set -eux
V2RAY_VERSION=5.14.1
export V2RAY_SERVER_IP=${1:-127.0.0.1}
export V2RAY_CLIENT_IP=${2:-127.0.0.1}
apt update -y
apt install -y wget gettext lsof net-tools
bash <(wget -q -O - https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --version $V2RAY_VERSION
/usr/local/bin/v2ray version
UUID=$(/usr/local/bin/v2ray uuid)
CRET_NAME=${UUID:0:8}
CRET_ORG=${UUID:9:4}
export TEMPLATE_SERVER_DOMAIN_NAME="${UUID:14:4}.test"
export TEMPLATE_CLIENT_ID=$UUID
export TEMPLATE_CERTIFICATE_JSON=$(/usr/local/bin/v2ray tls cert --ca --json --domain=$TEMPLATE_SERVER_DOMAIN_NAME --expire=720 --name=$CRET_NAME --org=$CRET_ORG)
SERVER_JSON_TEMPLATE=$(cat <<'SERVER_JSON'
{
"log": {
"logLevel": "None"
},
"inbounds": [
{
"listen": "${V2RAY_SERVER_IP}",
"port": 443,
"protocol": "vless",
"settings": {
"decryption": "none",
"clients": [
{
"id": "${TEMPLATE_CLIENT_ID}"
}
]
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"serverName": "${TEMPLATE_SERVER_DOMAIN_NAME}",
"allowInsecure": false,
"allowInsecureCiphers": false,
"disableSystemRoot": true,
"certificates": [
${TEMPLATE_CERTIFICATE_JSON}
]
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
]
}
SERVER_JSON
)
echo "${SERVER_JSON_TEMPLATE}" | envsubst > /usr/local/etc/v2ray/config.json
/usr/local/bin/v2ray test -c /usr/local/etc/v2ray/config.json
CLIENT_JSON_TEMPLATE=$(cat <<'CLIENT_JSON'
{
"log": {
"logLevel": "None"
},
"inbounds": [
{
"listen": "$V2RAY_CLIENT_IP",
"port": 1080,
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": true
}
}
],
"outbounds": [
{
"protocol": "vless",
"settings": {
"vnext": [
{
"address": "${V2RAY_SERVER_IP}",
"port": 443,
"users": [
{
"id": "${TEMPLATE_CLIENT_ID}",
"encryption": "none"
}
]
}
]
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"serverName": "${TEMPLATE_SERVER_DOMAIN_NAME}",
"allowInsecure": false,
"allowInsecureCiphers": false,
"disableSystemRoot": true,
"certificates": [
${TEMPLATE_CERTIFICATE_JSON}
]
}
},
"mux": {
"enabled": false
}
},
{
"protocol": "freedom",
"settings": {},
"mux": {
"enabled": false
}
}
]
}
CLIENT_JSON
)
echo "${CLIENT_JSON_TEMPLATE}" | envsubst > v2ray-client-config.json
setcap cap_net_bind_service=+ep /usr/local/bin/v2ray
systemctl daemon-reload
systemctl enable v2ray
systemctl restart v2ray
systemctl status v2ray
lsof -i:443
netstat -an | grep 4432 客户端安装
2.1 Windows
下载客户端https://github.com/v2fly/v2ray-core/releases/download/v5.14.1/v2ray-windows-64.zip。
然后用服务器安装中生成的client-config.json替换zip解压后的config.json即可。
2.2 macOS
下载客户端https://github.com/v2fly/v2ray-core/releases/download/v5.14.1/v2ray-macos-64.zip。
然后用服务器安装中生成的client-config.json替换zip解压后的config.json即可。
2.3 Andorid
下载APKhttps://github.com/2dust/v2rayNG/releases。
然后用服务器安装中生成的client-config.v2rayng.json复制到剪切板或者生成二维码。用v2rayNG这个APP从剪切板导入或者扫描二维码都可以。
3 浏览器扩展
SwitchyOmega : https://chrome.google.com/webstore/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif
4 参考
4.1 服务器配置模板
{
"log": {
"logLevel": "None"
},
"inbounds": [
{
"listen": "$V2RAY_SERVER_IP",
"port": 443,
"protocol": "vless",
"settings": {
"decryption": "none",
"clients": [
{
"id": "$TEMPLATE_CLIENT_ID"
}
]
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"serverName": "$TEMPLATE_SERVER_DOMAIN_NAME",
"allowInsecure": false,
"allowInsecureCiphers": false,
"disableSystemRoot": true,
"certificates": [
$TEMPLATE_CERTIFICATE_JSON
]
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
]
}4.2 客户端配置模板(v2ray-core)
{
"log": {
"logLevel": "None"
},
"inbounds": [
{
"listen": "$V2RAY_CLIENT_IP",
"port": 1080,
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": true
}
}
],
"outbounds": [
{
"protocol": "vless",
"settings": {
"vnext": [
{
"address": "$V2RAY_SERVER_IP",
"port": 443,
"users": [
{
"id": "$TEMPLATE_CLIENT_ID",
"encryption": "none"
}
]
}
]
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"serverName": "$TEMPLATE_SERVER_DOMAIN_NAME",
"allowInsecure": false,
"allowInsecureCiphers": false,
"disableSystemRoot": true,
"certificates": [
$TEMPLATE_CERTIFICATE_JSON
]
}
},
"mux": {
"enabled": false
}
},
{
"protocol": "freedom",
"settings": {},
"mux": {
"enabled": false
}
}
]
}4.4 OpenWrt
#!/bin/sh /etc/rc.common
# openwrt
# /etc/init.d/v2ray
# chmod +x /etc/init.d/v2ray
# /etc/init.d/v2ray enable
# /etc/init.d/v2ray start
# /etc/init.d/v2ray stop
# /etc/init.d/v2ray reload
START=99
SERVICE_WRITE_PID=1
SERVICE_DAEMONIZE=1
start() {
service_start /usr/bin/v2ray --config=/etc/config/v2ray.json
}
stop() {
service_stop /usr/bin/v2ray
}
reload() {
service_reload /usr/bin/v2ray
}