Simplify Your Dante SOCKS5 Proxy Setup with This Bash Script
Setting up a Dante SOCKS5 proxy on a Debian-based system can be complex, especially for those unfamiliar with network configurations. This Bash script automates the installation and configuration process, making it easier than ever to deploy a secure SOCKS5 proxy server.
What is Dante?
Dante is a versatile SOCKS5 proxy server that allows clients to securely route their network traffic through a proxy. It’s widely used for enhancing privacy, bypassing network restrictions, and managing traffic in various environments.
Overview of the Dante Server Setup Script
This Bash script automates the installation and configuration of the Dante server on Debian-based systems. Here’s a brief overview of its main functionalities:
Key Features
- Root Privileges Check: Ensures the script is executed with the necessary administrative permissions.
- Automatic Installation: Installs the Dante server if it’s not already present on the system.
- Network Interface Detection: Automatically identifies the primary network interface for accurate proxy configuration.
- Configuration Management: Updates the Dante configuration file to set up the SOCKS5 proxy on the specified port.
- Security Enhancements: Applies
setcap
to allow Dante to bind to privileged ports without running as root. - Service Management: Restarts the Dante service to apply the new configurations seamlessly.
Bash
#!/bin/bash
# =========================================
# Dante Server Setup Script
# =========================================
#
# Version: 1.0.0
# Script written by Warith AL Maawali
#
# Discord channel: https://discord.gg/KEFErEx
# Twitter: http://twitter.com/warith2020
# Linkedin: http://www.linkedin.com/in/warith1977
# Website: https://www.digi77.com
# (c) 2024
#
# Description:
# This script installs and configures the Dante server for SOCKS5 proxy on a Debian-based system.
# It ensures root privileges, installs the Dante server if not already installed, auto-detects the network interface,
# and configures the Dante server to listen on the specified port.
#
# This software is dual-licensed:
#
# Personal, non-commercial use: Apache License 2.0
# Commercial, corporate, or organizational use: Separate commercial license required.
# Contact me for licensing inquiries.
#
# Usage: ./danate-setup.sh
#
# Usage Examples:
# Run this script as root to install and configure the Dante server:
# ./danate-setup.sh
# =========================================
dante_port=4004
# Check if Dante server is already installed
if ! command -v danted &>/dev/null; then
echo "Installing Dante server..."
sudo apt update
sudo apt install -y dante-server
else
echo "Dante server is already installed."
fi
# Auto-detect the network interface
interface=$(ip -o -4 route show to default | awk '{print $5}')
# Check if the configuration file exists and contains the specified port
if ! grep -q "port = $dante_port" /etc/danted.conf; then
echo "Configuring Dante for SOCKS5 on port $dante_port..."
bash -c "cat <<EOF >> /etc/danted.conf
logoutput: syslog
internal: 0.0.0.0 port = $dante_port
internal: :: port = $dante_port
external: $interface
clientmethod: none
socksmethod: none
client pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: error
}
client pass {
from: ::/0 to: ::/0
log: error
}
socks pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: error
}
socks pass {
from: ::/0 to: ::/0
log: error
}
EOF"
danted_path=$(which danted)
if [ -n "$danted_path" ]; then
# Use readlink to get the original file path if it's a symlink
real_danted_path=$(readlink -f "$danted_path")
if [ -n "$real_danted_path" ]; then
echo "Applying setcap to $real_danted_path"
sudo setcap 'cap_net_bind_service=+ep' "$real_danted_path"
else
echo "Failed to resolve the real path for danted"
exit 1
fi
else
echo "Error: danted not found in PATH"
exit 1
fi
# Restart Dante to apply changes
sudo systemctl restart danted
echo "Dante SOCKS5 proxy setup complete on port $dante_port."
else
echo "Dante is already configured correctly."
fi
Bash
Posted in Tech Blog