Skip to content

Instantly share code, notes, and snippets.

@vruzin
Forked from igentuman/install_3proxy.sh
Created August 5, 2024 17:47
Show Gist options
  • Save vruzin/e5f39a5b5d2f28eca1afd1851fb9697d to your computer and use it in GitHub Desktop.
Save vruzin/e5f39a5b5d2f28eca1afd1851fb9697d to your computer and use it in GitHub Desktop.
UBUNTU install 3proxy server
#!/bin/bash
echo -n "Enter Proxy Username: "
read PROXYUSER
echo -n "Enter Proxy Password: "
read PROXYPASS
echo -n "Enter Proxy Port (Default 9128): "
read PROXYPORT
DEFAULTNS=$(cat /etc/resolv.conf | gawk 'match($0, /nameserver\s([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, a) {print a[1]}')
echo -n "Enter nameserver from /etc/resolv.conf (Autodected $DEFAULTNS): "
read DNS
[ -z "$PROXYUSER" ] && { echo "Proxy User is Required"; exit 1; }
[ -z "$PROXYPASS" ] && { echo "Proxy Password is Required"; exit 1; }
[ -z "$PROXYPORT" ] && { PROXYPORT=9128; }
[ -z "$DNS" ] && { DNS=$DEFAULTNS; }
sudo apt-get update
sudo apt-get install gawk
sudo apt-get install -y build-essential
wget https://github.com/z3APA3A/3proxy/archive/0.9.3.tar.gz
tar xzf 0.9.3.tar.gz
cd ~/3proxy-0.9.3
sudo make -f Makefile.Linux
sudo mkdir /etc/3proxy
cd ~/3proxy-0.9.3/bin
sudo cp 3proxy /usr/bin/
sudo adduser --system --no-create-home --disabled-login --group proxy3
PUID=$(id proxy3 | gawk 'match($0, /uid=([0-9]+)/, a) {print a[1]}')
PGID=$(id proxy3 | gawk 'match($0, /gid=([0-9]+)/, a) {print a[1]}')
sudo cat >/etc/3proxy/3proxy.cfg << EOF
setgid $PUID
setuid $PGID
nserver $DNS
nserver 77.88.8.8
nscache 65536
timeouts 1 5 30 60 180 1800 15 60
users $/etc/3proxy/.proxyauth
daemon
log /var/log/3proxy/3proxy.log D
logformat "- +_L%t.%. %N.%p %E %U %C:%c %R:%r %O %I %h %T"
auth cache strong
allow $PROXYUSER
proxy -n -p$PROXYPORT -a
EOF
sudo cat >/etc/3proxy/.proxyauth << EOF
##see for documentation: http://www.3proxy.ru/howtoe.asp#USERS
$PROXYUSER:CL:$PROXYPASS
EOF
sudo chown proxy3:proxy3 -R /etc/3proxy
sudo chown proxy3:proxy3 /usr/bin/3proxy
sudo chmod 444 /etc/3proxy/3proxy.cfg
sudo chmod 400 /etc/3proxy/.proxyauth
sudo mkdir /var/log/3proxy
sudo chown proxy3:proxy3 /var/log/3proxy
sudo cat >/etc/systemd/system/3proxy.service << EOF
[Unit]
Description=3proxy Proxy Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/3proxy /etc/3proxy/3proxy.cfg
ExecStop=/bin/kill `/usr/bin/pgrep -u proxy3`
RemainAfterExit=yes
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable 3proxy
sudo systemctl start 3proxy
rm ~/0.9.3.tar.gz
sudo rm -r ~/3proxy-0.9.3
echo "Installation Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment