A Bash script to configure system-wide proxy settings for V2Ray on Linux. Supports separate HTTP and SOCKS5 proxies, auto-detects V2Ray ports from its config, and writes settings to both /etc/profile.d/proxy.sh and /etc/environment for maximum compatibility.
- V2Ray port auto-detection — reads
httpandsocksinbound ports from/usr/local/share/v2ray/config.json(falls back to10809/10808) - Separate HTTP and SOCKS5 proxy configuration
- Port reachability test before applying settings
- Dual-file writes —
/etc/profile.d/proxy.sh(login shells) and/etc/environment(display managers / PAM) - Safe backups — timestamped
.bakfiles created before any modification - HTB-aware
no_proxy— bypasses*.htband*.localout of the box - Electron/Chromium compatibility flag included
- Colored output for clear status feedback
- Linux (Debian/Ubuntu/Arch or any distro with
/etc/environment) bashjq(for V2Ray config parsing)- Root privileges (
sudoor run as root)
# Copy to system PATH
sudo cp proxy.sh /usr/local/bin/proxy
sudo chmod +x /usr/local/bin/proxysudo proxy| Choice | Action |
|---|---|
1 |
Custom — prompts for HTTP IP/port and SOCKS5 IP/port |
2 |
Default — auto-detects V2Ray ports and applies immediately |
3 |
Unset — removes all proxy settings from both files and current shell |
After setting, existing terminals need a manual source:
source /etc/profile.d/proxy.shNew login sessions pick up settings automatically.
| File | Purpose |
|---|---|
/etc/profile.d/proxy.sh |
Loaded by login shells (export statements) |
/etc/environment |
Loaded by PAM / display managers (no export) |
The following are always excluded from proxying:
localhost, 127.0.0.1, 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, ::1, *.local, *.htb