Skip to content

Instantly share code, notes, and snippets.

@eamirgh
Forked from mahmoud-eskandari/README.md
Created October 20, 2022 06:33
Show Gist options
  • Save eamirgh/3da9322226c877826c8a7c3707d261b5 to your computer and use it in GitHub Desktop.
Save eamirgh/3da9322226c877826c8a7c3707d261b5 to your computer and use it in GitHub Desktop.
Install v2ray on Bridge:(Ubuntu +18 via systemd) - Upstream (Ubuntu +18/CentOS +7 via docker)

At the beginning run this command on your internet server (foreign):

برای شروع میتوانید یک دایرکتوری در سرور خارجی ایجاد کنید و وارد آن شوید.

It's better to make a new directory and cd into:

mkdir vmess
cd vmess

سپس دستور زیر را در ترمینال سرور خارجی خود کپی کنید

1️⃣ sudo curl -s https://gist.githubusercontent.com/mahmoud-eskandari/960899f3494a1bffa1a29631dbaf0aee/raw/3609b30f4dd47f17751a3b88d490765795056632/install-upstream.sh | bash -s 2083

[ OR ]

If your internal server hasn't good internet connectivity you can use Iranian mirror: اگر اتفاقی نیفتاد ممکن است دسترسی سرور شما با اینترنت قطع شده باشد پس میتوانید از دستور زیر به جای آن استفاده کنید که یک کپی در سرورهای ایران است. توجه کنید اگر هر کدام اجرا شد و موفقیت آمیز بود دیگر نیازی به اجرای آن یکی ندارید. کپی هم هستند صرفا!

sudo curl -s https://v2rayv2ray.s3.ir-thr-at1.arvanstorage.com/install-upstream.sh | bash -s 2083

After successful installation it returns a message like this: Run this command on your bridge(interanet) server:

بعد از اینکه مرحله ۱ را انجام دادید در انتها شبیه اسکریپت زیر یک کد به شما میدهد که میبایست آنرا کپی کنید و در سرور ایران خود اجرا کنید.

2️⃣ curl -s https://gist.github....install-bridge.sh | bash -s x.x.x.x 2083 xxxxxxxx-xxx-xxx-xxxx-xxxxxxxxxxx

اگر این اجرا موفقیت آمیز بود یک پیغام به شما نشان میدهد و کانکشنهای مختلف برای اتصال به تلگرام vmess و ... را چاپ میکند. Finally run this command on your bridge(internal) server!

#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root user or run with sudo"
exit
fi
cd /tmp/
rm -rf ./v2ray && mkdir ./v2ray
cd ./v2ray
## x86_64
## Source: https://github.com/v2fly/v2ray-core/releases/tag/v4.31.0
curl -L https://v2rayv2ray.s3.ir-thr-at1.arvanstorage.com/v2ray-$(uname -m).tar.gz -o v2ray.tar.gz
tar -xvf v2ray.tar.gz
## make directories
rm -rf /var/log/v2ray/ && mkdir -p /var/log/v2ray/
chown -R nobody /var/log/v2ray
rm -rf /usr/local/share/v2ray/ && mkdir -p /usr/local/share/v2ray/
chown -R nobody /usr/local/share/v2ray/
rm -rf /usr/local/etc/v2ray/ && mkdir -p /usr/local/etc/v2ray/
## Get an UUID
UUID=$(cat /proc/sys/kernel/random/uuid)
if [ $? -ne 0 ]
then
UUID= $(curl -s "https://www.uuidgenerator.net/api/version4" )
fi
SSPASS=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13 )
SOPASS=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 8 )
MTPORTO=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 32 | md5sum | head -c 32)
## Write config file
cat <<EOF > /usr/local/etc/v2ray/config.json
{
"log": {
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log",
"loglevel": "warning"
},
"inbounds": [
{
"listen": "0.0.0.0",
"port": 9007,
"protocol": "socks",
"settings": {
"auth": "password",
"accounts": [
{
"user": "user",
"pass": "$SOPASS"
}
],
"udp": true
}
},
{
"port": 9006,
"protocol": "mtproto",
"settings": {
"users": [{"secret": "$MTPORTO"}]
}
},
{
"listen": "0.0.0.0",
"port": 9008,
"protocol": "shadowsocks",
"settings": {
"password": "$SSPASS",
"timeout":60,
"method":"chacha20-ietf-poly1305"
}
},
{
"listen": "0.0.0.0",
"port": 9009,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$UUID",
"alterId": 0,
"security": "auto"
}
]
}
}
],
"outbound": {
"tag": "proxy",
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "$1",
"port": $2,
"users": [
{
"id": "$3",
"alterId": 0,
"security": "chacha20-poly1305"
}
]
}
]
},
"streamSettings": {
"network": "ws"
},
"mux": {
"enabled": true
}
},
"inboundDetour": null,
"outboundDetour": [
{
"protocol": "freedom",
"tag": "freedom"
},
{
"protocol": "blackhole",
"tag": "blackhole"
}
],
"dns": {
"servers": [
"8.8.8.8",
"8.8.4.4",
"localhost"
]
},
"routing": {
"domainStrategy": "IPIfNonMatch",
"settings": {
"rules": [
{
"type": "field",
"outboundTag": "blackhole",
"ip": [
"geoip:private"
]
},
{
"type": "field",
"outboundTag": "direct",
"ip": [
"geoip:ir"
],
"domain": [
"regexp:^.+\\\\.ir$",
"ext:iran.dat:ir"
]
}
]
}
}
}}
EOF
cp ./systemd/system/v2ray.service /etc/systemd/system/
cp ./systemd/system/v2ray@.service /etc/systemd/system/
## create log files
touch /var/log/v2ray/access.log
touch /var/log/v2ray/error.log
## copy binaries
cp ./v2ray /usr/local/bin/v2ray
cp ./v2ctl /usr/local/bin/v2ctl
chmod +x /usr/local/bin/v2ray
chmod +x /usr/local/bin/v2ctl
## copy dat files
cp ./iran.dat /usr/local/share/v2ray/iran.dat
cp ./geosite.dat /usr/local/share/v2ray/geosite.dat
cp ./geoip.dat /usr/local/share/v2ray/geoip.dat
systemctl daemon-reload
systemctl enable v2ray
systemctl restart v2ray
cd /tmp/
rm -rf ./v2ray
IP=$(curl -s "https://api.ipify.org/" )
## Fallback interanet
if [ "$IP" = ""]
then
IP=$(curl -s "https://dzy.ir/ip.txt" )
fi
VMESS=$(echo "{\"add\":\"$IP\",\"aid\":\"0\",\"host\":\"\",\"id\":\"$UUID\",\"net\":\"tcp\",\"path\":\"\",\"port\":\"9009\",\"ps\":\"Iran-$IP\",\"scy\":\"auto\",\"sni\":\"\",\"tls\":\"\",\"type\":\"none\",\"v\":\"2\"}" | base64)
SHADOW=$(echo "chacha20-ietf-poly1305:$SSPASS" | base64)
cat <<EOF > ./v2ray-install.log
Output saved into >>>
/tmp/v2ray-install.log
Your Internal IP is: $IP , by api.ipify.org
If your ip is not correct (because of proxy affect etc.) change it manualy in connection configs.
===============================
ShadowSoocks Connection:
ss://$SHADOW@$IP:9008#Iran-$IP
Password:$SSPASS
Port:9008
===============================
V2ray vmess Connection:
vmess://$VMESS
Password:$UUID
Port:9009
===============================
Telegram Socks:
https://t.me/socks?server=$IP&port=9007&user=user&pass=$SOPASS
Telegram MtProto:
https://t.me/proxy?server=$IP&port=9006&secret=$MTPORTO
===============================
Socks5:
IP: $IP
Port: 9007
Username: user
Password: $SOPASS
===============================
EOF
cat ./v2ray-install.log
echo "For check v2ray helth run: systemctl status v2ray"
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root user or run with sudo"
exit
fi
## Check for docker
docker --version
if [ $? -ne 0 ]
then
curl -fsSL https://get.docker.com | sh
fi
## Check for docker compose
docker-compose --version
if [ $? -ne 0 ]
then
curl -L "https://github.com/docker/compose/releases/download/$(curl --silent "https://api.github.com/repos/docker/compose/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")')/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
fi
rm -f docker-compose.yml
rm -f config.json
rm -rf log
mkdir log
## Get an UUID
UUID=$(cat /proc/sys/kernel/random/uuid)
if [ $? -ne 0 ]
then
UUID= $(curl -s "https://www.uuidgenerator.net/api/version4" )
fi
## Write compose file
cat <<EOF > ./docker-compose.yml
version: "3"
services:
v2ray:
image: v2fly/v2fly-core:latest
container_name: v2ray
restart: always
ports:
- $1:$1
volumes:
- ./config.json:/etc/v2ray/config.json
- ./log/:/var/log/v2ray/
EOF
## Write config file
cat <<EOF > ./config.json
{
"log": {
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log",
"loglevel": "warning"
},
"inbound": {
"listen": "0.0.0.0",
"port": $1,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$UUID",
"alterId": 0,
"security": "chacha20-poly1305"
}
]
},
"streamSettings": {
"network": "ws"
}
},
"outbound": {
"protocol": "freedom"
},
"inboundDetour": null,
"outboundDetour": [
{
"protocol": "blackhole",
"tag": "blackhole"
}
],
"routing": {
"domainStrategy": "IPIfNonMatch",
"settings": {
"rules": [
{
"type": "field",
"outboundTag": "blackhole",
"ip": [
"geoip:private"
]
}
]
}
}
}
EOF
docker-compose up -d
IP=$(curl -s "https://api.ipify.org/" )
cat <<EOF > ./bridge-install-by-curl.sh
## Run this command on your bridge(interanet) server:
sudo curl -s https://gist.githubusercontent.com/mahmoud-eskandari/960899f3494a1bffa1a29631dbaf0aee/raw/5384ebaa2b7c71179aff6a8dd49c59fe9e54a383/install-bridge.sh | bash -s $IP $1 $UUID
## If your internal server hasn't access to foreign internet you can also use internal mirror:
sudo curl -s https://v2rayv2ray.s3.ir-thr-at1.arvanstorage.com/run.sh | bash -s $IP $1 $UUID
EOF
cat ./bridge-install-by-curl.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment