Tutorial

How to Set Up a Proxy on Ubuntu

Four places hold a proxy on Ubuntu. Which one reaches your program, the commands for each, and the check that proves it. Measured on Ubuntu 24.04.

HProxy Team··Updated September 16, 2026·5 min read
HProxy.Tutorial

Free proxies won't hold up here.

Shared datacenter IPs get flagged and dropped fast. When it has to hold, gaming, streaming, accounts, you need mobile and residential IPs that read as a real device, from $0.44/GB, pay as you go.

See plans & pricing

Ubuntu keeps the proxy setting in four separate places, and each one reaches a different set of programs. That is why the panel in Settings can be filled in correctly while sudo apt update still goes straight out. Pick the place that covers the program you care about, then prove it with one command.

Everything below was measured on our own server on 16 September 2026: Ubuntu 24.04.4 LTS with apt 2.8.3, sudo 1.9.15p5 and snapd 2.76. Where a step was not run, the desktop panel above all, this page says so.

Where you set itWhat it reachesWhat it leaves out
Settings, Network, Network ProxyDesktop apps that read the desktop settingTerminals, apt, snap
export in a terminalcurl, wget, git, pip and apt in that terminalOther terminals, anything under sudo
/etc/environmentEvery login shell, and sudo through PAMPrograms already running, snap
/etc/apt/apt.conf.d/apt, including under sudoEverything that is not apt
/etc/systemd/system/snapd.service.d/snap downloadsEverything that is not snap

Canonical makes the same split in its own tooling. The ubuntu-proxy-manager project writes a single proxy into three separate files, one for the environment, one for apt and one for the desktop, and it silently skips values a backend cannot express, such as no_proxy for apt.

What you need before you start

  • A proxy address as host:port, plus a user name and password if the proxy needs a login. If your provider sent four values in a different order, the proxy format guide sorts them out.
  • A terminal. Every step here except the desktop panel works on a server with no desktop, and inside WSL.
  • For a first test, any HTTP entry from our free proxy list will do. Expect it to die within hours.

Step 1: set the proxy for this terminal

export http_proxy="http://user:pass@host:port" https_proxy="http://user:pass@host:port" no_proxy="localhost,127.0.0.1,::1"

Both variables start with http://, including the one for HTTPS, because they name the proxy and the proxy speaks plain HTTP. Write the names in lower case. When we set only the upper-case HTTP_PROXY to a dead address, curl fetched the page anyway, exactly like the control run with no proxy set. With the lower-case name it failed at once, which is the behaviour you want.

This setting lives until you close the terminal. The Linux page carries the per-tool detail for curl, wget, git and pip.

Step 2: make it permanent

For one user, add the same line to the end of ~/.bashrc. A new terminal reads it.

For every user, put the three names into /etc/environment as plain lines:

http_proxy="http://user:pass@host:port"
https_proxy="http://user:pass@host:port"
no_proxy="localhost,127.0.0.1,::1"

On a fresh Ubuntu 24.04.4 install that file holds one line, the PATH, so anything else in it was put there by somebody. The file is read at login, not by the shell you already have open, so log out and back in.

Step 3: give apt its own setting

apt does not read the desktop panel, and under sudo it does not see your shell variables either. It reads its own option. Write it into a fragment so an upgrade never overwrites it:

echo 'Acquire::http::Proxy "http://user:pass@host:port/";' | sudo tee /etc/apt/apt.conf.d/99proxy
echo 'Acquire::https::Proxy "http://user:pass@host:port/";' | sudo tee -a /etc/apt/apt.conf.d/99proxy

The manual for the transport apt uses gives the form scheme://[[user][:pass]@]host[:port]/. It also takes a per-host option, Acquire::http::Proxy::archive.ubuntu.com, and the special value DIRECT for a host that should skip the proxy. On a stock install apt has no proxy at all: apt-config dump printed nothing for that option before we set it.

Step 4: snap needs a setting of its own

Snap downloads follow neither the panel nor your shell. On our server, snapd started with an empty environment, had no drop-in directory, and snap get system proxy answered that the option is not set. The documented snap set system proxy.http option is listed for Ubuntu Core.

On a desktop or server install, give snapd the variables through systemd:

sudo mkdir -p /etc/systemd/system/snapd.service.d
printf '[Service]\nEnvironment=http_proxy=http://user:pass@host:port\nEnvironment=https_proxy=http://user:pass@host:port\n' | sudo tee /etc/systemd/system/snapd.service.d/proxy.conf
sudo systemctl daemon-reload && sudo systemctl restart snapd

Step 5: the desktop panel, and what it is for

On Ubuntu Desktop, Ubuntu own help gives these steps: open the Activities overview and start typing Network, click Network to open the panel, then select Network proxy from the list on the left. The three methods are None, Manual and Automatic. Manual takes an address and a port per protocol, and Automatic takes a URL that holds the configuration.

We did not run this step, because we measured on a server install, and a server has no such panel at all: the proxy schema the desktop uses was absent on our machine. Treat the panel as the setting for desktop apps, and keep the terminal, apt and snap settings above for everything else.

Check that it worked

curl -s https://www.cloudflare.com/cdn-cgi/trace | grep ^ip=
curl -s https://hproxy.com/api/ip/THE_ADDRESS_YOU_JUST_SAW

The first line prints the address a site sees. If it is the proxy address, your traffic is going through the proxy. The second line takes that address and returns its country, city, network and AS number, so you can tell a datacenter range from a home connection. Then paste the entry into our free proxy checker, which reports status, protocol, anonymity, country and latency for every line.

Our free proxy checker after a real run of five public entries from the HProxy free list: three working and two dead, with protocol, anonymity, city, network and latency per line.
Captured on 16 September 2026 on hproxy.com/proxy-checker, with five entries taken from our public free list. Three answered, two were already dead, and the average was 38 ms.

Two of those five entries were dead within the same hour they were published, which is the normal life of a public entry. When a download has to finish, a paid proxy is the part that stops changing under you.

When it does not work

  • sudo apt update ignores the proxy. sudo runs the command in a minimal environment, so your exported names never arrive. Use sudo -E, or better, the apt file from step 3.
  • Only the upper-case name is set. curl ignores HTTP_PROXY for an http:// address. Use lower case.
  • The panel is set and the terminal is not proxied. They are separate settings. See the table at the top.
  • snap still downloads directly. snapd reads neither of the first two. Use the drop-in from step 4.
  • The password contains an @. In the URL form, @ separates the login from the host, so encode it as %40.

Turning it off again

Unset the names in the shell, remove what you added to ~/.bashrc and /etc/environment, delete /etc/apt/apt.conf.d/99proxy, remove the snapd drop-in and reload systemd, and set the desktop panel back to None. Each place is independent, and a forgotten one keeps sending traffic to a proxy that no longer exists.

Frequently asked questions

How do I set a proxy on Ubuntu?
Pick the place that reaches the program you care about. For this terminal, export http_proxy and https_proxy. For every login, put the same names into /etc/environment. For apt, write Acquire::http::Proxy into a file under /etc/apt/apt.conf.d/. For snap, add an Environment line to a systemd drop-in. The desktop panel under Settings, Network, Network Proxy covers desktop apps only.
Why does sudo apt update ignore my proxy?
Because sudo starts the command in a fresh environment. The sudoers manual says sudo runs the command in a minimal environment, and on our own Ubuntu 24.04.4 server sudo carried no http_proxy at all while sudo -E carried it. Either use sudo -E, or give apt its own setting, which is the version that survives a reboot.
Does the Ubuntu desktop proxy setting cover the terminal?
No. The panel writes the desktop setting, and a terminal reads environment variables instead. Canonical own proxy tool makes the same split: it writes one proxy into three separate places, an environment file, an apt file and a desktop override, because no single file covers all three.
How do I set a proxy for snap on Ubuntu?
On a desktop or server install, add Environment lines for http_proxy and https_proxy to a drop-in file under /etc/systemd/system/snapd.service.d/, then reload systemd and restart snapd. The documented snap set system proxy.http option is listed for Ubuntu Core. On our own server, snapd started with an empty environment and no proxy set at all.
Should I write http_proxy or HTTP_PROXY?
Lower case. On Ubuntu 24.04.4 we set only the upper-case HTTP_PROXY and curl went straight out, exactly like the control run with no proxy at all. With the lower-case http_proxy set to the same dead address, curl failed at once. Lower case is the spelling every tool agreed on.
How do I keep local addresses off the proxy?
Set no_proxy next to the other two, for example no_proxy=localhost,127.0.0.1,::1, so requests to your own machine do not travel to the proxy and back. Note that apt does not support no_proxy, which is why Canonical own tool skips that value on its apt backend.
How do I check that the proxy is really being used?
Run curl -s https://www.cloudflare.com/cdn-cgi/trace through the proxy and read the ip= line. If it shows the proxy address, your traffic is going through it. Our free lookup at https://hproxy.com/api/ip/ADDRESS then names the country, city and network behind it, and our free proxy checker reports status, protocol, anonymity, country and latency per line.
How do I turn the proxy off again on Ubuntu?
Unset the variables in the shell, remove the lines you added to ~/.bashrc or /etc/environment, delete the file you created under /etc/apt/apt.conf.d/, remove the snapd drop-in and reload systemd, and set the desktop panel back to None. Each place is independent, so a forgotten one keeps sending traffic to a proxy that is gone.

Proxies that don't die mid-job

Residential, ISP, datacenter and mobile, verified by the same engine that runs tens of millions of checks. They read as a real device and hold up under load. Pay as you go, and your balance never expires. $0.44/GB is the 2,000 GB+ rate; a single gigabyte is $0.50/GB, with no minimum order.

129M+ proxy checks run · 100+ countries · HTTP / HTTPS / SOCKS · re-checked every few minutes · no signup

HProxy.

Honest guides and comparisons on proxies, scraping and staying unblocked, from the team that runs the network.

RSS feed