You set a proxy in Ubuntu's settings. Firefox picked it up. Then you opened a terminal, ran sudo apt update, and it went straight out over your home connection.
Sound familiar? Linux doesn't have one proxy switch. It has several, and each program checks a different one.
The good news: setting a proxy on Linux takes about five minutes once you know which layer each app reads. On Ubuntu and Debian, that means the desktop settings, a few environment variables, and an apt config file.
There's also one tiny letter that decides whether your DNS lookups leak past a SOCKS proxy. We'll get to it. First, let's map where Linux looks.
Where does Linux actually read proxy settings?
Think of it as four layers. Each one only reaches the programs that bother to look at it.
- The desktop setting (GNOME on Ubuntu), read by most graphical apps.
- Environment variables like
http_proxy, read by terminal tools. - Config files for tools that ignore both, such as apt, wget, git and Docker.
- A wrapper like proxychains, for programs that support none of the above.
That's why "I set the proxy and it doesn't work" is so common on Linux. You set it in one layer and tested it in another.

So the real question isn't "how do I set a proxy on Linux?" It's "which program am I trying to route?" Keep that in mind and the rest of this guide gets easy.
What do you need before you start?
Grab these details from your provider's dashboard first. You'll type them more than once.
| Detail | Example | Notes |
|---|---|---|
| Host | gate.example.com | A hostname or an IP address |
| Port | 8080 | Often 8080 or 3128 for HTTP, 1080 for SOCKS |
| Protocol | HTTP or SOCKS5 | Decides which methods below will work |
| Username | user123 | Skip it if you use IP whitelisting |
| Password | s3cret | Special characters need URL encoding |
Not sure which port is which? Our guide to common proxy ports breaks them down. And if you're torn between protocols, read HTTP vs SOCKS5 proxies before you pick one.
One more check. Does your provider use a username and password, or an IP allowlist? That choice matters more on Linux than you'd think, and proxy authentication methods explains why.
Method 1: Set a proxy in Ubuntu's desktop settings
This is the easiest route, and it covers browsers and most graphical apps.
- Open Settings and go to Network.
- Click Network Proxy.
- Switch the method to Manual.
- Fill in the HTTP and HTTPS proxy host and port. Use the Socks Host field for a SOCKS proxy.
- Add local addresses to Ignore Hosts, like
localhost, 127.0.0.0/8.
Close the window and the change applies right away. No reboot needed.
Prefer the terminal? The same setting lives in gsettings:
gsettings set org.gnome.system.proxy mode 'manual'
gsettings set org.gnome.system.proxy.http host 'gate.example.com'
gsettings set org.gnome.system.proxy.http port 8080
gsettings set org.gnome.system.proxy.https host 'gate.example.com'
gsettings set org.gnome.system.proxy.https port 8080
Now the catch. The GNOME dialog has no username or password fields.
If your proxy needs a login, apps will either prompt you or fail quietly. Chrome usually asks. Many others don't. For a logged-in proxy, IP whitelisting or the methods below work better.
Desktop settings don't reach the terminal
The GNOME proxy only applies to apps that read it. curl, apt, wget and most scripts ignore it completely. That's the most common reason a "working" proxy seems to do nothing.
Using a different desktop, like KDE or Xfce? The menus differ, but the idea is the same. And for the browser alone, you can also set a proxy in Chrome or in Firefox directly.
Method 2: Route the terminal with environment variables
Most command-line tools check a handful of environment variables. Set them, and curl, pip, git and many others follow along.
export http_proxy="http://user123:s3cret@gate.example.com:8080"
export https_proxy="http://user123:s3cret@gate.example.com:8080"
export no_proxy="localhost,127.0.0.1,::1"
Notice that https_proxy still starts with http://. That's not a typo.
The scheme describes how your machine talks to the proxy, not the site you're visiting. Most proxies accept plain HTTP and then open an encrypted tunnel to the HTTPS site for you.
Lowercase or uppercase?
Set both if you want fewer surprises. Tools don't agree on which one they read.
curl, for example, ignores uppercase HTTP_PROXY on purpose, as a guard against a security bug called httpoxy. It reads lowercase http_proxy instead. Other programs only check the uppercase names.
export HTTP_PROXY="$http_proxy"
export HTTPS_PROXY="$https_proxy"
export NO_PROXY="$no_proxy"
What no_proxy is for
Without it, requests to your own machine and local network go through the proxy too. That breaks local dev servers and makes some tools hang.
List hosts and domains separated by commas. A leading dot, like .internal.lan, matches every subdomain. Support for CIDR ranges varies between tools, so list important IPs on their own.
How do you make the proxy stick after a reboot?
Exports only last for the current terminal. Close the window and they're gone.
You have two places to make them permanent, and they behave differently.
| File | Who it affects | Format |
|---|---|---|
~/.bashrc | Your user, in new bash terminals | Shell commands with export |
/etc/environment | Every user, after the next login | Plain NAME="value" lines only |
For just yourself, add the export lines to the end of ~/.bashrc, then run source ~/.bashrc.
For the whole system, edit /etc/environment with sudo:
http_proxy="http://user123:s3cret@gate.example.com:8080"
https_proxy="http://user123:s3cret@gate.example.com:8080"
no_proxy="localhost,127.0.0.1,::1"
HTTP_PROXY="http://user123:s3cret@gate.example.com:8080"
HTTPS_PROXY="http://user123:s3cret@gate.example.com:8080"
NO_PROXY="localhost,127.0.0.1,::1"
Two rules for this file. Don't write export, and don't reference other variables like $http_proxy. It isn't a shell script, so neither works.
Log out and back in for it to take effect. Opening a new terminal isn't enough.
How to turn the proxy off again
Switching back to a direct connection is just as easy, and worth knowing before you need it. Say the proxy plan runs out mid-week. Suddenly nothing in your terminal can reach the internet.
For the current terminal, clear the variables:
unset http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY
Then remove the lines from ~/.bashrc or /etc/environment so they don't come back at the next login. On the desktop, set Network Proxy back to Disabled, or run gsettings set org.gnome.system.proxy mode 'none'.
Mind who can read your password
Every user on the machine can read /etc/environment. On a shared server, keep credentials in your own ~/.bashrc or switch to IP whitelisting.
Why does sudo apt update ignore your proxy?
Remember that sudo apt update from the start? Here's what went wrong. Two separate things, actually.
First, sudo resets most environment variables by default. It's a security feature called env_reset. Depending on your sudo build, your carefully exported proxy variables may never reach the command.
You can keep them for one command with sudo -E. Or keep them for good by adding a line with sudo visudo:
Defaults env_keep += "http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY"
Second, and this is the cleaner fix, apt has its own proxy setting. It doesn't need the environment at all.
Create a small config file:
sudo nano /etc/apt/apt.conf.d/95proxies
Then add these two lines:
Acquire::http::Proxy "http://user123:s3cret@gate.example.com:8080/";
Acquire::https::Proxy "http://user123:s3cret@gate.example.com:8080/";
Save, run sudo apt update, and watch it go through the proxy. Want to undo it later? Delete the file.
The trailing semicolons matter. Leave one out and apt refuses to read the file, with an error that doesn't point at the missing character.
SOCKS5 proxies on Linux: what works and what doesn't
SOCKS5 is where Linux gets picky. Plenty of tools only speak HTTP proxy, so a SOCKS address in http_proxy often just fails.
Here's how the common tools handle it.
- curl supports SOCKS5 directly, through
--socks5-hostnameor asocks5h://URL. - git uses the same library as curl, so
socks5h://URLs work there too. - Recent apt versions accept a
socks5h://URL in their proxy setting. - wget has no SOCKS support at all.
- The GNOME desktop setting has a dedicated Socks Host field.
Now, about that tiny letter from the intro. It's the h in socks5h.
With socks5://, your machine looks up the site's address itself, then hands the IP to the proxy. Your local DNS server sees every site you visit.
With socks5h://, the hostname goes to the proxy, and the proxy does the lookup. Nothing leaks to your ISP's DNS. It also stops sites from seeing a DNS resolver in a different country from your exit IP.

curl --proxy "socks5h://user123:s3cret@gate.example.com:1080" https://api.ipify.org
Proxychains for apps with no proxy support
What about a program that ignores every setting above? That's what proxychains is for.
sudo apt install proxychains4
Open /etc/proxychains4.conf, go to the [ProxyList] section at the bottom, and replace the default line with yours:
socks5 gate.example.com 1080 user123 s3cret
Then put proxychains4 in front of any command, like proxychains4 curl https://api.ipify.org.
The catch: proxychains works by hooking into the system's network library as a program loads. Statically linked binaries, including many tools written in Go, skip that library. For those, proxychains does nothing, and you'll need the app's own proxy option.
Setting a proxy for git, wget, snap and Docker
A few everyday tools keep their own settings. Here are the ones that trip people up most.
Git
Git reads the environment variables, but you can pin a proxy to git alone:
git config --global http.proxy "http://user123:s3cret@gate.example.com:8080"
Remove it later with git config --global --unset http.proxy. This covers HTTPS remotes. SSH remotes need a different setup through your SSH config.
wget
wget reads the environment, or a ~/.wgetrc file:
use_proxy = on
http_proxy = http://user123:s3cret@gate.example.com:8080
https_proxy = http://user123:s3cret@gate.example.com:8080
Snap
Snap downloads run as a system service, so your shell variables never reach them. Ubuntu users hit this when the Snap Store hangs. Set the proxy on snap itself:
sudo snap set system proxy.http="http://gate.example.com:8080"
sudo snap set system proxy.https="http://gate.example.com:8080"
Docker
Here's one that surprises people. The Docker daemon runs docker pull, not your terminal, so your exports don't apply.
Give the daemon its own settings with a systemd drop-in file at /etc/systemd/system/docker.service.d/http-proxy.conf:
[Service]
Environment="HTTP_PROXY=http://gate.example.com:8080"
Environment="HTTPS_PROXY=http://gate.example.com:8080"
Environment="NO_PROXY=localhost,127.0.0.1"
Then reload and restart:
sudo systemctl daemon-reload
sudo systemctl restart docker
That handles image pulls. Containers that need a proxy at runtime need it passed in separately, usually as environment variables.
How do you know the proxy is actually working?
Don't trust the settings screen. Ask a website what IP it sees.
curl https://api.ipify.org
Run it once with the proxy set and once without. If both print the same IP, your traffic isn't going through the proxy.
To see which variables your shell actually has, run:
env | grep -i proxy
And for the full picture, add -v to curl. The verbose output shows whether it connected to the proxy host or to the site directly.
Quick tip
Test with curl before you blame your real app. If curl works and your app doesn't, the app is reading a different layer. Our curl proxy guide covers the flags in more depth.
One thing that won't tell you anything: ping. It uses ICMP, a different protocol that HTTP and SOCKS proxies don't carry. A ping that goes direct is normal, not a sign your setup failed.
When the proxy still won't work: the usual suspects
If the test above shows your real IP, or curl throws an error, start here. These cover most failures we see in setup questions.
| Symptom | Likely cause | Fix |
|---|---|---|
| 407 Proxy Authentication Required | Wrong or missing login | Recheck the username, password and URL format |
| Login fails with a correct password | Special characters break the URL | URL-encode them, like @ as %40 |
| Works in the terminal, not with sudo | sudo dropped the variables | Use sudo -E or apt's own config |
| Browser works, terminal doesn't | Only the desktop setting is on | Export the environment variables |
| Local dev server hangs | Local traffic goes through the proxy | Add it to no_proxy |
| Connection refused | Wrong port or protocol | Confirm HTTP vs SOCKS and the port |
The special-character problem deserves a second look. A password like p@ss:word confuses every tool, because @ and : already mean something in a proxy URL.
Encode them, and p@ss:word becomes p%40ss%3Aword. Or ask your provider for a password without symbols.
Still stuck after all that? The problem may be the proxy itself, not Linux.
A blocked or dead IP looks the same as a broken config from your side. Swapping in a fresh IP from your provider is a quick way to tell the two apart.
So, which method should you use?
Match the method to the program, not the other way round.
Browsing on the desktop? Use Ubuntu's Network Proxy setting. Working in the terminal? Export the environment variables and save them in ~/.bashrc. Updating packages? Give apt its own config file and stop fighting sudo.
And if it's a SOCKS5 proxy, use socks5h wherever you can.
Don't have a proxy yet? Compare the proxy providers we've reviewed, or start with residential vs datacenter proxies to pick the right type.
Five minutes, and you're routed.
Frequently asked questions
Open Settings, go to Network, click Network Proxy and choose Manual, then enter the host and port. That covers most desktop apps. Terminal tools need the http_proxy and https_proxy environment variables as well.
Export http_proxy and https_proxy with your proxy URL, for example http://user:pass@host:port. Add the same lines to ~/.bashrc to keep them after you close the terminal, and set no_proxy for local addresses.
Because sudo resets most environment variables, and apt can't see the proxy you exported. The cleanest fix is a file in /etc/apt/apt.conf.d/ with Acquire::http::Proxy and Acquire::https::Proxy lines.
With socks5h, the proxy resolves hostnames instead of your machine, so DNS lookups don't leak to your local resolver. Plain socks5 sends only the resolved IP to the proxy and does the lookup locally.
Run curl https://api.ipify.org with and without the proxy set. If both show the same IP, traffic isn't going through the proxy. Note that ping never uses HTTP or SOCKS proxies.
Run unset on the proxy variables, then delete the lines from ~/.bashrc or /etc/environment. On the desktop, set Network Proxy back to Disabled, and delete any apt proxy file you created.


