Skip to content

Instantly share code, notes, and snippets.

@iamvee
Forked from mahmoud-eskandari/README.md
Created October 21, 2022 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamvee/55d2a6f314af184b5a472c8593eedfca to your computer and use it in GitHub Desktop.
Save iamvee/55d2a6f314af184b5a472c8593eedfca to your computer and use it in GitHub Desktop.
Install v2ray on Bridge:(Ubuntu +18 via systemd) - Upstream (Ubuntu +18/CentOS +7 via docker)

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

mkdir vmess
cd vmess

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

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

[ یا ]

اگر اتفاقی نیفتاد ممکن است دسترسی سرور شما با اینترنت قطع شده باشد پس میتوانید از دستور زیر به جای آن استفاده کنید که یک کپی در سرورهای ایران است. توجه کنید اگر هر کدام اجرا شد و موفقیت آمیز بود دیگر نیازی به اجرای آن یکی ندارید. کپی هم هستند صرفا!

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

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

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

اگر این اجرا موفقیت آمیز بود یک پیغام به شما نشان میدهد و کانکشنهای مختلف برای اتصال به تلگرام vmess و ... را چاپ میکند.

👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇

روش تست بخشهای مختلف برای عیب یابی کردن

1. چک کردن سرویس V2ray در سرور ایران systemctl status v2ray‍‍

رو اجرا کنید اگر مشکل داشت ممکنه مشکل دسترسی باشه

chown -R nobody /usr/local/share/v2ray/
chown -R nobody /var/log/v2ray
systemctl restart v2ray

رو اجرا کنید اگر مشکل داشت

/usr/local/bin/v2ray -config /usr/local/etc/v2ray/config.json

با اجرای کامند بالا سرویس رو اجرا کنید به صورت دستی اگر تو خروجی مشکلی باشه همونجا پرینت میشه

2. بررسی باز بودن پورت ها به منظور چک کردن بالا بودن سرویس

برای اینکه بفهمیم سرور خارج به ایران مشکل اتصال نداره میتونید با دستور

telnet FOREIGN_IP PORT

مثل

telnet 1.2.3.4.5 2083

تست کنید از سرور ایران ببینید وصل میشه اگر وصل نشد یعنی روی سرور خارجتون چیزی لیسن نمیکنه که بهش وصل شد

اگر روی پورتهای داخل خود سرور ایران هم این رو تست کنید مشخص میشه سرویس داره لیسن میکنه یا نه IP داخلی هر سروری میشه 127.0.0.1 مثلا پورت 9009 برای vmess هست اگر در سرور ایران

telnet 127.0.0.1 9009

بزنید و وصل نشه یعنی سرور ایرانتون اصلا لیسن نمیکنه یه بار

systemctl restart v2ray

بزنید شاید کار کرد.

حالا برای اینکه ببینید این پورت روی سرور ایرانتون به داخل بازه و مسدودش نکردن در برنامه Putty میتونید با زدن گزینه telnet این کار رو بکنید یعنی IP_IRAN – 9009 رو مثلا وارد کنید ببینید وصل میشه اگر لینوکس یا مک دارید در ترمینالش بزنید

telnet IP_IRAN 9009

ببینید وصل میشه

اگر داخل سرور شد ولی از بیرون نشد یعنی این پورت رو مسدود کردن.

در صورتیکه مشکل اتصال و محدودیت وجود داشت باید Obfoscation رو اعمال کنید این روش باعث کندتر شدن اتصال میشه مخصوصا توی استریمینگ ولی اغلب سامانه‌های ضدفیلتر رو دور میزنه با اضافه کردن یک هدر

سمپلش در اینجا هست

V2Ray Obfs قسمت "streamSettings" رو باید تغییر بدید

همچنین در کلاینتها هم باید header: http اضافه کنید

#!/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/
rm -rf /usr/local/share/v2ray/ && mkdir -p /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": "freedom",
"ip": [
"geoip:ir"
],
"domain": [
"regexp:^*\\\\.ir$",
"iran: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
chown -R nobody /usr/local/share/v2ray/
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)
VMESS=$(sed "s/\=//g" <<<"$VMESS")
VMESS=$(sed ':a; N; s/[[:space:]]//g; ta' <<<"$VMESS")
SHADOW=$(echo "chacha20-ietf-poly1305:$SSPASS" | base64)
SHADOW=$(sed "s/\=//g" <<<"$SHADOW")
SHADOW=$(sed ':a; N; s/[[:space:]]//g; ta' <<<"$SHADOW")
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
Encryption:"chacha20-ietf-poly1305"
===============================
V2ray vmess Connection:
vmess://$VMESS
ID/UUID: $UUID
Port: 9009
alterId: 0
===============================
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
- 8080:8080
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"
},
"inbounds": [
{
"listen": "0.0.0.0",
"port": 8080,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$UUID",
"alterId": 64,
"security": "chacha20-poly1305"
}
]
},
"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"
}
}
}
}
}
},{
"listen": "0.0.0.0",
"port": $1,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "$UUID",
"alterId": 0,
"security": "chacha20-poly1305"
}
]
},
"streamSettings": {
"network": "ws"
}
}],
"outbound": {
"protocol": "freedom",
"tag": "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/" )
VMESS=$(echo "{\"add\":\"$IP\",\"aid\":\"64\",\"host\":\"\",\"id\":\"$UUID\",\"net\":\"tcp\",\"path\":\"\",\"port\":\"8080\",\"ps\":\"Foreign-$IP\",\"scy\":\"auto\",\"sni\":\"\",\"tls\":\"\",\"type\":\"http\",\"v\":\"2\"}" | base64)
VMESS=$(sed "s/\=//g" <<<"$VMESS")
VMESS=$(sed ':a; N; s/[[:space:]]//g; ta' <<<"$VMESS")
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/d3278ec065227173edb16a63d7fe03fdebc1bc7d/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
####### External Vmess connection ######
Server: $IP
Port: 8080
ID: $UUID
alterId: 64
security: chacha20-poly1305
head type: http
domain: [An internal website domain like: digikala.com]
vmess://$VMESS
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