Skip to content

Instantly share code, notes, and snippets.

@soleil0-0
Last active November 1, 2017 13:43
Show Gist options
  • Save soleil0-0/da9180a3fc85c161f137d5814ecd446a to your computer and use it in GitHub Desktop.
Save soleil0-0/da9180a3fc85c161f137d5814ecd446a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
tunnel_v2ray_server_docker() {
CONFIG_PATH=/etc/v2ray/config.json
tunnel_v2ray_server_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 80:80 \
v2ray/official
HOST_IP=$(ip -4 addr show eth0 2>/dev/null | awk ' /inet/ {print $2}' | cut -d/ -f1)
echo "The client should connect to ${HOST_IP}"
}
tunnel_v2ray_server_config() {
# https://www.v2ray.com/chapter_05/01_exp.html
# https://toutyrater.github.io/advanced/httpfake.html
CONFIG_PATH=${CONFIG_PATH:-/etc/v2ray/config.json}
sudo mkdir -p ${CONFIG_PATH%/*}
cat <<EOF | sudo tee $CONFIG_PATH >/dev/null
{
"log" : {
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log",
"loglevel": "warning"
},
"inbound": {
"port": 80,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "e751718e-8c01-4315-a967-57969c4e8612",
"level": 1,
"alterId": 64
}
]
},
"streamSettings": {
"network": "tcp",
"tcpSettings": {
"header": {
"type": "http",
"response": {
"version": "1.1",
"status": "200",
"reason": "OK",
"headers": {
"Content-Type": ["application/octet-stream", "application/x-msdownload", "text/html", "application/x-shockwave-flash"],
"Transfer-Encoding": ["chunked"],
"Connection": ["keep-alive"],
"Pragma": "no-cache"
}
}
}
}
}
},
"outbound": {
"protocol": "freedom",
"settings": {}
},
"outboundDetour": [
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
],
"routing": {
"strategy": "rules",
"settings": {
"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": "blocked"
}
]
}
}
}
EOF
}
tunnel_v2ray_server_docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment