本站支持「有偿」远程协助!

多 IP 服务器搭建 socks5 代理

源进源出,多 IP 服务器搭建 socks 代理,支持 UDP .

配置 IP

ip a
network:
  version: 2
  renderer: networkd
  ethernets:
    eth1:
      addresses:
        - 172.20.245.124/24
        - 172.20.245.121/24
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eth1:
      addresses:
        - 172.20.245.124/24
        - 172.20.245.121/24
for ip in $(hostname -I)
do
curl ip.me --interface $ip
done

/etc/rc.local

ifconfig eth0:1 10
ifconfig eth0:2 103
ifconfig eth0:3 101.34
ifconfig eth0:4 1041.35
cd /etc/netplan
netplan generate
netplan try
netplan appley

/etc/network/interface

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 12.1.1.1
netmask 255.255.255.0
gateway 3.51.7.1

auto eth0:1
iface eth0:1 inet static
address 2.2.3.4
netmask 255.255.255.0

auto eth0:2
iface eth0:2 inet static
address 5.6.1.5
netmask 255.255.255.0

脚本

#/bin/sh

socks_port="1080"
socks_user="admin"
socks_pass="admin"

ips=(
134.122.143.2
134.122.143.130
134.122.143.3
)

ips=(
$(hostname -I)
)
# Xray Installation
wget -O /usr/local/bin/xray https://cdn.jsdelivr.net/gh/none-blue/xray-amd64@main/xray
chmod +x /usr/local/bin/xray

cat <<EOF > /etc/systemd/system/xray.service
[Unit]
Description=The Xray Proxy Serve
After=network-online.target

[Service]
ExecStart=/usr/local/bin/xray -c /etc/xray/serve.toml
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=always
RestartSec=15s

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable xray

# Xray Configuration
mkdir -p /etc/xray
echo -n "" > /etc/xray/serve.toml
for ((i = 0; i < ${#ips[@]}; i++)); do
cat <<EOF >> /etc/xray/serve.toml
[[inbounds]]
listen = "${ips[i]}"
port = $socks_port
protocol = "socks"
tag = "$((i+1))"
[inbounds.settings]
auth = "password"
udp = true
ip = "${ips[i]}"
[[inbounds.settings.accounts]]
user = "$socks_user"
pass = "$socks_pass"

[[routing.rules]]
type = "field"
inboundTag = "$((i+1))"
outboundTag = "$((i+1))"

[[outbounds]]
sendThrough = "${ips[i]}"
protocol = "freedom"
tag = "$((i+1))"

EOF
done

systemctl stop xray
systemctl start xray
#systemctl status xray


for ((i = 0; i < ${#ips[@]}; i++)); do
echo socks5://$socks_user:$socks_pass@${ips[i]}:$socks_port
curl ip.me -x socks5://$socks_user:$socks_pass@${ips[i]}:$socks_port
done

for ((i = 0; i < ${#ips[@]}; i++)); do
echo socks://`echo "$socks_user:$socks_pass@${ips[i]}:$socks_port" | base64`#$((i+1))
done

腾讯云专版

#!/bin/bash

socks_port="1080"
socks_user="admin"
socks_pass="admin"

# ther first ip must be primary ip

ips=(
172.19.0.18
172.19.0.20
)

ips=(
$(hostname -I)
)

# install yq
apt update -y
apt install -y network-manager
wget -O /usr/local/bin/yq https://cdn.jsdelivr.net/gh/mainians/yq@main/yq
chmod +x /usr/local/bin/yq

# Xray Installation
wget -O /usr/local/bin/xray https://cdn.jsdelivr.net/gh/none-blue/xray-amd64@main/xray
chmod +x /usr/local/bin/xray



# configure multipe ips
cat <<EOF >   /etc/netplan/other.yaml
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eth0:
      addresses:
EOF

for ((i = 0; i < $((${#ips[@]}-1)); i++)); do
yq e -i '.network.ethernets.eth0.addresses['"$i"'] = "'"${ips[i+1]}"'/24"'  /etc/netplan/other.yaml
done

# netplan apply
netplan apply --state /etc/netplan



cat <<EOF > /etc/systemd/system/xray.service
[Unit]
Description=The Xray Proxy Serve
After=network-online.target

[Service]
ExecStart=/usr/local/bin/xray -c /etc/xray/serve.toml
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=always
RestartSec=15s

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable xray

# Xray Configuration
mkdir -p /etc/xray
echo -n "" > /etc/xray/serve.toml
for ((i = 0; i < ${#ips[@]}; i++)); do
cat <<EOF >> /etc/xray/serve.toml
[[inbounds]]
listen = "${ips[i]}"
port = $socks_port
protocol = "socks"
tag = "$((i+1))"
[inbounds.settings]
auth = "password"
udp = true
ip = "${ips[i]}"
[[inbounds.settings.accounts]]
user = "$socks_user"
pass = "$socks_pass"

[[routing.rules]]
type = "field"
inboundTag = "$((i+1))"
outboundTag = "$((i+1))"

[[outbounds]]
sendThrough = "${ips[i]}"
protocol = "freedom"
tag = "$((i+1))"

EOF
done

systemctl stop xray
systemctl start xray
#systemctl status xray


sleep 5

# test IP

for ((i = 0; i < ${#ips[@]}; i++)); do
echo socks5://$socks_user:$socks_pass@${ips[i]}:$socks_port
curl ip.me -x socks5://$socks_user:$socks_pass@${ips[i]}:$socks_port
done


# output socks url(private)
for ((i = 0; i < ${#ips[@]}; i++)); do
echo socks://`echo "$socks_user:$socks_pass@${ips[i]}:$socks_port" | base64`#$((i+1))
done


# output socks url(public)
for ((i = 0; i < ${#ips[@]}; i++)); do
echo socks://`echo "$socks_user:$socks_pass@$(curl -4sL ip.me -x socks5://$socks_user:$socks_pass@${ips[i]}:$socks_port):$socks_port" | base64`#$((i+1))
done

无密码

#/bin/sh

socks_port="1080"

ips=(
134.122.143.2
134.122.143.130
134.122.143.3
)

ips=(
$(hostname -I)
)
# Xray Installation
wget -O /usr/local/bin/xray https://cdn.jsdelivr.net/gh/none-blue/xray-amd64@main/xray
chmod +x /usr/local/bin/xray

cat <<EOF > /etc/systemd/system/xray.service
[Unit]
Description=The Xray Proxy Serve
After=network-online.target

[Service]
ExecStart=/usr/local/bin/xray -c /etc/xray/serve.toml
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=always
RestartSec=15s

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable xray

# Xray Configuration
mkdir -p /etc/xray
echo -n "" > /etc/xray/serve.toml
for ((i = 0; i < ${#ips[@]}; i++)); do
cat <<EOF >> /etc/xray/serve.toml
[[inbounds]]
listen = "${ips[i]}"
port = $socks_port
protocol = "socks"
tag = "$((i+1))"
[inbounds.settings]
auth = "noauth"
udp = true
ip = "${ips[i]}"

[[routing.rules]]
type = "field"
inboundTag = "$((i+1))"
outboundTag = "$((i+1))"

[[outbounds]]
sendThrough = "${ips[i]}"
protocol = "freedom"
tag = "$((i+1))"

EOF
done

systemctl stop xray
systemctl start xray
#systemctl status xray


for ((i = 0; i < ${#ips[@]}; i++)); do
echo socks5://${ips[i]}:$socks_port
curl ip.me -x socks5://${ips[i]}:$socks_port
done

for ((i = 0; i < ${#ips[@]}; i++)); do
echo socks://`echo "${ips[i]}:$socks_port" | base64`#$((i+1))
done
Loading ...
无广告!