Skip to content

Instantly share code, notes, and snippets.

@soleil0-0
Last active November 5, 2017 03:15
Show Gist options
  • Save soleil0-0/00d600b9b9160d0e492135a8e9263c4c to your computer and use it in GitHub Desktop.
Save soleil0-0/00d600b9b9160d0e492135a8e9263c4c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
tunnel_v2ray_client_docker() {
SERVER_PORT=1080
CONFIG_PATH=/etc/v2ray/config.json
tunnel_v2ray_client_config
CONTAINER_NAME=v2ray
CONTAINER_ID=`docker ps -aq --filter=name=$CONTAINER_NAME`
[ -z "$CONTAINER_ID" ] || docker rm -f $CONTAINER_ID
docker run -d \
--name $CONTAINER_NAME \
-v $CONFIG_PATH:/etc/v2ray/config.json \
-p $SERVER_PORT:1080 \
v2ray/official
}
tunnel_v2ray_client_config() {
CONFIG_PATH=${CONFIG_PATH:-/etc/v2ray/config.json}
sudo mkdir -p ${CONFIG_PATH%/*}
cat <<EOF | sudo tee $CONFIG_PATH >/dev/null
{
"log": {
"loglevel": "warning"
},
"inbound": {
"port": 1080,
"protocol": "socks",
"settings": {
"auth": "noauth"
}
},
"outbound": {
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "$REMOTE_IP",
"port": 80,
"users": [
{
"id": "e751718e-8c01-4315-a967-57969c4e8612",
"alterId": 64
}
]
}
]
},
"streamSettings": {
"network": "tcp",
"tcpSettings": {
"header": {
"type": "http",
"request": {
"version": "1.1",
"method": "GET",
"path": ["/"],
"headers": {
"Host": ["www.cloudflare.com", "www.amazon.com"],
"User-Agent": [
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36",
"Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46"
],
"Accept-Encoding": ["gzip, deflate"],
"Connection": ["keep-alive"],
"Pragma": "no-cache"
}
}
}
}
}
},
"outboundDetour": [
{
"protocol": "freedom",
"settings": {},
"tag": "direct"
}
],
"routing": {
"strategy": "rules",
"settings": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"type": "field",
"ip": [
"0.0.0.0/8",
"10.0.0.0/8",
"100.64.0.0/10",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.0.0.0/24",
"192.0.2.0/24",
"192.168.0.0/16",
"198.18.0.0/15",
"198.51.100.0/24",
"203.0.113.0/24",
"::1/128",
"fc00::/7",
"fe80::/10"
],
"outboundTag": "direct"
},
{
"type": "chinasites",
"outboundTag": "direct"
},
{
"type": "chinaip",
"outboundTag": "direct"
}
]
}
}
}
EOF
}
tunnel_v2ray_client_docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment