---
title: "What Is a Proxy Kill Switch? Does Traffic Stop If It Drops?"
description: "A proxy kill switch stops traffic when the proxy drops instead of falling back to a direct connection. Setup in code, firewall and browser, plus how to test it."
url: https://proxynet.io/blog/proxy-kill-switch
date: 2026-12-03
author: "Acar Diveroli"
category: "Privacy"
lang: en
---

# What Is a Proxy Kill Switch? Does Traffic Stop If It Drops?

A proxy kill switch is a mechanism that stops traffic when the proxy connection drops, instead of letting it go out over a direct connection. Most tools raise an error when they cannot reach the proxy and do not connect directly on their own. A leak happens when the configuration still holds a fallback that allows a direct connection. That fallback can be a `try/except` block, a missing scheme key or a `DIRECT` entry in a PAC file. This post covers setting up a kill switch at the application, system and browser level, and testing it by switching the proxy off.

> **Note: Short answer**
>
> A proxy kill switch stops a request when the proxy drops, instead of sending it from your real IP. Do not write a direct-connection fallback in code, allow outbound traffic only to the proxy address in the firewall, and remove the `DIRECT` fallback from your PAC file.

## Falling back to a direct connection

Falling back to a direct connection means the request is sent without the proxy when the proxy is not working. The target site sees that request from your real IP address. No error appears either, because the request completes successfully.

The tools' own behavior is mostly safe. The problem sits at the edges of the configuration. These are the cases we saw in our test and in the official documentation:

| Case | Result |
|---|---|
| Requests, proxy down | `ProxyError`, request stops ✓ |
| Requests, only the `"http"` key, HTTPS target | Request goes out directly ✗ |
| Requests, wrong password, HTTP target | Returns a `407` response, no exception |
| curl `-x`, proxy down | Exit code `7`, request stops ✓ |
| curl `-x`, `NO_PROXY` covers the target | Request goes out directly ✗ |
| `PROXY …; DIRECT` in a PAC file | Connects directly when the proxy drops ✗ |
| Chrome, PAC file cannot be downloaded | Silently connects directly ✗ |

Each ✗ row is a separate open door, and a kill switch means closing those doors one by one. The most robust setup has two layers: the code makes the proxy mandatory, and the firewall allows no other way out even if the code makes a mistake.

## Making the proxy mandatory in code

An application-level kill switch catches the proxy error and stops the job. Retrying over a direct connection after the error breaks the kill switch. This is the most common mistake:

```python
try:
    r = requests.get(url, proxies=proxies, timeout=10)
except requests.exceptions.ProxyError:
    r = requests.get(url, timeout=10)  # the line that breaks the kill switch
```

In our test, with the proxy down, this block connected to the target directly and raised no error. Use the setup below instead. The session ignores environment variables and both scheme keys are filled in. A proxy error is retried only through the proxy, and the job stops when the retries run out. Before the job starts, the exit IP is compared with your real IP.

```python
import sys
import time

import requests

PROXY = "http://user:pass@pr.proxynet.io:8000"
IP_URL = "https://api.ipify.org"

def proxied_session():
    s = requests.Session()
    s.trust_env = False  # environment variables cannot override the setting
    s.proxies = {"http": PROXY, "https": PROXY}  # both keys are set
    return s

def fetch(s, url, tries=3):
    for i in range(tries):
        try:
            r = s.get(url, timeout=(5, 30))
        except requests.exceptions.ProxyError:
            time.sleep(2 ** i)  # retry through the proxy only
            continue
        if r.status_code == 407:
            sys.exit("Proxy rejected authentication, job stopped")
        return r
    sys.exit("Cannot reach the proxy, job stopped")  # no switch to a direct connection

direct = requests.Session()
direct.trust_env = False
real_ip = direct.get(IP_URL, timeout=10).text.strip()

s = proxied_session()
exit_ip = fetch(s, IP_URL).text.strip()
if exit_ip == real_ip:
    sys.exit("Exit IP matches the real IP, job stopped")
print("Exit IP:", exit_ip)
```

The `"https"` key is the line people forget most. Requests picks the proxy by the target's scheme. For an HTTPS target with no matching key, no proxy is used and no error appears. The `407` check matters too: on an HTTP target a wrong password raises no exception, it returns a plain response. If the firewall rule is in place, the `real_ip` line fails. In that case, write your real IP as a constant.

## Making the proxy mandatory in curl

curl stops and does not connect directly when it cannot reach the proxy given with `-x`. If the proxy name cannot be resolved, the exit code is `5`. If the connection fails, it is `7`. Checking these codes in a script is enough in most cases.

There are two edge cases. The first is the `NO_PROXY` variable: in our test, when the target was on that list, curl connected directly even with `-x` set. The second is a wrong password: on an HTTP target, curl received the `407` response and exited with code `0`. These flags close both:

```bash
curl --noproxy "" --fail \
  -x http://user:pass@pr.proxynet.io:8000 \
  https://api.ipify.org
```

`--noproxy ""` overrides the `NO_PROXY` list from the environment. `--fail` exits with a non-zero code on responses of 400 and above. If the exit code is not `0`, your script should stop the job.

## A firewall kill switch

A system-level kill switch is a firewall rule that allows outbound traffic only to the proxy address. Even if the code makes a mistake, packets cannot go anywhere else. The connection is rejected and the request fails instead of leaking.

On Linux, running the job as a separate user is the cleanest way. The iptables `owner` match applies the rule only to that user's connections, so SSH and other services are not affected.

```bash
# Look up the IPv4 address of the proxy endpoint
getent ahostsv4 pr.proxynet.io

# Allow outbound traffic for the scraper user only to the proxy
sudo iptables -A OUTPUT -m owner --uid-owner scraper -o lo -j ACCEPT
sudo iptables -A OUTPUT -m owner --uid-owner scraper \
  -p tcp -d 203.0.113.10 --dport 8000 -j ACCEPT
sudo iptables -A OUTPUT -m owner --uid-owner scraper -j REJECT

# Block IPv6 outbound traffic for the same user
sudo ip6tables -A OUTPUT -m owner --uid-owner scraper -o lo -j ACCEPT
sudo ip6tables -A OUTPUT -m owner --uid-owner scraper -j REJECT
```

Replace `203.0.113.10` with the addresses from the `getent` output. If the address changes, the rule cuts the connection. That is the right direction for a kill switch: you update the rule with the new address. If the DNS resolver sits on a local address such as `127.0.0.53`, the `lo` rule covers it. Otherwise, add a separate rule for port 53 on the resolver. Do not skip the IPv6 lines: on a machine with only an IPv4 rule, IPv6 outbound stays open. Details are in our [IPv6 leak test](/blog/proxy-ipv6-leak-test) post.

A rotating [Residential Proxy](https://proxynet.io/residential-proxy) does not add rules. The exit IPs change behind the proxy gateway, and the gateway is the only address your machine connects to.

On Windows, the same logic means setting the outbound default in Windows Defender Firewall to "block" and adding a single allow rule. This setting affects the whole machine, so set it up in a separate virtual machine.

## The DIRECT fallback in the browser

In the browser, the source of a leak is usually a direct-connection fallback. If a single manually entered proxy goes down, Chrome stops the request with `ERR_PROXY_CONNECTION_FAILED`. That behavior already works like a kill switch.

A PAC file is different. The line `"PROXY pr.proxynet.io:8000; DIRECT"` means connecting directly, without asking the user, once the proxy drops. The Chromium documentation describes a second path: if the PAC file cannot be downloaded, Chrome silently connects directly. Adding `direct://` to the `--proxy-server` value on the command line sets up the same fallback. For data collection targets, return only `PROXY`. Rule syntax is covered in our [PAC file](/blog/pac-file) post.

Serve the PAC file from local disk or your own server, because an unreachable file means every rule is ignored. The "Automatically detect settings" option also connects directly when it finds no PAC file.

## Testing the kill switch

The way to test a kill switch is to break the proxy on purpose. While the proxy works, everything looks right. The fault only shows at the moment of the drop.

1. Note your real IP from an IP echo service with the proxy off.
2. Start the application with the proxy and confirm the exit IP is different.
3. Break the proxy: point it to a closed port (such as `pr.proxynet.io:8001`) or corrupt the password.
4. Send the same request again.
5. The request should fail. If a response comes back and the IP is your real IP, a fallback path is open.

Test each layer separately: code, command line and browser. To check the firewall rule, turn off the code's own check temporarily. The request should still not get out. For choosing an echo service, see our [proxy exit IP check](/blog/proxy-egress-ip-check-api) post.

## Troubleshooting

A short list from symptom to cause:

- **The page loads with the proxy down.** There is a direct request inside an `except` in the code, `DIRECT` in the PAC file, or automatic detection in the browser.
- **Only HTTPS requests leave from your real IP.** The `"https"` key is missing in Requests.
- **curl skips the proxy for one target.** `NO_PROXY` covers that target. Add `--noproxy ""`.
- **The script finished "successfully" but there is no data.** The `407` response was not treated as an error. Add `--fail` in curl and check the status code in your code.
- **Nothing works after the firewall rule.** DNS is blocked or the proxy address changed. Look up the address again with `getent`.

## How we tested

We ran the scenarios on December 3, 2026 on Windows 11 with Python 3.13.17, Requests 2.34.2 and curl 8.23.0. We set up a local Python proxy that requires `user:pass` and logs every request. We used two local servers as targets. We decided whether a request went through the proxy by checking the proxy log and the header the target saw. For "proxy down" we used a port with nothing listening, and for "wrong password" we sent bad credentials. We ran the Python code above, with the proxy address and IP service swapped for local equivalents, in three cases: working proxy, proxy down and wrong password. We did not test the firewall rules or browser behavior on this machine. Those sections rely on the official documentation.

## The bottom line

Make the proxy mandatory in code, do not write a direct-connection fallback, and allow outbound traffic in the firewall only to the proxy address. For tools that use UDP, pick a [SOCKS5 Proxy](https://proxynet.io/socks5-proxy) that carries UDP and add the UDP address to the rule too. Above all, test the kill switch by switching the proxy off on purpose: everything you see while the setup is working is misleading.

## Sources

- [Requests, Advanced Usage, Proxies: requests.readthedocs.io](https://requests.readthedocs.io/en/latest/user/advanced/#proxies)
- [curl man page, --noproxy and exit codes: curl.se](https://curl.se/docs/manpage.html)
- [iptables-extensions, owner match: man7.org](https://man7.org/linux/man-pages/man8/iptables-extensions.8.html)
- [Proxy support in Chrome: chromium.googlesource.com](https://chromium.googlesource.com/chromium/src/+/HEAD/net/docs/proxy.md)
- [Proxy Auto-Configuration (PAC) file: developer.mozilla.org](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_PAC_file)

## Frequently asked questions

### What is a proxy kill switch?

A proxy kill switch is a setting that stops traffic when the proxy connection drops. The request is not sent from your real IP address, it fails. You set it up by catching the proxy error in code and stopping the job, by allowing outbound traffic only to the proxy address in the firewall, or by removing the `DIRECT` fallback from your PAC file. The most robust setup uses code and firewall together.

### Does my browser show my real IP if the proxy drops?

It depends on the setting. If a single manually entered proxy goes down, Chrome does not open the page and shows `ERR_PROXY_CONNECTION_FAILED`. If the PAC file has a `DIRECT` fallback, the PAC file cannot be downloaded, or automatic detection is on, the browser may connect directly. In that case the site sees your real IP address. Test it by switching the proxy off on purpose.

### Does Python Requests connect directly if the proxy fails?

No. If the proxy cannot be reached, Requests raises `ProxyError` and does not send the request. Leaks happen in two places. Either the code retries without the proxy inside an `except`, or the `"https"` key is missing from the `proxies` dictionary. In the second case, HTTPS targets go out directly with no error. Fill in both keys and use `trust_env = False`.

### How do you set up a kill switch with a firewall?

With rules that allow outbound traffic only to the address and port of the proxy gateway and reject everything else. On Linux, the iptables `owner` match applies the rule to a single user, so SSH is not affected. Write the same rule for IPv6 with ip6tables. If you need access to the DNS resolver, allow it separately. On Windows, you block outbound connections by default and add a single allow rule.

### How do I test that the kill switch works?

By breaking the proxy on purpose and sending the same request again. First note your real IP, then start the application with the proxy. Point the proxy address to a closed port or corrupt the password. The request should fail. If a response comes back and the IP is your real IP, a fallback path is still open. Test code, command line and browser separately.

### Does SOCKS5 UDP traffic get caught by the firewall rule?

Yes, if the rule only allows TCP. In SOCKS5, UDP traffic goes to a separate UDP address requested over the TCP connection. The server announces that address and port during the connection. Add this UDP address to the kill switch rule too. If you do not, UDP packets do not leak, they are only rejected and the application fails.
