File size: 1,245 Bytes
6c71751 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
#!/bin/bash
set -e
echo "Starting SSH/SOCKS5 NAT Gateway setup..."
# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
# Fetch public IP
PUBLIC_IP=$(curl -s ifconfig.me)
if [ -z "$PUBLIC_IP" ]; then
echo "Error: Could not fetch public IP. Exiting."
exit 1
fi
echo "Detected public IP: $PUBLIC_IP"
# Configure SSH server
cp /app/ssh-config/sshd_config /etc/ssh/sshd_config
chmod 600 /etc/ssh/sshd_config
# Generate SSH host keys if they don't exist
if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
ssh-keygen -A
fi
# Start SSH service in debug mode and redirect output to a file
/usr/sbin/sshd -D -e -f /etc/ssh/sshd_config > /var/log/sshd_debug.log 2>&1 &
echo "SSH server started."
# Configure Dante SOCKS5 server
cp /app/socks5-config/danted.conf /etc/danted.conf
chmod 644 /etc/danted.conf
# Start Dante SOCKS5 server
/usr/sbin/danted -D &
echo "Dante SOCKS5 server started."
# Apply iptables rules for NAT using iptables-legacy
iptables-legacy -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables-legacy -A FORWARD -i eth0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables-legacy -A FORWARD -i eth0 -o eth0 -j ACCEPT
echo "iptables NAT rules set."
# Keep the container running
exec tail -f /dev/null
|