Windows设置

image.png

image.png
cmd命令行下走代理:临时生效,关闭cmd就失效:
# Windows CMD 临时设置(当前窗口有效)
set HTTP_PROXY=http://127.0.0.1:10809
set HTTPS_PROXY=http://127.0.0.1:10809
set ALL_PROXY=socks5://127.0.0.1:10808
# Windows PowerShell 临时设置(当前窗口有效)
$env:HTTP_PROXY = "http://127.0.0.1:10809"
$env:HTTPS_PROXY = "http://127.0.0.1:10809"
$env:ALL_PROXY = "socks5://127.0.0.1:10808"
Linux设置
mkdir -p /usr/local/v2ray/bin
# v2ray是适用于Linux的代理文件
cp v2ray /usr/local/v2ray/bin/
# config.json是windows上的v2ray下的配置
cp config.json /usr/local/v2ray/
设置成systemd:
cat >> /usr/lib/systemd/system/v2ray.service << EOF
[Unit]
Description=V2Ray Service
Documentation=https://www.v2fly.org/
After=network.target nss-lookup.target
[Service]
User=nobody
Environment="V2RAY_VMESS_AEAD_FORCED=false"
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/usr/local/v2ray/bin/v2ray run -config /usr/local/v2ray/config.json
Restart=on-failure
RestartPreventExitStatus=23
[Install]
WantedBy=multi-user.target
EOF
cat >> /usr/lib/systemd/system/v2ray@.service << EOF
[Unit]
Description=V2Ray Service
Documentation=https://www.v2fly.org/
After=network.target nss-lookup.target
[Service]
User=nobody
Environment="V2RAY_VMESS_AEAD_FORCED=false"
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/usr/local/v2ray/bin/v2ray run -config /usr/local/v2ray/%i.json
Restart=on-failure
RestartPreventExitStatus=23
[Install]
WantedBy=multi-user.target
EOF
日常启停:
systemctl start v2ray.service
systemctl stop v2ray.service
动态设置代理:
# 编辑 ~/.bashrc,添加以下函数
vim ~/.bashrc
# 粘贴内容(自定义快捷命令)
# 开启代理
proxy_on() {
export http_proxy="socks5://127.0.0.1:10808"
export https_proxy="socks5://127.0.0.1:10808"
export all_proxy="socks5://127.0.0.1:10808"
export no_proxy="localhost,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,::1"
echo "✅ 代理已开启"
echo "当前代理地址:$http_proxy"
}
# 关闭代理
proxy_off() {
unset http_proxy https_proxy all_proxy no_proxy
echo "❌ 代理已关闭"
}
# 查看代理状态
proxy_status() {
if [ -n "$http_proxy" ]; then
echo "🔍 代理已开启,地址:$http_proxy"
else
echo "🔍 代理未开启"
fi
}
# 保存退出后生效
source ~/.bashrc
开启:
proxy_on # 开启代理
proxy_off # 关闭代理
proxy_status # 查看代理状态
echo $http_proxy # 测试代理是否配置
日常开启代理:
systemctl start v2ray.service
proxy_on