In this article, we’ll walk through configuring proxy settings on Ubuntu, focusing on HTTP and SOCKS5 proxies. You’ll learn the key differences between forward and reverse proxies, as well as between HTTP and SOCKS5 proxies, with use cases for each. We’ll cover both command-line (CLI) methods and using Squid, a popular proxy server, for setting up proxies.
Let’s get started!
A proxy in Ubuntu is a network service configured to route your system's internet traffic through an intermediary server. This setup allows you to control outgoing and incoming traffic, manage access, and improve security. By adjusting proxy settings in Ubuntu, you can direct network requests through specific servers. This is useful for enhancing privacy, bypassing geographical restrictions, or managing traffic in organizational networks.
In Ubuntu, a forward proxy routes outgoing traffic from your system to external servers, acting as an intermediary. It's typically used to hide your IP address, control internet access, or bypass network restrictions. Forward proxies in Ubuntu are often set up for privacy, content filtering, or managing network traffic for individual users or devices.
A reverse proxy in Ubuntu, on the other hand, manages incoming traffic to a server from external clients. It's commonly used to improve load balancing, secure servers, and distribute requests across multiple backend servers in a network.
In this article, we’ll focus on setting up forward proxies in Ubuntu to manage outgoing requests from your system.
The major differences between both are as:
To configure a proxy on Ubuntu, you’ll need to ensure the following:
sudo apt update
sudo apt upgrade
Network Connectivity: Ensure your Ubuntu system is connected to the internet. You can check your connection with the following command:
ping google.com
To start using free proxies, sign up on Webshare and get access to their proxy services. Webshare offers both HTTP and SOCKS5 proxies, which you can use for routing your network traffic. After registering, you’ll receive proxy details such as IP addresses, ports, and authentication credentials.
When setting up an HTTP proxy on Ubuntu, there are two common methods: using the command line interface (CLI) and setting up a proxy server like Squid. Both approaches are efficient and allow you to control network traffic, improve privacy, and bypass restrictions.
Setting up an HTTP proxy using the command terminal (CLI) on Ubuntu is quick and easy. This method configures system-wide proxy settings that apply to all terminal-based applications.
Open the terminal and run the following commands, replacing proxy-server and port with the actual proxy details from your provider (e.g., Webshare):
export http_proxy="http://proxy-server:port"
export https_proxy="http://proxy-server:port"
nano ~/.bashrc
Add the following lines at the end of the file:
export http_proxy="http://proxy-server:port"
export https_proxy="http://proxy-server:port"
After saving the changes, run:
source ~/.bashrc
curl ifconfig.me
This command should return the IP address of your proxy server. If it matches, your proxy is configured correctly.
unset http_proxy
unset https_proxy
Squid is a widely-used proxy server software that allows more advanced configurations, such as caching, access control, and traffic filtering. Here's how to set up Squid for HTTP proxy on Ubuntu.
sudo apt update
sudo apt install squid
Open the configuration file in a text editor:
sudo nano /etc/squid/squid.conf
Locate the http_port directive and ensure it is uncommented or add it if missing. Set it to the desired port for the proxy (default is 3128):
http_port 3128
acl all src 0.0.0.0/0
http_access allow all
For more secure setups, you can restrict access to specific IP ranges.
sudo systemctl start squid
Enable Squid to run on startup with:
sudo systemctl enable squid
tail -f /var/log/squid/access.log
curl -x http://localhost:3128 http://ifconfig.me
Setting up a SOCKS5 proxy on Ubuntu can be done using the command line (CLI) or by configuring a proxy server like Squid.
Setting up a SOCKS5 proxy via the command line is straightforward and can be done with the help of tools like ssh or proxychains.
Open the terminal and run the following command:
ssh -D [local-port] [username]@[remote-server-ip]
Replace:
For example:
ssh -D 1080 user@123.456.78.9
This command will create a SOCKS5 proxy on your local machine, running on port 1080. All traffic routed through this proxy will go through the remote server, enhancing privacy.
curl --socks5 localhost:1080 ifconfig.me
Proxychains is a tool that forces any application to use a SOCKS5 proxy, even if the application doesn't natively support proxy configuration.
sudo apt update
sudo apt install proxychains
sudo nano /etc/proxychains.conf
Scroll to the bottom of the file and add your SOCKS5 proxy details in the following format:
socks5 127.0.0.1 1080
proxychains curl ifconfig.me
This command forces curl to use the SOCKS5 proxy for outgoing traffic.
Squid does not natively support SOCKS5 proxy functionality. Squid is primarily designed for HTTP and HTTPS traffic and cannot handle SOCKS5 connections directly. If you need SOCKS5 proxy support, Squid is not the ideal choice. Instead, you would use a tool like Dante, which is a SOCKS proxy server designed specifically for SOCKS5 traffic.
Below are the steps to set up SOCKS5 proxy on Ubuntu using Dante:
sudo apt update
sudo apt install dante-server
sudo nano /etc/danted.conf
Add the following configuration, replacing [server-ip] with the IP address of your Ubuntu machine and [port] with the desired port for the SOCKS5 proxy (e.g., 1080):
logoutput: syslog
internal: [server-ip] port = [port]
external: [server-ip]
method: username none
client pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: connect disconnect error
}
socks pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
}
sudo systemctl start danted
sudo systemctl enable danted
curl --socks5 [server-ip]:[port] ifconfig.me
tail -f /var/log/syslog
Although Squid is not natively designed for SOCKS5, you can configure it to work in conjunction with a SOCKS5 proxy like Dante or ssh for a hybrid setup.
sudo apt install tsocks
Then configure it to route Squid traffic through the SOCKS5 proxy by editing /etc/tsocks.conf and adding:
server = 127.0.0.1
server_port = 1080
sudo tsocks systemctl start squid
Setting up proxies on Ubuntu—whether HTTP or SOCKS5—can enhance privacy and security for your online activities. For HTTP proxies, Squid offers a reliable solution, while SOCKS5 proxies can be implemented using tools like Dante for a dedicated server or tsocks to route traffic through an existing SOCKS5 proxy.