skip to content
afterblue.
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 ~/.zshrc so 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:

Terminal window
networksetup -listallnetworkservices

Example output:

An asterisk (*) denotes that a network service is disabled.
Wi-Fi
Ethernet
Thunderbolt Bridge

Check 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:

Terminal window
env | grep -i proxy

If this returns nothing, CLI tools are routing traffic directly — regardless of what is configured in System Settings.

You can also check individual variables:

Terminal window
echo $http_proxy
echo $https_proxy
echo $all_proxy

macOS System Settings

Inspect what is configured in System Settings → Wi-Fi → Details → Proxies:

Terminal window
# HTTP proxy
networksetup -getwebproxy "Wi-Fi"
# HTTPS proxy
networksetup -getsecurewebproxy "Wi-Fi"
# SOCKS5 proxy
networksetup -getsocksfirewallproxy "Wi-Fi"

Each command produces output like this:

Enabled: Yes
Server: 127.0.0.1
Port: 7890
Authenticated Proxy Enabled: 0

If 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:

Terminal window
# HTTP proxy
export http_proxy="http://HOST:PORT"
export HTTP_PROXY="$http_proxy"
# HTTPS proxy
export https_proxy="http://HOST:PORT"
export HTTPS_PROXY="$https_proxy"
# SOCKS5 proxy
export all_proxy="socks5://HOST:PORT"
export ALL_PROXY="$all_proxy"

Unset Proxy Variables

To disable the proxy mid-session without closing the terminal:

Terminal window
unset http_proxy HTTP_PROXY
unset https_proxy HTTPS_PROXY
unset all_proxy ALL_PROXY

Auto-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:

Terminal window
_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"
fi

Solution 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:

Terminal window
# ── 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"

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:

Terminal window
# ── 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:

Terminal window
source ~/.zshrc

Verification

Check Environment Variables

Confirm all six proxy variables are present in the current environment:

Terminal window
env | grep -i proxy

Expected output:

http_proxy=http://HOST:PORT
HTTP_PROXY=http://HOST:PORT
https_proxy=http://HOST:PORT
HTTPS_PROXY=http://HOST:PORT
all_proxy=socks5://HOST:PORT
ALL_PROXY=socks5://HOST:PORT

Test Connectivity Through the Proxy

Send a request through the proxy and inspect the reported origin IP:

Terminal window
curl -v https://httpbin.org/ip

The 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