Sunday, October 20, 2024

How to Setting Up a SOCKS5 Proxy Server on Linux with MicroSocks

While Virtual Private Networks (VPNs) are popular for securing online activities, many users still prefer the speed and efficiency of SOCKS proxies, particularly for managing torrent traffic. This article explores how to set up a robust and lightweight SOCKS5 proxy server on your Linux system using MicroSocks.

MicroSocks: A Simple and Efficient Solution

MicroSocks stands out as a lightweight and multi-threaded SOCKS5 proxy server designed to handle requests effectively even on systems with limited resources. It achieves this by consuming minimal resources and gracefully denying new connections during periods of high demand, rather than abruptly aborting them.

Here are some of MicroSocks' key features:

  • IPv4 and IPv6 Support: MicroSocks seamlessly supports both IPv4 and IPv6 addressing, ensuring compatibility with modern networks.

  • DNS Support: It handles DNS requests, ensuring smooth resolution of domain names.

  • TCP-Based: MicroSocks currently relies on TCP for network proxying, providing a reliable and well-established protocol.

  • Flexible Authentication: You can connect to MicroSocks with or without a password, or even use a one-time password. The flexibility eliminates the need for configuration file manipulation.

Installation and Configuration

MicroSocks is readily available in most Linux repositories. Let's examine the installation process on popular distributions:

Debian, Ubuntu, Kali Linux, Linux Mint, etc.

      sudo apt install microsocks
    

Arch Linux, Manjaro, BlackArch, Garuda, etc.

      sudo pacman -S microsocks
    

For Red Hat and Fedora-based distributions, or older Debian and Ubuntu versions, you can compile and install from source to ensure the latest version:

  1. Install development tools:

          sudo apt update && sudo apt install build-essential
        

  2. Download and extract MicroSocks:

    wget http://ftp.barfooze.de/pub/sabotage/tarballs/microsocks-1.0.4.tar.xz
    tar -xvf microsocks-1.0.4.tar.xz && cd microsocks*/
        

  3. Compile and install:

          make && sudo make install
        

Once the installation is complete, the MicroSocks executable will be located in the "/usr/local/bin" directory.

Starting the MicroSocks Proxy Server

The "microsocks" command is now ready for use. Before launching it, let's explore some useful options:

  • -1: Enables one-time authentication, adding your IP address to a whitelist. Subsequent connections from this IP will not require authentication.

  • -q: Disables logging.

  • -i ip-address: Specifies the IP address to listen on. If omitted, MicroSocks listens on all network interfaces (default: "0.0.0.0").

  • -p port: Sets the listening port (default: "1080").

  • -u user and -P password: Specify the username and password for authentication in plain text. These can be any combination and are independent of existing user accounts on your system.

For instance, let's say you want to run MicroSocks on a DigitalOcean VPS, listening on all server IPs using port 8484 with a username "proxyuser" and password "securepassword":

      microsocks -1 -p 8484 -u proxyuser -P securepassword
    

The output should display "starting microsocks server."

Connecting to the MicroSocks Server

To connect to the newly started MicroSocks server from your local machine, use the following command, replacing the placeholders with your actual server information:

      curl --socks5 user:password@server-ip:port https://www.google.com/
    

This will connect to your MicroSocks server. Due to the "-1" option, your local machine will be whitelisted, allowing you to configure your browser or operating system for SOCKS5 without providing credentials.

Configuring Browsers and Systems

Firefox:

  1. Open Firefox and go to "Preferences".

  2. Select "General".

  3. Scroll down to "Network Settings" and click "Settings".

  4. Choose "Manual proxy configuration".

  5. Select "SOCKS v5".

  6. Enter the host and port of your MicroSocks server.

GNOME (Ubuntu)

  1. Go to "Settings".

  2. Navigate to "Network" and then "Proxy".

  3. Enable "Network Proxy" and select "Manual" configuration.

  4. Enter the host and port of your MicroSocks server in the "SOCKS5 HOST" section.

Firewall Configuration

If you're using UFW (Uncomplicated Firewall) on Ubuntu, you need to open the port your proxy server is listening on.

  1. Check your firewall status:

          sudo ufw status
        

  2. If UFW is active, open the port (remember, we used port 8484 in our example):

          sudo ufw allow 8484/tcp
        

Systemd Service for Background Execution

To ensure the MicroSocks proxy server runs in the background and automatically starts at boot, create a Systemd service:

  1. Create a Systemd service file:

          sudo nano /etc/systemd/system/microsocks.service
        

  2. Paste the following configuration (adjust the "/usr/bin/microsocks" path if you installed MicroSocks from source):

    [Unit]
    Description=microsocks SOCKS5 server
    Documentation=https://github.com/rofl0r/microsocks
    After=network.target auditd.service
    
    [Service]
    EnvironmentFile=/etc/microsocks.conf
    ExecStart=/usr/bin/microsocks -1 -u ${MICROSOCKS_LOGIN} -P ${MICROSOCKS_PASSW}
    
    [Install]
    WantedBy=multi-user.target
        

  3. Save and close the file.

  4. Create a MicroSocks configuration file for the username and password:

          sudo nano /etc/microsocks.conf
        

  5. Paste the following (replace the user and password with your MicroSocks details):

          # used by the systemd service file
    MICROSOCKS_LOGIN="proxy-user"
    MICROSOCKS_PASSW="proxy-password"
        

  6. Save and close the file.

  7. Enable and start the service:

          sudo systemctl enable --now microsocks.service
        

  8. Verify the service status:

          systemctl status microsocks
        

Uninstalling MicroSocks

To uninstall MicroSocks:

Package Manager Installation:

  • Debian, Ubuntu, etc.:

          sudo apt remove microsocks
        

  • Arch Linux, Manjaro, etc.:

          sudo pacman -R microsocks
        

Source Installation:

      sudo rm /usr/local/bin/microsocks
    

Removing the Systemd Service:

sudo systemctl disable --now microsocks.service
sudo rm /etc/microsocks.conf
    

Closing the Firewall Port:

  1. Find the port's index number:

          sudo ufw status numbered
        

  2. Delete the corresponding port:

          sudo ufw delete [no]
        

Conclusion

MicroSocks provides a reliable and lightweight solution for setting up a SOCKS5 proxy server on your Linux system. With its simple configuration and flexible authentication options, it empowers you to enhance your online privacy and security, manage traffic efficiently, and access blocked content with ease. By following the steps outlined in this guide, you can easily deploy and manage a robust SOCKS5 proxy server, taking control of your online experience.

0 comments:

Post a Comment