{"id":46733,"date":"2024-06-12T16:53:43","date_gmt":"2024-06-12T16:53:43","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=46733"},"modified":"2024-06-12T16:53:43","modified_gmt":"2024-06-12T16:53:43","slug":"lightweight-socks5-ubuntu-debian","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2024\/06\/lightweight-socks5-ubuntu-debian\/","title":{"rendered":"Set up Lightweight Socks5 Proxy Server in Ubuntu 24.04 \/ Debian 12"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-43605\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-600x600.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2023\/01\/network-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>This is a step by step beginner&#8217;s guide shows how to install and set up a lightweight Socks5 proxy server in Ubuntu or Debian.<\/p>\n<p>Due to poor network connection, I decided to set up a proxy server on my remote VPS for playing an online game. However, the tutorials on the web are mostly using Dante, which consumes too much RAM, and makes my cheap VPS server frequently run out of memory.<\/p>\n<p>After digging around, I found a lightweight socks5 proxy server called Microsocks. And, here&#8217;s how to install &amp; use it in Debian &amp; Ubuntu.<\/p>\n<p><!--more--><\/p>\n<h3>Step 1: Install Microsocks<\/h3>\n<p><a href=\"https:\/\/github.com\/rofl0r\/microsocks\" target=\"_blank\" rel=\"noopener\">Microsocks<\/a> is a multi-threaded, small, efficient SOCKS5 server, that supports IPv4, IPv6, DNS, and use TCP protocol for network proxy. It&#8217;s easy to set up, and very lightweight that consume less than 4 MB memory in my server. Sadly, it does NOT support UDP as which requires almost double the existing code make it no longer &#8220;micro&#8221;.<\/p>\n<p><b>Debian bullseye, bookworm, as well as Ubuntu 24.04 and Ubuntu 22.04<\/b> include the software package in system repository. You can simply connect to your server and run command to install it:<\/p>\n<pre>sudo apt install microsocks<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/apt-microsocks.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-46734\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/apt-microsocks-700x331.webp\" alt=\"\" width=\"610\" height=\"288\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/apt-microsocks-700x331.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/apt-microsocks-300x142.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/apt-microsocks.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p><b>For old Ubuntu and Debian that don&#8217;t have the package in repository, or if you want to get the latest version,<\/b> do the following steps one by one to build from source.<\/p>\n<ol>\n<li>First, run command to install dependency libraries for building the source:\n<pre>sudo apt install build-essential debhelper<\/pre>\n<\/li>\n<li>Download the source tarball by command:\n<pre>wget http:\/\/ftp.barfooze.de\/pub\/sabotage\/tarballs\/microsocks-1.0.4.tar.xz<\/pre>\n<p><i>As the time goes by, the link will be outdated! Go this <a href=\"https:\/\/github.com\/rofl0r\/microsocks\/releases\" target=\"_blank\" rel=\"noopener\">github page<\/a> for the most recent download link, and use it to replace the one in the command above.<\/i><\/li>\n<li>Once you downloaded the tarball, use command to extract (replace package name accordingly):\n<pre>tar -Jxf microsocks-1.0.4.tar.xz<\/pre>\n<p><i>Replace <code>-Jxf<\/code> in command if the file extension changed. <code>-zxf<\/code> for .tar.gz or <code>-jxf<\/code> for tar.bz2.<\/i><\/li>\n<li>Finally, navigate to the extracted folder and run command to build &amp; install:\n<pre>cd microsocks*<\/pre>\n<pre>make &amp;&amp; sudo make install<\/pre>\n<\/li>\n<\/ol>\n<p>Once successfully installed, you&#8217;ll see the executable file installed to <code>\/usr\/local\/bin<\/code> directory:<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/install-microsocks-source.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-46735\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/install-microsocks-source-700x570.webp\" alt=\"\" width=\"610\" height=\"497\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/install-microsocks-source-700x570.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/install-microsocks-source-300x244.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/install-microsocks-source-768x625.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/install-microsocks-source.webp 1106w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Step 2: Start Microsocks SOCKS5 Server<\/h3>\n<p>Once installed the software package, just run the command below to start the proxy server:<\/p>\n<pre>microsocks -1 -q -i 100.111.122.123 -p 1234 -u JI -P abcde454<\/pre>\n<p>In the command, all the arguments can be skipped.<\/p>\n<ul>\n<li><b>-1<\/b> activates auth_once mode. once a specific ip address authenticated successfully, it is added to a whitelist and may use the proxy without authentication anymore.<\/li>\n<li><b>-q<\/b> disable log. Need version 1.0.4+.<\/li>\n<li><b>-i 100.111.122.123<\/b> tells which IP address to listen on. Skip it so to listen on all network interface in server.<\/li>\n<li><b>-p 1234<\/b> tells to listen on port 1234. Skip it, will listen on default <b>1080<\/b>.<\/li>\n<li><b>-u JI<\/b> and <b>-P abcde454<\/b> specify the username and password for authentication. Username can be any desired text, rather than existing user on server.<\/li>\n<\/ul>\n<p>In my case, I use the command below instead. Which listen on all the server IP, port 1080, authenticated with user <b>JI<\/b> and password <b>abcde454<\/b>.<\/p>\n<pre>microsocks -1 -u JI -P abcde454<\/pre>\n<p>After that, try connecting using a Socks5 client or run command instead to verify:<\/p>\n<pre>curl --socks5 user:password@server-ip:port https:\/\/www.google.com\/<\/pre>\n<h4>Create systemd service for the SOCKS5 server<\/h4>\n<p>Thanks to <a href=\"https:\/\/github.com\/rofl0r\/microsocks\/issues\/69\" target=\"_blank\" rel=\"noopener\">this request<\/a>, you can run the proxy server silently in background as a system service and automatically on startup.<\/p>\n<p>1. To do so, first press <b>Ctrl+C<\/b> to exit the command above if running. Then, run command to create a service file and edit with <code>nano<\/code> editor:<\/p>\n<pre>sudo nano \/etc\/systemd\/system\/microsocks.service<\/pre>\n<p>When the file opens in command line, paste the line below:<\/p>\n<pre>[Unit]\r\nDescription=microsocks SOCKS5 server\r\nDocumentation=https:\/\/github.com\/rofl0r\/microsocks\r\nAfter=network.target auditd.service\r\n\r\n[Service]\r\nEnvironmentFile=\/etc\/microsocks.conf\r\nExecStart=\/usr\/bin\/microsocks -u ${MICROSOCKS_LOGIN} -P ${MICROSOCKS_PASSW}\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n<p><b>NOTE: If you installed the proxy server from source, then replace <code>\/usr\/bin\/microsocks<\/code> with <code>\/usr\/local\/bin\/microsocks<\/code> in lines above, and add more flags, such as <code>-1<\/code>, <code>-p ${PORT}<\/code> as need.<\/b><\/p>\n<p>When done editing the file, press Ctrl+S to save, and Ctrl+X to exit.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/microsocks-servicefile.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-46736\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/microsocks-servicefile-700x505.webp\" alt=\"\" width=\"610\" height=\"440\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/microsocks-servicefile-700x505.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/microsocks-servicefile-300x216.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/microsocks-servicefile.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>2. Next, create the <code>\/etc\/microsocks.conf<\/code> config file and edit with nano:<\/p>\n<pre>sudo nano \/etc\/microsocks.conf<\/pre>\n<p>When file opens, write following lines and save it:<\/p>\n<pre># used by the systemd service file\r\nMICROSOCKS_LOGIN=\"any_name_here\"\r\nMICROSOCKS_PASSW=\"any_password_here\"<\/pre>\n<p>Also add <code>IP=\"xx.xx.xx.xx\"<\/code> and\/or <code>PORT=\"xxxx\"<\/code> if you enable the flags in last step via the systemd service file.<\/p>\n<p>3. Finally, enable and start the service via command:<\/p>\n<pre>sudo systemctl enable --now microsocks.service<\/pre>\n<p>And, verify if it&#8217;s active running by <code>systemctl status microsocks<\/code>.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/microsocks-service.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-46737\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/microsocks-service-700x406.webp\" alt=\"\" width=\"610\" height=\"354\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/microsocks-service-700x406.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/microsocks-service-300x174.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/microsocks-service.webp 735w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Step 3: Open the listening port in firewall<\/h3>\n<p>If your server has firewall enabled, then you need to open the port for the proxy server function.<\/p>\n<p>To do so, first run command to verify the firewall status:<\/p>\n<pre>sudo ufw status<\/pre>\n<p>If it&#8217;s in active running, you may open the port 1080 (replace port number if another in use for microsocks) via command:<\/p>\n<pre>sudo ufw allow 1080\/tcp<\/pre>\n<h3>Connect to the SOCKS5 Server from local machine<\/h3>\n<p>In my case in Windows, I use proxifier to connect to my proxy server. It&#8217;s an app need to paid for use. Just search in Google for download &amp; how to use guide.<\/p>\n<p>For Ubuntu and other Linux (or Windows for web browser), you may enable <b>-1<\/b> flag in the server side, then run the command below in local machine to connect and authenticate (replace user, password, server-ip and port) for the first time:<\/p>\n<pre>curl --socks5 user:password@server-ip:port https:\/\/www.google.com\/<\/pre>\n<p>Next, you can use go to Network -&gt; Proxy to enable the Socks5 proxy without authentication:<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/gnome-network-socks5.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-46738\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/gnome-network-socks5-700x470.webp\" alt=\"\" width=\"610\" height=\"410\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/gnome-network-socks5-700x470.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/gnome-network-socks5-300x201.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/gnome-network-socks5-768x515.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2024\/06\/gnome-network-socks5.webp 1230w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Uninstall:<\/h3>\n<p>To uninstall the SOCKS5 proxy server in your Debian or Ubuntu, either use command:<\/p>\n<pre>sudo apt remove microsocks<\/pre>\n<p>Or, just delete the executable file if you installed it from the source:<\/p>\n<pre>sudo rm \/usr\/local\/bin\/microsocks<\/pre>\n<p>Also, disable the systemd service if installed:<\/p>\n<pre>sudo systemctl disable --now microsocks.service<\/pre>\n<p>And, run <code>sudo rm \/etc\/microsocks.conf<\/code> to delete the config file.<\/p>","protected":false},"excerpt":{"rendered":"<p>This is a step by step beginner&#8217;s guide shows how to install and set up a lightweight Socks5 proxy server in Ubuntu or Debian. Due to poor network connection, I decided to set up a proxy server on my remote VPS for playing an online game. However, the tutorials on the web are mostly using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":43605,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[1317,2171],"class_list":["post-46733","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-network","tag-socks5"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/46733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=46733"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/46733\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/43605"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=46733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=46733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=46733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}