By Leo Lin, Product Manager at FlashIP (https://www.flaship.com), Singapore. Author works on FlashIP.
You export https_proxy in ~/.bashrc, curl works, and then sudo apt update ignores it, a systemd service ignores it, and the desktop browser ignores it too. That's not a bug. Linux has no single "system proxy". Each layer reads its own settings: your shell, login sessions (PAM), sudo, the systemd service manager and the desktop. This guide sets the proxy once per layer, explains why each one is separate, and shows how to check it. proxy.example.net:8000 and USER:PASS are placeholders.
Layer 1: the variables everybody reads
Most command-line tools read the same variables: http_proxy, https_proxy, no_proxy (plus the uppercase versions) and sometimes all_proxy. Set both cases. curl, for example, reads http_proxy only in lowercase, while other tools check the uppercase names first.
export http_proxy=http://USER:PASS@proxy.example.net:8000 export https_proxy=$http_proxy export no_proxy=localhost,127.0.0.1,::1,.internal.example export HTTP_PROXY=$http_proxy HTTPS_PROXY=$https_proxy NO_PROXY=$no_proxy In ~/.bashrc this only covers interactive shells for one user. Two notes:
-
https_proxyusually still starts withhttp://. It names the protocol used to talk to the proxy, and HTTPS goes through it withCONNECT. -
no_proxymatching differs between tools. Domain suffixes such as.internal.exampleare widely supported. CIDR ranges like10.0.0.0/8are not, so list hostnames when in doubt.
Layer 2: every login session with /etc/environment
To give every user the variables at login (console, SSH, desktop), put them in /etc/environment. The pam_env module reads this file. Its man page describes it as "simple KEY=VAL pairs on separate lines":
http_proxy=http://proxy.example.net:8000 https_proxy=http://proxy.example.net:8000 no_proxy=localhost,127.0.0.1,::1 HTTP_PROXY=http://proxy.example.net:8000 HTTPS_PROXY=http://proxy.example.net:8000 NO_PROXY=localhost,127.0.0.1,::1 This is not a shell script. Don't write export and don't use $http_proxy, because nothing expands it. Changes apply at the next login, not in shells that are already open. The file is world-readable, so think twice before putting a proxy password in it. An IP-allowlisted endpoint is cleaner for machine-wide settings.
Layer 3: sudo drops your variables
The default sudoers on Debian and Ubuntu has Defaults env_reset. That runs the command with a minimal environment, and the proxy variables are not on the keep list. On a Debian 13 box with sudo 1.9.16, sudo -V (run as root) lists the preserved variables. There's no proxy entry, and https_proxy=... sudo env shows no proxy at all.
To fix it once, keep the variables with a drop-in. Always edit it through visudo so a typo can't lock you out:
sudo visudo -f /etc/sudoers.d/proxy Defaults env_keep += "http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY" sudo visudo -cf /etc/sudoers.d/proxy checks the syntax. For a one-off command, sudo --preserve-env=https_proxy,http_proxy apt update does the same without editing sudoers. Some distributions also run pam_env for sudo sessions, which re-applies /etc/environment. Don't count on it, and test with sudo env | grep -i proxy.
Layer 4: systemd services see none of the above
Services started by systemd don't come from a login shell, so they never see ~/.bashrc or /etc/environment unless the unit loads it. You have two options.
One service (usually what you want):
sudo systemctl edit myapp.service [Service] Environment="HTTPS_PROXY=http://proxy.example.net:8000" Environment="NO_PROXY=localhost,127.0.0.1" systemctl edit writes a drop-in and reloads the configuration for you. Then sudo systemctl restart myapp.service. Check it with systemctl show myapp.service -p Environment.
Every service: DefaultEnvironment= in the [Manager] section of system.conf, preferably as a drop-in, for example /etc/systemd/system.conf.d/proxy.conf:
[Manager] DefaultEnvironment="HTTPS_PROXY=http://proxy.example.net:8000" "NO_PROXY=localhost,127.0.0.1" The systemd docs describe it as a space-separated list of assignments, quoted like the example above, passed to all executed processes. Apply it with sudo systemctl daemon-reexec (or reboot), restart the services that need it, and check systemctl show-environment. Be careful here. Every daemon now sends traffic to the proxy, including ones that should never leave your network, so keep NO_PROXY complete. Per-service is usually safer.
For a quick test there is also sudo systemctl set-environment HTTPS_PROXY=.... It only affects processes started afterwards and doesn't survive a reboot.
Layer 5: the GNOME desktop
GNOME apps and anything that uses GNOME's proxy resolver read GSettings, not environment variables. The schema is org.gnome.system.proxy:
gsettings set org.gnome.system.proxy mode 'manual' gsettings set org.gnome.system.proxy.http host 'proxy.example.net' gsettings set org.gnome.system.proxy.http port 8000 gsettings set org.gnome.system.proxy.https host 'proxy.example.net' gsettings set org.gnome.system.proxy.https port 8000 gsettings set org.gnome.system.proxy ignore-hosts "['localhost', '127.0.0.0/8', '::1']" For SOCKS, set org.gnome.system.proxy.socks host and port instead. mode 'auto' together with autoconfig-url points to a PAC file, and mode 'none' turns the proxy off. These are per-user settings, so they don't affect sudo, cron or services.
A quick check per layer
env | grep -i _proxy # your shell sudo env | grep -i _proxy # sudo systemctl show myapp.service -p Environment # one service systemctl show-environment # service manager defaults gsettings get org.gnome.system.proxy mode # desktop curl -sS https://example.com -o /dev/null -w '%{http_code}\n' If a tool still goes direct, it probably has its own setting (apt, Docker, Git and npm all do). Configure that directly.
Wrapping up
There is no single Linux proxy switch, but there are only a few places to set one: shell, /etc/environment, sudoers env_keep, systemd and GSettings. Set the layers your workload actually uses, keep no_proxy accurate, and confirm each one with the checks above. Any standard HTTP or SOCKS5 endpoint works here, including FlashIP's residential, mobile, static ISP and datacenter proxies (https://www.flaship.com).

