macOS Terminal traffic bypassing your proxy? Turn on TUN mode

December 25, 2025

How it started

Today I wanted to install nvm on my Mac, but the installation script hung:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

It just couldn't connect to GitHub. Strange. Didn't I already have V2rayN running?

I tried a few more times. The connection kept timing out. That's when I realized my terminal traffic wasn't going through the proxy at all.

Why the terminal bypasses the proxy

V2rayN defaults to system proxy mode, which changes the system's proxy settings. But commands run in Terminal or iTerm2 don't pick up those settings. They look for environment variables such as http_proxy.

That explains why the browser could reach blocked sites while curl, wget, and npm in my terminal were all connecting directly.

Turning on TUN mode

After some tinkering, I found TUN mode in V2rayN. It creates a virtual network interface that takes over network traffic at the system level. Whichever app you're using, its traffic goes through the proxy.

Here's how I enabled it:

  1. Click the V2rayN menu bar icon.
  2. Go to Settings → Tun Mode Settings.
  3. Check “Enable Tun Mode.”
  4. Enter your administrator password when prompted the first time.
  5. Restart V2rayN.

I tried again:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

It downloaded instantly. Much better.

Checking that the proxy works

If you're unsure, check your outgoing IP address:

curl ipinfo.io

If the result shows your proxy node's IP address instead of your usual one, it's working.

Another option: Set environment variables manually

If you don't want TUN mode, since you don't always need a system-wide proxy, you can configure the terminal manually:

export http_proxy=http://127.0.0.1:10809
export https_proxy=http://127.0.0.1:10809
export all_proxy=socks5://127.0.0.1:10808

The ports depend on your V2rayN configuration. Common defaults are 10809 for HTTP and 10808 for SOCKS5.

To save yourself some typing, add a switch to ~/.zshrc:

proxy_on() {
    export http_proxy=http://127.0.0.1:10809
    export https_proxy=http://127.0.0.1:10809
    export all_proxy=socks5://127.0.0.1:10808
    echo "Proxy ON"
}

proxy_off() {
    unset http_proxy https_proxy all_proxy
    echo "Proxy OFF"
}

Then use proxy_on to turn it on and proxy_off to turn it off.

Summary

  • It's normal for terminal commands to bypass the system proxy.
  • TUN mode is the easy option if you want everything to use the proxy.
  • Use environment variables if you want more control.

I leave TUN mode on now. It's one less thing to think about every time I install something.

© 2025 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2025-12-25). macOS Terminal traffic bypassing your proxy? Turn on TUN mode. https://caiborui.com/blog/2025-12-25-zh-v2rayn-tun-mode-terminal-proxy-entrans

@misc{borui2025-5dddfda1,
  author = {borui},
  title = {{macOS Terminal traffic bypassing your proxy? Turn on TUN mode}},
  year = {2025},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2025-12-25-zh-v2rayn-tun-mode-terminal-proxy-entrans}
}