Setting Up a SOCKS5 Proxy with Danted on Ubuntu

2024-09-05

Setting Up a SOCKS5 Proxy with Danted on Ubuntu


In today's digital world, the need for secure and efficient internet access has become increasingly important. One way to achieve this is by setting up a SOCKS5 proxy, which allows clients to route their traffic through a remote server. This guide will walk you through the process of installing and configuring Danted, a popular SOCKS5 proxy server, on an Ubuntu system.


What is a SOCKS5 Proxy?

SOCKS (Socket Secure) is a protocol that routes network packets between a client and server through a proxy server. SOCKS5 is the latest version of this protocol and supports various authentication methods, UDP traffic, and IPv6. It is widely used for:

- Anonymity: Hiding the user's IP address.

- Bypassing Restrictions: Accessing geo-restricted content.

- Security: Protecting data transmitted over the network.


Why Choose Danted?

Danted is a versatile and easy-to-configure SOCKS proxy server that supports both IPv4 and IPv6. Its lightweight nature and robust features make it a popular choice for users looking to set up a SOCKS5 proxy.


Prerequisites

Before you begin, ensure you have:

1. A running instance of Ubuntu (18.04 or later).

2. Root or sudo access to the server.

3. Basic knowledge of Linux command line.


Step 1: Installing Danted

To install Danted on your Ubuntu server, follow these steps:

1. Update Package Lists:

Begin by updating your package lists to ensure you have the latest information:

```bash

sudo apt update

```

2. Install Danted:

Install the Danted package using the following command:

```bash

sudo apt install dante-server

```

3. Verify Installation:

After installation, check if Danted is installed correctly:

```bash

dpkg -l | grep dante

```


Step 2: Configuring Danted

The main configuration file for Danted is located at `/etc/danted.conf`. Before making changes, it’s wise to back up the original configuration file:

```bash

sudo cp /etc/danted.conf /etc/danted.conf.bak

```

Basic Configuration

1. Open the Configuration File:

Use a text editor to open the configuration file:

```bash

sudo nano /etc/danted.conf

```

2. Configure the Server:

Here’s a basic configuration example. Modify the following lines according to your network settings:

```plaintext

logoutput: /var/log/danted.log

internal: eth0 port = 1080

external: eth0

method: username none

client pass {

from: 0.0.0.0/0 to: 0.0.0.0/0

log: connect disconnect

}

sock pass {

from: 0.0.0.0/0 to: 0.0.0.0/0

log: connect disconnect

}

```

In this configuration:

- `logoutput` specifies where logs will be stored.

- `internal` defines the interface and port for the proxy.

- `external` specifies the outgoing interface.

- The `method` line sets the authentication method.

- The `client pass` and `sock pass` sections define access rules.

3. Save and Exit:

After editing, save the changes and exit the editor.


Step 3: Setting Up User Authentication (Optional)

If you want to restrict access to the proxy server, you can set up user authentication. First, create a user that will be used for authentication:

```bash

sudo adduser --system --no-create-home danteuser

```

Then, update the `method` line in the configuration file to use the `username` method:

```plaintext

method: username

```

To add users for authentication, you can use the `htpasswd` utility from the `apache2-utils` package:

1. Install Apache2 Utils:

```bash

sudo apt install apache2-utils

```

2. Create a Password File:

```bash

sudo touch /etc/danted.passwd

```

3. Add Users:

```bash

sudo htpasswd /etc/danted.passwd username

```

4. Update Configuration:

Modify the `danted.conf` file to include the password file:

```plaintext

method: username

user.privileged: root

user.unprivileged: danteuser

```


Step 4: Restarting Danted

After making changes to the configuration, restart the Danted service to apply them:

```bash

sudo systemctl restart danted

```


Step 5: Allowing Firewall Access

If you have a firewall enabled, ensure that the SOCKS5 port (default is 1080) is open:

1. Allow Port 1080:

```bash

sudo ufw allow 1080/tcp

```

2. Check UFW Status:

Verify that the rule has been added:

```bash

sudo ufw status

```


Step 6: Testing the SOCKS5 Proxy

To test your SOCKS5 proxy, you can use tools like `curl` or configure your web browser to use the proxy.

Testing with Curl

Use the following command to test the proxy:

```bash

curl --socks5-hostname localhost:1080 http://www.example.com

```

If everything is set up correctly, you should see the HTML output of the webpage.


Configuring a Web Browser

To configure a web browser (like Firefox or Chrome) to use the SOCKS5 proxy:

1. Open Network Settings in your browser.

2. Set the Proxy Type to SOCKS5.

3. Enter the Proxy Address: `localhost` and Port: `1080`.

4. Save Changes and test by visiting a website.


Conclusion

Setting up a SOCKS5 proxy using Danted on an Ubuntu server is a straightforward process that enhances privacy and security. By following the steps outlined in this guide, you can successfully configure a SOCKS5 proxy, allowing users to route their traffic securely and efficiently. Whether for personal use or organizational needs, a SOCKS5 proxy can provide significant benefits in managing internet access.