FlClash Get FlClash

Send the terminal, Git, Docker and WSL through FlClash

The browser works but git clone hangs. Every tool reads its proxy from a different place. Here they all are.

Published , about 4 min

The system proxy is for programs like browsers. Terminal tools have their own rules: some read environment variables, some their own config, and Docker is another world.

Why the browser and not the terminal? System proxy is a line in settings that programs may read. Browsers do, most command-line tools do not. FlClash is not broken; nobody told the tool.

Two ways

The easy way is TUN. It captures everything and you can skip the rest.

If you don't want TUN, or a work PC won't give you admin rights, set each tool. Ports below use FlClash's default 7890. Change them if yours differs.

Two switches at the bottom right: System proxy and TUN. With TUN on, the terminal needs nothing else.
Two switches at the bottom right: System proxy and TUN. With TUN on, the terminal needs nothing else. Image: FlClash, GPL-3.0

The terminal itself

macOS and Linux:

export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
export all_proxy=socks5h://127.0.0.1:7890
export no_proxy=localhost,127.0.0.1,192.168.0.0/16

PowerShell:

$env:HTTPS_PROXY = 'http://127.0.0.1:7890'
$env:HTTP_PROXY = 'http://127.0.0.1:7890'

Both last until the window closes. To keep them, put them in ~/.zshrc, ~/.bashrc or PowerShell's $PROFILE. When FlClash is off, commands will then fail to reach 7890, so many people wrap this in a function they call when needed.

The h in socks5h matters: it lets the proxy resolve names. With plain socks5 they're resolved locally and can come back wrong.

Git

For HTTPS repositories:

git config --global http.proxy http://127.0.0.1:7890
git config --global --unset http.proxy

The second line undoes it. SSH repositories ([email protected]:) ignore this and need ~/.ssh/config:

Host github.com
  HostName ssh.github.com
  Port 443
  ProxyCommand nc -X 5 -x 127.0.0.1:7890 %h %p

It also moves to port 443, since some networks block 22. Windows has no nc; use Git's own connect -S 127.0.0.1:7890 %h %p.

npm and pip

npm config set proxy http://127.0.0.1:7890
npm config set https-proxy http://127.0.0.1:7890
pip install -U pip --proxy http://127.0.0.1:7890

If you use a nearby mirror, skip the proxy. It only adds a detour.

Docker

Three things get mixed up in most guides, which is why following half of one doesn't work.

What you're doingWhere to set it
Pulling images, docker pullThe daemon's proxy
Downloads during docker buildBuild arguments or client config
A running container going onlineThe container's environment

Pulling is the usual one. Edit /etc/docker/daemon.json and restart Docker:

{
  "proxies": {
    "http-proxy": "http://127.0.0.1:7890",
    "https-proxy": "http://127.0.0.1:7890",
    "no-proxy": "localhost,127.0.0.0/8"
  }
}

In Docker Desktop, fill in Resources › Proxies instead. Details are in the Docker documentation.

Inside a container, 127.0.0.1 is the container. To reach FlClash on your computer, use host.docker.internal:7890 in Docker Desktop and turn on Allow LAN in FlClash.

A container is like any other device: it needs Allow LAN.

WSL2

By default WSL2 is a separate virtual machine, and its 127.0.0.1 isn't Windows. From Windows 11 22H2 you can mirror the network. Create .wslconfig in your Windows user folder:

[wsl2]
networkingMode=mirrored
autoProxy=true

Run wsl --shutdown and reopen. After that, WSL can use 127.0.0.1:7890. Microsoft explains it here.

Check it

curl -I -x http://127.0.0.1:7890 https://www.google.com

If it returns 200, FlClash is fine and the rest is that tool's own setting.

With TUN on, nothing needs setting in the terminal.

Proxy or network

Run the same command with and without the proxy. Only with: tell the tool. Neither: node or rules.

Functions instead of fixed variables

proxy_on()  { export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5h://127.0.0.1:7890; echo on; }
proxy_off() { unset https_proxy http_proxy all_proxy; echo off; }

In ~/.zshrc or ~/.bashrc; the same two in PowerShell's $PROFILE.

Where tools read it

ToolVariablesOwn setting
curl, wgetYes~/.curlrc, ~/.wgetrc
git httpsYeshttp.proxy
git sshNo~/.ssh/config
npm, pnpm, yarnYesconfig
pipYespip config set global.proxy
goYesGOPROXY
cargoYes~/.cargo/config.toml
gradle, mavenNogradle.properties, settings.xml
aptYes, lost with sudo/etc/apt/apt.conf.d/
brewALL_PROXY
VS CodePartlyhttp.proxy
ping, nslookupNoNone

A nearby mirror is better than a proxy where there is one.

Docker

docker build --build-arg https_proxy=http://host.docker.internal:7890 -t app .
docker run -e https_proxy=http://host.docker.internal:7890 app

On Linux add --add-host=host.docker.internal:host-gateway or use 172.17.0.1. Turn on the LAN proxy and open 7890. docker pull belongs to the daemon: restart after editing and check docker info | grep -i proxy.

WSL2 without mirrored mode

  1. Addressip route show default, third field
  2. Setexport https_proxy=http://that-address:7890
  3. FlClashLAN proxy on
  4. FirewallAllow FlClash on public networks

Still failing with TUN

Nodes may block port 22: use 443. Docker Desktop has its own machine. A company VPN competes for routes. Certificate errors: turn off inspection.

Also asked

https_proxy is set but ping still fails.

Ping uses ICMP, which never goes through an HTTP proxy. Test with curl.

The proxy is gone after sudo.

sudo clears the environment by default. Use sudo -E.

The intranet fails with a proxy?

Put it in no_proxy, in full where wildcards are not supported.

User and password?

http://user:[email protected]:7890, special characters escaped.

VS Code extensions?

http.proxy, or start code after proxy_on.

Read next

On the same line

Key terms: Git through proxy, Docker proxy settings, WSL2 Clash