The essential points from this guide -- each one is explained in detail below.
Environment variables (http_proxy, https_proxy) set proxy access for a shell session or specific commands.
Ubuntu's GUI network settings apply a proxy system-wide for desktop apps.
Squid turns a Linux server into its own local proxy that other devices can route through.
Command-line tools like apt and curl need their own proxy config files -- environment variables alone do not always cover them.
Persistent proxy settings survive reboots when added to shell profile files or systemd environment files.
Most Linux tools read proxy settings from four environment variables: http_proxy, https_proxy, ftp_proxy, and no_proxy. Setting these gives your shell and any program launched from it a linux proxy server to route through, without editing each application's own configuration file.
To set a proxy for your current session, run:
export http_proxy="http://USER:PASS@gw.knoxproxy.com:7000"
export https_proxy="http://USER:PASS@gw.knoxproxy.com:7000"
export no_proxy="localhost,127.0.0.1"The USER and PASS placeholders are the credentials your proxy provider issues, and the host and port after the @ symbol point to the provider's gateway. The no_proxy variable lists hosts that should bypass the proxy entirely, such as internal servers, localhost, or other machines on your local network that do not need to route through an external IP.
Some tools check the uppercase versions (HTTP_PROXY, HTTPS_PROXY) instead of the lowercase form, so set both cases to be safe:
export HTTP_PROXY="$http_proxy"
export HTTPS_PROXY="$https_proxy"These variables only apply to the current terminal session and to any child process launched from it. Close the terminal, and they are gone. A background service started before you exported the variables will not pick them up either, since it inherited the environment from an earlier, proxy-less state. For a proxy server on Ubuntu that needs to persist across logins and reboots, add the export lines to a shell profile file or a systemd environment file, which the later section on persistence covers in detail.
Ubuntu's desktop environment includes a graphical proxy configuration that applies to system apps and most browsers. Open Settings, then Network, then Network Proxy. You can choose Manual mode and enter a separate proxy address and port for HTTP, HTTPS, FTP, and SOCKS traffic.
Manual mode is the right choice when you have specific proxy credentials from a provider. Automatic mode instead points to a PAC (Proxy Auto-Config) file URL, which is common in corporate networks that route different destinations through different proxies.
The GUI method works well for a desktop workstation but is not available on headless Ubuntu servers, which have no graphical interface. For those, the environment variable and command-line tool methods below are the practical path. GNOME's proxy settings also only affect apps that read the system proxy config (like GNOME's own apps and some browsers) -- many command-line tools ignore it entirely and need their own configuration.
Squid is a free, open-source proxy server that runs directly on Ubuntu and other Linux distributions. It turns your machine into its own linux proxy server that other devices on the network can route through, or that you can chain to an upstream commercial proxy.
Install Squid with:
sudo apt update
sudo apt install squidSquid's main config file lives at /etc/squid/squid.conf. A minimal working config allows connections from your local network on the default port 3128:
http_port 3128
acl localnet src 192.168.1.0/24
http_access allow localnet
http_access deny allThe acl line defines which source addresses count as trusted local traffic, and the two http_access lines allow that trusted range while denying everyone else by default. Adjust the subnet in the acl line to match your own local network range before restarting the service.
Restart the service to apply changes:
sudo systemctl restart squid
sudo systemctl enable squidThe enable command makes Squid start automatically on every boot, so it is available immediately after a server restart rather than requiring a manual start each time.
Squid is useful for caching repeated requests, filtering traffic on a local network, or acting as a forwarding layer in front of an upstream residential or datacenter proxy pool. It is not a replacement for a rotating IP pool -- Squid still exits through your server's single IP unless you configure it to forward to an upstream proxy. For workloads that need a large pool of rotating exit IPs, such as web scraping or geo-testing, pair Squid's local caching with an upstream residential proxy rather than relying on Squid alone.
Environment variables cover many command-line tools, but not all of them read the standard http_proxy variable automatically. Some need their own config file with linux server proxy settings written in a tool-specific format.
For apt, create /etc/apt/apt.conf.d/95proxies with:
Acquire::http::Proxy "http://USER:PASS@gw.knoxproxy.com:7000";
Acquire::https::Proxy "http://USER:PASS@gw.knoxproxy.com:7000";For curl, either pass the proxy directly on each call:
curl -x http://USER:PASS@gw.knoxproxy.com:7000 https://example.comor set it once in ~/.curlrc:
proxy = http://USER:PASS@gw.knoxproxy.com:7000wget reads the standard http_proxy and https_proxy environment variables, but you can also set them explicitly in /etc/wgetrc with http_proxy and https_proxy lines. Git needs its own setting too: git config --global http.proxy http://USER:PASS@gw.knoxproxy.com:7000. Always check a tool's documentation before assuming the environment variables alone will cover it.
Environment variables set with export only last for the current shell session. To make them persistent, add the export lines to a shell profile file that loads automatically.
For a proxy that applies to one user, edit ~/.bashrc or ~/.profile and add:
export http_proxy="http://USER:PASS@gw.knoxproxy.com:7000"
export https_proxy="http://USER:PASS@gw.knoxproxy.com:7000"Then reload it with source ~/.bashrc.
For a system-wide setting that applies to every user, add the same lines to /etc/environment instead (without the export keyword, since /etc/environment uses plain KEY=value syntax):
http_proxy="http://USER:PASS@gw.knoxproxy.com:7000"
https_proxy="http://USER:PASS@gw.knoxproxy.com:7000"If you run services under systemd, add proxy variables to the service's unit file or to /etc/systemd/system.conf.d/proxy.conf under an [Manager] Environment= directive, then run sudo systemctl daemon-reload. This ensures background services pick up the proxy on boot, not just interactive shell sessions.
env | grep -i proxy in a terminal to see all proxy-related environment variables set in your current session. For apt, check the files inside /etc/apt/apt.conf.d/ for a proxy config entry. For Squid, open /etc/squid/squid.conf and look for the http_port and acl directives directly.export ALL_PROXY="socks5://USER:PASS@gw.knoxproxy.com:7001" for tools that support SOCKS5 directly, noting the port usually differs from the HTTP proxy port. Not every command-line tool reads ALL_PROXY, so check each tool's documentation before assuming SOCKS5 support works out of the box.unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY to clear proxy variables from the current session. Then remove any export lines you added to ~/.bashrc, ~/.profile, or /etc/environment, and reload the shell with source ~/.bashrc or reboot the server. If you set a proxy through Ubuntu's GUI, switch Network Proxy back to Off in Settings > Network instead.Ready to put this into practice? Browse Residential Proxies
KnoxProxy Research Team · Technical Content
Network engineers and proxy infrastructure specialists with 10+ years in anti-bot systems, web scraping, and IP routing.
90.4M+ ethically sourced residential IPs across 195 countries. Instant activation, 14-day money-back guarantee.