How to Use Proxychains to Redirect Traffic Through Proxy Server

Sometimes we install a proxy server, but only certain programs such as Firefox and Google chrome provide proxy settings. Luckily, we can use a command line utility called proxychains to redirect any program to go through our proxy server. This tutorial will show you how to set it up on Debian, Ubuntu, OpenSUSE, Fedora, CentOS/Redhat, Arch Linux and their derivatives.

If your don’t know how to set up a proxy server, then check out this post to learn shadowsocks proxy. After that, come back here.

Install proxychains on Linux

Debian/Ubuntu/Linux Mint/Elementary OS

sudo apt-get install proxychains4

OpenSUSE Leap

proxychains is available from the packman repository.

sudo zypper install proxychains

Fedora

sudo dnf install proxychains

CentOS/Redhat

sudo yum install proxychains

Archlinux

sudo pacman -S proxychains-ng

On kali linux, proxychains is installed by default.

Add a Proxy Server to Proxychains

Open the configuration file.

sudo nano /etc/proxychains4.conf

At the end of the file, add your proxy like this

socks5   127.0.0.1   1080

socks5 is the proxy type, you can add other types as well such as http, https, socks4 etc. depending on your situation. 127.0.0.1 is the proxy host, and 1080 is the port on which proxy server listens. Again, change them to your specific situation.

The default proxy is socks4 127.0.0.1 9050 which you can safely remove.

Set a Default DNS Server

It’s highly recommended that you change the default 4.4.2.2 DNS server to something else, such as Google’s DNS server 8.8.8.8/8.8.4.4. Or OpenDNS server 203.67.222.222/203.67.220.220. Open the resolv configuration file.

Debian/Ubuntu

sudo nano /usr/lib/proxyresolv

Linux Mint/Elementary OS

sudo nano /usr/lib/proxychains3/proxyresolv

Fedora/CentOS/Redhat/OpenSUSE

sudo nano /usr/bin/proxyresolv

Find the following line

DNS_SERVER=4.4.2.2

Change its value to something like 8.8.8.8. Then save and close the file. On Arch Linux, there’s no proxyresolv config file.

Test

Just prepend proxychains to any command you execute like the following.

proxychains youtube-dl -citw https://www.youtube.com/channel/<channel-id>

If you are using youtube-dl then you may know that it has not built-in support for socks proxy, but Proxychains will redirect youtube-dl to go through the proxy server.

If you want to redirect all your terminal traffic through proxy server, then enter start a new shell program with proxychains, like below.

proxychains bash

This command will start another bash shell with proxychains in your terminal and from now on you don’t have to prepend proxychains to your command. Your traffic in this new shell will be automatically redirected through proxy server.

Note:  Terminal is different from shell. Terminal is the device that enable you to connect to a host computer whereas shell is a piece of software on the host computer. Shell is a command line interpreter, translating your command to zeros and ones so the computer can understand your command. When a terminal connects to a host computer, a shell program will be automatically started so that the user’s commands can be interpreted by the shell and the computer can understand the user’s commands.

Quiet Mode

By default, proxychains will output its activity to the terminal. If you don’t want to see this information, then you can disable it by editing /etc/proxychains.conf file.

sudo nao /etc/proxychains.conf

Find the following line

#quiet_mode

Remove the hashtag. Save and close the file. Now you will only see the output of the application that is being redirected.

As always, if you found this post useful, please subscribe to our free newsletter or follow us on Google+, Twitter or like our Facebook page

Rate this tutorial
[Total: 19 Average: 4]

7 Responses to “How to Use Proxychains to Redirect Traffic Through Proxy Server

  • Will it work using the default socks5 server or do I need to buy or find a different one to add?

    I’ve tried to access a search engine Using the proxy chain command however it opens up my browser and says “cannot find server”.

    • Xiao Guo An (Admin)
      5 years ago

      Hi, there are two parts in SOCKS proxy: the server part and the client part.

      You need to set up a SOCKS proxy on a remote server and install the SOCKS client on your local computer.

      The SOCKS client listens on a port on localhost and you need to configure proxychains to redirect traffic to that port.

      the default socks4 127.0.0.1 9050 in /etc/proxychains.conf won’t work.

  • Kamran Hosseini
    5 years ago

    so as you said I can use “proxychains google-chrome” and all the traffic goes through the port I specified in the config file?
    I did this and nothing happens!

  • the correct command for Setting Default DNS Server in Debian/Ubuntu:
    sudo nano /usr/lib/proxychains3/proxyresolv

  • cool toh..

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here