Skip to main content
Proxy Basics

How to Set Proxy in Mac Terminal [2026 Guide]

6 min read

How to Set Proxy in Mac Terminal: A Complete 2025 Guide

Configuring a proxy server via the Mac Terminal is a critical skill for network engineers, sysadmins, and developers. While macOS provides a graphical interface for network settings, the Terminal offers granular control, allowing for scriptable configuration and troubleshooting.

In 2025, with the rise of automated data scraping and secure remote development, understanding how to route traffic through a SOCKS or HTTP proxy directly from the command line is more relevant than ever. This guide covers temporary and permanent configurations, authentication, and tool-specific setups.

---

Understanding Terminal Proxy Variables

When you set a proxy in the Terminal, you are essentially exporting Environment Variables. These variables store information that the shell and running applications (like curl, git, python, or wget) read to determine how to connect to the internet.

The Core Variables

There are four primary variables you need to know:

| Variable | Usage | Protocol | | :--- | :--- | :--- | | http_proxy | Routes HTTP traffic | HTTP / HTTPS | | https_proxy | Routes HTTPS traffic (encrypted) | HTTPS | | all_proxy | Routes all traffic if no specific protocol is set | SOCKS4 / SOCKS5 / HTTP | | no_proxy | Comma-separated list of hostnames/IPs to exclude | N/A |

> Note: Unix-based systems like macOS are case-sensitive regarding variable names, though many modern tools accept both lowercase (http_proxy) and uppercase (HTTP_PROXY). For best practices, use lowercase.

---

Method 1: Temporary Session Configuration

This is the safest method for testing. The proxy settings will vanish immediately when you close the Terminal window or restart the shell.

1. Basic Setup (No Auth)

Open your terminal (Zsh is the default on modern macOS) and type:

Syntax

export http_proxy="http://proxy_ip:port" export https_proxy="http://proxy_ip:port"

Example

export http_proxy="http://192.168.1.50:8080" export https_proxy="http://192.168.1.50:8080"

2. Authenticated Proxy

If your corporate or residential proxy requires a username and password:

Syntax

export http_proxy="http://username:password@proxy_ip:port"

Example

export http_proxy="http://admin:secretpass@10.0.0.5:3128" export https_proxy="http://admin:secretpass@10.0.0.5:3128"

> Security Warning: Commands typed in the terminal are saved in your shell history (~/.zsh_history). If you type a password in the command line, it is saved in plain text. For production environments, use a .netrc file or tool-specific config files to handle credentials securely.

3. Excluding Local Addresses

To prevent local traffic (like internal Intranet sites or Docker containers) from going through the proxy, use the no_proxy variable:

export no_proxy="localhost,127.0.0.1,*.local,192.168.*"

---

Method 2: Permanent Configuration (macOS 2025)

To persist proxy settings across reboots, you must add the export commands to your shell's configuration file.

Identifying Your Shell

macOS switched from Bash to Zsh as the default shell in macOS Catalina (10.15). First, check which shell you are using:

echo $SHELL

  • Output /bin/zsh: You need to edit ~/.zshrc.
  • Output /bin/bash: You need to edit ~/.bash_profile or ~/.profile.

Editing the Config File

1. Open the file in a text editor like Nano or Vim:

    nano ~/.zshrc

2. Scroll to the bottom and add your proxy lines:

    # Proxy Settings

export http_proxy="http://192.168.1.50:8080" export https_proxy="http://192.168.1.50:8080" export no_proxy="localhost,127.0.0.1"

3. Save and exit (Ctrl+O, Enter, Ctrl+X). 4. Apply the changes immediately without restarting:

    source ~/.zshrc

---

Method 3: The networksetup Command (System Level)

The export method only affects the command line. If you want to configure the actual macOS network adapter settings via the Terminal—so that browsers and other apps also use the proxy—you use the networksetup tool.

This is often used in scripting (e.g., Jamf scripts) for enterprise device management.

1. List Network Services

First, find the exact name of the network interface you want to configure (e.g., Wi-Fi, Ethernet).

networksetup -listallnetworkservices

2. Set the Web Proxy

Syntax

sudo networksetup -setwebproxy

Example for Wi-Fi

sudo networksetup -setwebproxy Wi-Fi 192.168.1.50 8080 on

3. Set the Secure Web Proxy

sudo networksetup -setsecurewebproxy Wi-Fi 192.168.1.50 8080 on

4. Set Proxy Bypass Hosts

sudo networksetup -setproxybypassdomains Wi-Fi "localhost" "*.local"

How to Remove Proxy Settings (Unset)

If you need to disable the proxy via terminal:

Turn off the proxy state

sudo networksetup -setwebproxystate Wi-Fi off sudo networksetup -setsecurewebproxystate Wi-Fi off

Or unset environment variables

unset http_proxy unset https_proxy

---

Application-Specific Configurations

Some Python or CLI tools ignore system environment variables and require specific configuration.

Python

The requests library respects environment variables automatically. However, you can also configure proxies in your code:

import requests

proxies = { 'http': 'http://192.168.1.50:8080', 'https': 'http://192.168.1.50:8080', }

Using a context manager is best practice for scraping

try: response = requests.get('https://api.ipify.org?format=json', proxies=proxies, timeout=5) print(response.json()) except requests.exceptions.ProxyError as e: print(f"Proxy Error: {e}")

Git

If you are pushing to a repository (like GitHub) from behind a corporate firewall:

Global config

sudo git config --global http.proxy http://192.168.1.50:8080

Or per URL

sudo git config --global http.https://github.com.proxy http://192.168.1.50:8080

SSH (SOCKS Proxy)

For SSH tunneling (Dynamic Port Forwarding), you use the -D flag:

Creates a SOCKS proxy on local port 9999

ssh -D 9999 user@remote-server.com

Then you can set your all_proxy variable to use this tunnel

export all_proxy="socks5://127.0.0.1:9999"

---

Verifying Your Connection

Always verify that the traffic is actually being routed through the proxy.

Check your public IP (should return proxy IP, not your home IP)

curl https://ipinfo.io/ip

Alternatively, for a verbose output showing the handshake:

curl -v https://www.google.com

Look for Proxy-Connection: keep-alive in the output headers to confirm the proxy is being used.

---

Troubleshooting Common Issues

1. "curl: (56) Failure in receiving network data"

This usually means the proxy is refusing connections. Check if the IP and port are correct and if the proxy allows your machine's IP.

2. Variable Not Persisting

Ensure you are editing the correct dotfile (.zshrc vs .bash_profile) and that you ran the source command. Also, verify your shell hasn't reverted to a default system shell in macOS settings.

3. DNS Leaks

Sometimes the connection goes through the proxy, but DNS requests do not. This is common with misconfigured no_proxy entries. Ensure your proxy handles DNS or use a tool that forces DNS over the proxy.

Share: