Terminal Proxy Setup on macOS Sequoia
/ 7 min read
Table of Contents
Overview
macOS stores proxy settings in System Settings → Wi-Fi → Details → Proxies, but Terminal.app does not inherit them automatically. Every command-line tool — curl, git, brew, npm, pip, and more — looks for proxy configuration in environment variables, not the GUI settings panel. Until those variables are set, your terminal sessions route traffic directly, bypassing any configured proxy entirely.
This post covers the following:
- Check current proxy settings — inspect both system-level and shell-level proxy state.
- Solution 1 — Temporary: export variables for the current shell session only. Closing the tab or window clears them automatically.
- Solution 2 — Permanent: add the exports (or a helper function) to
~/.zshrcso every new session picks them up automatically.
Prerequisites — Find Your Network Service Name
Several commands below accept a network service name (e.g. "Wi-Fi") as an argument. Before using them, confirm the exact name of your active network service:
networksetup -listallnetworkservicesExample output:
An asterisk (*) denotes that a network service is disabled.Wi-FiEthernetThunderbolt BridgeCheck Current Proxy Settings
There are two separate layers to inspect: the shell environment variables (what CLI tools actually see) and the macOS System Settings (what GUI apps and networksetup report).
Shell Environment Variables
Check what proxy variables are currently exported in the active session:
env | grep -i proxyIf this returns nothing, CLI tools are routing traffic directly — regardless of what is configured in System Settings.
You can also check individual variables:
echo $http_proxyecho $https_proxyecho $all_proxymacOS System Settings
Inspect what is configured in System Settings → Wi-Fi → Details → Proxies:
# HTTP proxynetworksetup -getwebproxy "Wi-Fi"
# HTTPS proxynetworksetup -getsecurewebproxy "Wi-Fi"
# SOCKS5 proxynetworksetup -getsocksfirewallproxy "Wi-Fi"Each command produces output like this:
Enabled: YesServer: 127.0.0.1Port: 7890Authenticated Proxy Enabled: 0If Enabled: No, that proxy type is turned off at the system level even if a server address is filled in.
Solution 1 — Temporary (Current Session Only)
These export commands live only for the duration of the active shell session. Closing the terminal tab or window clears them automatically — no cleanup required.
Set Proxy Variables
Replace HOST and PORT with your proxy server’s address and port number:
# HTTP proxyexport http_proxy="http://HOST:PORT"export HTTP_PROXY="$http_proxy"
# HTTPS proxyexport https_proxy="http://HOST:PORT"export HTTPS_PROXY="$https_proxy"
# SOCKS5 proxyexport all_proxy="socks5://HOST:PORT"export ALL_PROXY="$all_proxy"Unset Proxy Variables
To disable the proxy mid-session without closing the terminal:
unset http_proxy HTTP_PROXYunset https_proxy HTTPS_PROXYunset all_proxy ALL_PROXYAuto-read from macOS System Settings
The following snippet reads all three proxy types and exports them — but only if they are enabled in System Settings. Set _SVC to match your active network service name before running:
_SVC="Wi-Fi"
# ── HTTP proxy ──────────────────────────────────────────────_HTTP=$(networksetup -getwebproxy "$_SVC" 2>/dev/null)if [ "$(echo "$_HTTP" | awk '/^Enabled:/{print $2}')" = "Yes" ]; then _HOST=$(echo "$_HTTP" | awk '/^Server:/{print $2}') _PORT=$(echo "$_HTTP" | awk '/^Port:/{print $2}') export http_proxy="http://$_HOST:$_PORT" export HTTP_PROXY="$http_proxy"fi
# ── HTTPS proxy ─────────────────────────────────────────────_HTTPS=$(networksetup -getsecurewebproxy "$_SVC" 2>/dev/null)if [ "$(echo "$_HTTPS" | awk '/^Enabled:/{print $2}')" = "Yes" ]; then _HOST=$(echo "$_HTTPS" | awk '/^Server:/{print $2}') _PORT=$(echo "$_HTTPS" | awk '/^Port:/{print $2}') export https_proxy="http://$_HOST:$_PORT" export HTTPS_PROXY="$https_proxy"fi
# ── SOCKS5 proxy ────────────────────────────────────────────_SOCKS=$(networksetup -getsocksfirewallproxy "$_SVC" 2>/dev/null)if [ "$(echo "$_SOCKS" | awk '/^Enabled:/{print $2}')" = "Yes" ]; then _HOST=$(echo "$_SOCKS" | awk '/^Server:/{print $2}') _PORT=$(echo "$_SOCKS" | awk '/^Port:/{print $2}') export all_proxy="socks5://$_HOST:$_PORT" export ALL_PROXY="$all_proxy"fiSolution 2 — Permanent (Persists Across Sessions)
Adding proxy configuration to ~/.zshrc ensures it is sourced automatically by zsh on every new terminal session. Both options below produce the same end result; choose whichever fits your workflow.
Option A — Hardcoded Values
Simple and straightforward. Ideal when your proxy settings rarely change.
Append the following block to ~/.zshrc, replacing HOST and PORT with your actual values:
# ── Proxy Settings ─────────────────────────────────────────export http_proxy="http://HOST:PORT"export HTTP_PROXY="$http_proxy"
export https_proxy="http://HOST:PORT"export HTTPS_PROXY="$https_proxy"
export all_proxy="socks5://HOST:PORT"export ALL_PROXY="$all_proxy"Option B — Auto-read from macOS System Settings (Recommended)
Best suited when proxy settings change frequently or differ across network environments. The function reads live from macOS System Settings every time a new shell starts, so it always reflects the current configuration without any manual edits.
Append the following to ~/.zshrc:
# ── Proxy Settings ─────────────────────────────────────────_load_system_proxy() { local svc="${1:-Wi-Fi}"
# HTTP proxy local _http _http=$(networksetup -getwebproxy "$svc" 2>/dev/null) if [ "$(echo "$_http" | awk '/^Enabled:/{print $2}')" = "Yes" ]; then local _host _port _host=$(echo "$_http" | awk '/^Server:/{print $2}') _port=$(echo "$_http" | awk '/^Port:/{print $2}') export http_proxy="http://$_host:$_port" export HTTP_PROXY="$http_proxy" fi
# HTTPS proxy local _https _https=$(networksetup -getsecurewebproxy "$svc" 2>/dev/null) if [ "$(echo "$_https" | awk '/^Enabled:/{print $2}')" = "Yes" ]; then local _host _port _host=$(echo "$_https" | awk '/^Server:/{print $2}') _port=$(echo "$_https" | awk '/^Port:/{print $2}') export https_proxy="http://$_host:$_port" export HTTPS_PROXY="$https_proxy" fi
# SOCKS5 proxy local _socks _socks=$(networksetup -getsocksfirewallproxy "$svc" 2>/dev/null) if [ "$(echo "$_socks" | awk '/^Enabled:/{print $2}')" = "Yes" ]; then local _host _port _host=$(echo "$_socks" | awk '/^Server:/{print $2}') _port=$(echo "$_socks" | awk '/^Port:/{print $2}') export all_proxy="socks5://$_host:$_port" export ALL_PROXY="$all_proxy" fi}
_load_system_proxy "Wi-Fi"Apply the Changes
After editing ~/.zshrc, reload it in the current session to apply immediately — without opening a new terminal window:
source ~/.zshrcVerification
Check Environment Variables
Confirm all six proxy variables are present in the current environment:
env | grep -i proxyExpected output:
http_proxy=http://HOST:PORTHTTP_PROXY=http://HOST:PORThttps_proxy=http://HOST:PORTHTTPS_PROXY=http://HOST:PORTall_proxy=socks5://HOST:PORTALL_PROXY=socks5://HOST:PORTTest Connectivity Through the Proxy
Send a request through the proxy and inspect the reported origin IP:
curl -v https://httpbin.org/ipThe origin field in the JSON response should show the proxy server’s IP address, not your machine’s real public IP. If it shows your real IP, the proxy variables are not being picked up.
Quick Reference
| Goal | Command | Notes |
|---|---|---|
| List network services | networksetup -listallnetworkservices |
Find the exact service name |
| Check shell proxy env vars | env | grep -i proxy |
What CLI tools currently see |
| Check system HTTP proxy | networksetup -getwebproxy "Wi-Fi" |
Shows host, port, enabled status |
| Check system HTTPS proxy | networksetup -getsecurewebproxy "Wi-Fi" |
— |
| Check system SOCKS5 proxy | networksetup -getsocksfirewallproxy "Wi-Fi" |
— |
| Bypass proxy for one command | curl -x "" https://example.com |
Ignores proxy env vars for that call |
| Temporarily disable in session | unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY all_proxy ALL_PROXY |
Reverts until session ends |
| Reload zshrc | source ~/.zshrc |
Apply permanent changes immediately |