Sing-Box can serve as both a client and a server at the same time so it must be installed on both the VPS server and the VPN gateway.
Sing-Box Installation Steps:
Installing gcc is the first step:
sudo su
apt update && apt install -y build-essential
Code language: Bash (bash)
Let’s install the latest version of go (golang):
curl -fsL https://raw.githubusercontent.com/jetsung/golang-install/main/install.sh | bash
source /root/.bashrc
Code language: Bash (bash)
Run the following command to install the dev-next branch of sing-box:
go install -v -tags "with_clash_api with_quic with_grpc with_wireguard with_shadowsocksr with_ech with_utls with_acme with_v2ray_api with_gvisor with_lwip" github.com/sagernet/sing-box/cmd/sing-box@dev-next
Code language: Bash (bash)
Allow all users to run sing-box:
cp ~/go/bin/sing-box /usr/local/bin/
Code language: Bash (bash)
Next, create a sing-box directory to store assets and configurations:
mkdir /etc/sing-box/ && cd $_
Code language: Bash (bash)
Creating sing-box systemd service:
cat <<EOF > /etc/systemd/system/sing-box.service
[Unit]
Description=sing-box Service
Documentation=https://sing-box.sagernet.org/
After=network.target nss-lookup.target
Wants=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/sing-box run -c /etc/sing-box/config.json
Restart=always
RestartSec=3s
RestartPreventExitStatus=23
LimitNPROC=10000
LimitNOFILE=1000000
[Install]
WantedBy=multi-user.target
EOF
Code language: Bash (bash)
Docker Installation:
Here is the Sing-Box Dockerfile if you prefer using it with docker.
Sing-Box Config
You have the option to either use our pre-made config.json or create your own. Once you have customized the config.json to your liking, you can enable its service.