Enable Proxy When macOS VPN is On
Configuring macOS System Proxy When VPN is Active
When working with VPNs on macOS, you may encounter an issue where your system proxy settings seem to stop working. This article explains why this happens and how to properly configure proxy settings for VPN connections using command-line tools.
Understanding Network Services
By default, when macOS connects to a VPN, it automatically ignores globally configured proxy environment variables like http_proxy and https_proxy. This behavior occurs because proxy environment variables are bound to specific macOS network services.
To view all network services currently available on your system, use the following command:
networksetup -listallnetworkservicesProxy settings configured through the macOS Network Preferences interface are applied to the Wi-Fi service. However, when you activate a WireGuard VPN (or any VPN), the VPN’s corresponding service takes precedence and overrides the Wi-Fi configuration.
The challenge is that macOS doesn’t provide a graphical interface to configure proxy settings directly for VPN services. This is where the networksetup command-line utility becomes essential.
Using networksetup to Manage Proxy Settings
Viewing Current Proxy Configuration
To check the existing proxy settings for a specific network service, you can use these commands:
HTTP Proxy:
networksetup -getwebproxy Wi-FiHTTPS Proxy:
networksetup -getsecurewebproxy Wi-FiSOCKS Proxy:
networksetup -getsocksfirewallproxy Wi-FiProxy Bypass Domains:
networksetup -getproxybypassdomains Wi-FiConfiguring Proxy for VPN Service
First, identify your VPN service name using the networksetup -listallnetworkservices command mentioned earlier. Once you’ve identified the service name (in this example, “WRAP”), you can configure the proxy settings:
Set HTTP Proxy:
networksetup -setwebproxy WRAP 127.0.0.1 8080Set HTTPS Proxy:
networksetup -setsecurewebproxy WRAP 127.0.0.1 8080Set SOCKS Proxy:
networksetup -setsocksfirewallproxy WRAP 127.0.0.1 1080Disable Proxy for VPN Service
After enabling the proxy service through the networksetup command, there is no way to manage it through the GUI. To disable the proxy, use the following commands.
Disable HTTP Proxy:
networksetup -setwebproxystate WRAP offDisable HTTPS Proxy:
networksetup -setsecurewebproxystate WRAP offDisable SOCKS Proxy:
networksetup -setsocksfirewallproxystate WRAP offImportant Note
A system restart is required for these changes to take effect. Make sure to reboot your Mac after applying the proxy configuration to your VPN service.
With these commands, you can successfully configure proxy settings that persist even when your VPN connection is active, ensuring seamless routing of your network traffic through your preferred proxy server.