Set a proxy from the command line with ProxyField
- Export
http_proxy,https_proxyandHTTPS_PROXYwith the proxy URL from the table. - Set
no_proxyandNO_PROXYfor local hosts such aslocalhost,127.0.0.1. - For SOCKS5, export
ALL_PROXYwithsocks5h://and unset the HTTP variables, which win over it. - Add the lines to
~/.zshrcor~/.bashrcto keep them, andsourcethe file. - Run
curl https://api.ipify.org: it prints the proxy's exit IP, not yours.
The HTTP form in Bash or zsh, then one request that uses it.
export https_proxy="http://<login>-country-us-city-new_york:<password>@gate.proxyfield.io:7000"
curl https://api.ipify.orgcurl's own rules for these variables are in its manual's ENVIRONMENT section: curl man page (curl project).
On this page 9 sections
Set proxy environment variables on Linux and macOS
Set the variables in your shell, then run your commands as usual:
export http_proxy="http://<login>-country-us-city-new_york:<password>@gate.proxyfield.io:7000"
export https_proxy="$http_proxy"
export HTTPS_PROXY="$http_proxy"
export no_proxy="localhost,127.0.0.1,::1,.local"
export NO_PROXY="$no_proxy"
curl https://api.ipify.org # prints the proxy's exit IP, not yoursSOCKS5 instead of HTTP. ProxyField serves SOCKS5 on the same host and port, with the same login:
export ALL_PROXY="socks5h://<login>-country-us-city-new_york:<password>@gate.proxyfield.io:7000"
export all_proxy="$ALL_PROXY"
curl https://api.ipify.org # curl uses ALL_PROXY when no protocol-specific variable is setsocks5h://resolves the site's hostname through the proxy;socks5://resolves it on your machine, so your DNS lookups stay local. Usesocks5h://unless you have a reason not to; more in SOCKS5 vs HTTP proxy.- A protocol-specific variable beats
ALL_PROXY: ifhttps_proxyis also set, curl uses it forhttps://sites and ignoresALL_PROXY. Unset the HTTP variables when you switch to SOCKS. - Not every tool speaks SOCKS: curl does, wget does not, and Python requests needs the SOCKS extra (
pip install "requests[socks]").
Which variable a tool reads depends on the tool:
| Variable | What it covers | Notes |
|---|---|---|
http_proxy | requests to http:// sites | curl reads only the lowercase name for HTTP, as protection against the "httpoxy" header attack |
https_proxy / HTTPS_PROXY | requests to https:// sites | most tools read either case |
all_proxy / ALL_PROXY | every protocol without its own variable | often used for SOCKS: socks5h://<login>:<password>@host: |
no_proxy / NO_PROXY | hosts that skip the proxy | comma-separated; .example.com covers subdomains; * alone skips the proxy for every host |
Setting both cases avoids surprises; where both are set, curl checks the lowercase name first. The curl rules are in its manual's ENVIRONMENT section (curl man page).
Which tools read them. curl, wget, git, pip, Python requests and Go's default HTTP client read the proxy variables. Node.js's built-in http module and fetch do not by default: a Node.js program needs a proxy agent or its own proxy setting.
Run one command through a proxy without exporting anything:
https_proxy="http://<login>-country-us-city-new_york:<password>@gate.proxyfield.io:7000" curl https://api.ipify.orgFor programs that ignore the variables entirely, proxychains-style wrappers force their connections through a proxy; see the Linux proxy setup guide.
Make the variables permanent on Linux and macOS
The variables live only in the current shell. To keep them, add the export lines to your shell's startup file:
| System | Default shell | File | Reload |
|---|---|---|---|
| macOS (Catalina and later) | zsh | ~/.zshrc | source ~/.zshrc |
| Linux, interactive Bash | bash | ~/.bashrc | source ~/.bashrc |
| Linux, login shells (SSH, console) | bash or sh | ~/.profile (or ~/.bash_profile) | log in again |
| Linux, every user | any | /etc/environment (plain NAME=value lines, no export) | log in again |
Terminal windows that were already open do not see the change until you source the file in them. The password is now stored in that file, so keep it readable only by you (chmod 600 ~/.zshrc), or use the IP allowlist instead of a password in the URL. Mac-wide settings for apps other than the terminal: macOS proxy setup.
sudo usually drops them. On most distributions sudo resets the environment, so sudo apt update ignores your exports unless the sudoers file keeps the proxy variables. Use sudo -E to keep them for one command, or give apt its own setting (below).
Set a proxy for apt
apt reads its proxy from a file in /etc/apt/apt.conf.d/, so it works under sudo:
sudo tee /etc/apt/apt.conf.d/95proxy >/dev/null <<'EOF'
Acquire::http::Proxy "http://<login>:<password>@gate.proxyfield.io:7000/";
Acquire::https::Proxy "http://<login>:<password>@gate.proxyfield.io:7000/";
EOF
sudo apt updateThe Acquire::http::Proxy option is described in the apt-transport-http manual. Delete the file to stop. Package downloads are large, and every byte through a residential proxy counts as traffic, so route apt through a proxy only when the network requires it.
Tools with their own proxy settings
| Tool | Command | Undo |
|---|---|---|
| git | git config --global http. | git config --global --unset http. |
| npm | npm config set proxy http://<login>:<password>@gate. and npm config set https-proxy <same URL> | npm config delete proxy, npm config delete https-proxy |
| pip | pip install --proxy http://<login>:<password>@gate. | omit the flag |
| wget | reads http_proxy and https_proxy; -e use_ for one run | wget guide |
| curl | -x <URL> for one request, --noproxy '*' to skip the proxy | curl guide |
Special characters in the password (@, :, /, #) must be percent-encoded in these URLs; proxy format shows how.
Set a proxy in Windows Command Prompt
:: this window only
set HTTPS_PROXY=http://<login>-country-us-city-new_york:<password>@gate.proxyfield.io:7000
set HTTP_PROXY=%HTTPS_PROXY%
curl https://api.ipify.org
:: saved for new windows (setx does not change the current one)
setx HTTPS_PROXY "http://<login>-country-us-city-new_york:<password>@gate.proxyfield.io:7000"curl.exe, Python, Git and pip read these variables; Node.js does not by default. Windows itself does not: the system proxy is set in Settings, and the proxy for Windows services is set with netsh winhttp, which takes no login, so pair it with ProxyField's IP allowlist and use the port you set up in the dashboard as <port>:
netsh winhttp set proxy proxy-server="gate.proxyfield.io:<port>" bypass-list="<local>"
netsh winhttp show proxy
netsh winhttp reset proxyThe command reference is on Microsoft Learn: netsh winhttp. The Windows proxy setup guide covers the Settings side and setting a proxy from the Command Prompt step by step.
Set a proxy in PowerShell
Invoke-WebRequest and Invoke-RestMethod take the proxy and its login as parameters. Build the credential from environment variables instead of typing the password into the script:
$pass = ConvertTo-SecureString $env:PROXY_PASS -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($env:PROXY_USER, $pass)
Invoke-RestMethod -Uri "https://api.ipify.org" -Proxy "http://gate.proxyfield.io:7000" -ProxyCredential $cred$env:PROXY_USER holds a username such as <login>-country-us-city-new_york. In PowerShell 7, $env:HTTPS_PROXY = "http://<login>:<password>@gate.proxyfield.io:7000" also works for these cmdlets, because .NET reads the proxy variables (Microsoft Learn: HttpClient.DefaultProxy). To make every Invoke-WebRequest in a session use the authenticated proxy, set it once as a default parameter value: $PSDefaultParameterValues["Invoke-WebRequest:Proxy"] = "http://gate.proxyfield.io:7000" and $PSDefaultParameterValues["Invoke-WebRequest:ProxyCredential"] = $cred, with the same two lines for Invoke-RestMethod (Microsoft Learn: about_Parameters_Default_Values); the other session-wide options are on PowerShell proxy setup.
Can you ping through a proxy?
No. ping sends ICMP packets, and HTTP and SOCKS proxies relay TCP connections (SOCKS5 also UDP), not ICMP, so ping always goes out directly from your machine. To test a proxy from the command line, make a real request through it and time it:
curl -x gate.proxyfield.io:7000 -U "<login>-country-us-city-new_york:<password>" \
-o /dev/null -s -w "connect %{time_connect}s, total %{time_total}s, HTTP %{http_code}\n" \
https://api.ipify.orgtime_connect is the time to reach the proxy, and time_total includes the trip through the exit IP to the site. Run it a few times; a residential exit adds the latency of a home connection.
Check that the command line uses the proxy
curl https://api.ipify.orgprints the exit IP. It differs from your own when the proxy is in use.curl -v https://api.ipify.org 2>&1 | grep -i proxyshows whether curl picked up a proxy variable.env | grep -i _proxylists what is set.
To switch everything off again, see how to turn off a proxy. ProxyField proxies run on HTTP, HTTPS and SOCKS5 with unlimited concurrent threads, so one exported variable can serve many parallel commands; proxy authentication covers using the IP allowlist instead of a password in the URL.
Set a Proxy From the Command Line FAQ
How do I set an HTTP or SOCKS5 proxy with environment variables for terminal commands on Linux and macOS?
ProxyField serves HTTP and SOCKS5 on the same gateway, gate.proxyfield.io:7000, so the two forms are export https_proxy="http://<login>:<password>@gate.proxyfield.io:7000" (with http_proxy set to the same value) and export ALL_PROXY="socks5h://<login>:<password>@gate.proxyfield.io:7000". The syntax is the same in Bash on Linux and zsh on macOS; add the lines to ~/.bashrc or ~/.zshrc to keep them, and run source on the file. A protocol-specific variable beats ALL_PROXY, and socks5h:// sends DNS lookups through the proxy too; residential traffic costs from $1.95/GB.
What is the command to set up an HTTP proxy?
ProxyField residential proxies cost from $1.95/GB, and the command to set up an HTTP proxy for them on Linux and macOS is export https_proxy="http://<login>:<password>@gate.proxyfield.io:7000" (plus http_proxy with the same value). In Windows Command Prompt it is set HTTPS_PROXY= with the same URL. Tools that read these variables, such as curl, wget, git, pip and Python requests, then send every request through the gateway.
Can I ping through a proxy?
No. ping uses ICMP, and HTTP and SOCKS proxies relay TCP connections, so ping always goes out directly. To test a proxy, time a real request through it with curl's -w "%{time_connect} %{time_total}".
How do I enable an HTTP proxy?
For the whole device, enter the server and port in the system proxy settings; for command-line tools, set the http_proxy and https_proxy variables; for one program, use its own proxy option. Each covers only the apps that read it.
How do I set a proxy for an installer?
Give the installer its own setting: an Acquire::http::Proxy line in /etc/apt/apt.conf.d/ for apt, --proxy for pip, npm config set proxy for npm. Graphical installers on Windows and macOS usually follow the system proxy.
What does "proxy from env" mean?
It means a program takes its proxy from the environment variables (HTTP_PROXY, HTTPS_PROXY, NO_PROXY) instead of its own settings. Go's http.ProxyFromEnvironment and the default behavior of Python requests are examples.
How do I set a SOCKS5 proxy environment variable?
Use ALL_PROXY (or all_proxy) with a SOCKS URL, for example export ALL_PROXY="socks5h://<login>:<password>@gate.proxyfield.io:7000", and unset http_proxy and https_proxy, which would win over it. curl honors it; wget has no SOCKS support, and Python requests needs requests[socks] installed.
What's the difference between HTTP_PROXY and HTTPS_PROXY?
HTTP_PROXY is used for requests to http:// addresses and HTTPS_PROXY for https:// addresses; the names describe the target site, not the proxy. Both usually hold the same http:// proxy URL.
Should a proxy username and password be placed inside HTTP_PROXY?
It works, and it is the usual way for command-line tools, but the password is then visible to anything that can read your environment or shell profile. On shared machines and CI systems, prefer a secret store, or an IP allowlist so the URL needs no password.
Does netsh winhttp change my browser's proxy?
No. netsh winhttp sets the proxy for Windows services that use WinHTTP; browsers use the per-user proxy from Settings > Network & internet > Proxy. Change that one for Chrome and Edge.
Show 2 more questionsShow fewer questions
Do environment variables apply to all terminal commands?
Only to commands started from that shell after you set them, and only to programs that read them. sudo usually drops them unless you use sudo -E, and some programs, such as Node.js's built-in fetch, ignore them by default.
Does Go read HTTP_PROXY and HTTPS_PROXY automatically?
Yes. Go's default HTTP transport uses http.ProxyFromEnvironment, which reads HTTP_PROXY, HTTPS_PROXY and NO_PROXY in upper or lower case. A custom transport needs its Proxy field set to do the same.