How to use SOCKS 5 proxy in Ubuntu command line

This post is originally posted in Indonesian on my other blog: Here I wrap up it in English.

Sometimes, we need a proxy to bypass internet filtering. When we work in command line environment, it may not as simple as in graphical environment. But thanks to proxychains, it becomes so simple that we just need to put proxychains command before the commands we want to execute. Proxychains is available in Ubuntu repository. So, we just have to run sudo apt-get install proxychains to install it.

Proxychains can handle several proxy types, including SOCKS5 proxy. It is an SSH tunneling proxy. So we need a remote machine which allows us to login and access internet. That’s usually a VPS. So, we need to connect to SSH and make a tunnel before using proxychains.

ssh -vfCND1080 -l login_name -p port remote_machine_address
  • v argument makes verbose output, so you may ommit it
  • f argument makes ssh session run in the background
  • C argument enables compression for all data
  • N argument disables remote command to the machine we connect
  • D1080 means to make local dynamic listening poxy at port 1080
  • login_name is the username of our remote machine
  • port is the SSH port of remote machine, usually 22
  • remote_machine_address is the address of our remote machine, either IP number or domain

Once connected, we can now use proxychains to bypass internet blocking. But first, we need to configure the proxychains in order to use our tunnel proxy. Edit the /etc/proxychains.conf file. Make sure you have these lines uncommented.

tcp_read_time_out 15000
tcp_connect_time_out 8000
socks5 1080

We can also make a per-user config file at $HOME/.proxychains/proxychains.conf. Then we can make use of proxychains in every command we execute which needs internet. For instance:

sudo proxychains apt-get update

Share your idea here (markdown enabled)

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.