WireBalancer is a high-performance load balancer that routes your traffic through multiple WireGuard VPN connections via SOCKS5 proxies. It's perfect for:
- Load balancing across multiple VPN connections
- Automatic failover when connections go down
- Real-time monitoring of connection health
- Choosing specific connections for different applications (this simplifies multi-threaded scraping tasks)
cd /path/to/downloadmkdir wireguard-configs
# Copy your .conf files here
cp /path/to/your/wg0.conf wireguard-configs/
cp /path/to/your/wg1.conf wireguard-configs/cp config.example.yml config.yml
nano config.yml # Edit to match your setupExample config:
wireguard:
connections:
- name: "US Server"
interface_name: "wg0"
config_path: "/etc/wireguard/wg0.conf"
- name: "EU Server"
interface_name: "wg1"
config_path: "/etc/wireguard/wg1.conf"# Option A: Using docker compose
docker compose up -d
# Option B: Using make
make docker-upOpen http://localhost:9929 in your browser
- 9930: Random connection (load balanced)
- 9931: First WireGuard connection (wg0)
- 9932: Second WireGuard connection (wg1)
- 9933: Third WireGuard connection (wg2)
- ... and so on
# Random connection
curl -x socks5://localhost:9930 https://api.ipify.org
# Specific connection
curl -x socks5://localhost:9931 https://api.ipify.org- Open browser settings
- Find proxy/network settings
- Set SOCKS5 proxy:
- Host:
localhost - Port:
9930(or specific port)
- Host:
import requests
proxies = {
'http': 'socks5://localhost:9930',
'https': 'socks5://localhost:9930'
}
response = requests.get('https://api.ipify.org', proxies=proxies)
print(f"Your IP: {response.text}")const SocksProxyAgent = require('socks-proxy-agent');
const fetch = require('node-fetch');
const agent = new SocksProxyAgent('socks5://localhost:9930');
fetch('https://api.ipify.org', { agent })
.then(res => res.text())
.then(ip => console.log('Your IP:', ip));package main
import (
"fmt"
"io/ioutil"
"net/http"
"golang.org/x/net/proxy"
)
func main() {
dialer, err := proxy.SOCKS5("tcp", "localhost:9930", nil, proxy.Direct)
if err != nil {
panic(err)
}
transport := &http.Transport{Dial: dialer.Dial}
client := &http.Client{Transport: transport}
resp, err := client.Get("https://api.ipify.org")
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println("Your IP:", string(body))
}Dashboard (http://localhost:9929)
- View all connection statuses
- See request counts per connection
- Monitor latency
- Check uptime
# Get JSON stats
curl http://localhost:9929/api/stats | jq# View logs
docker compose logs -f
# Restart
docker compose restart
# Stop
docker compose down
# Rebuild after config changes
docker compose up -d --force-recreate
# Check status
docker compose ps
# Get stats
make stats# Check WireGuard status
docker exec wirebalancer wg show
# Check logs
docker compose logs wirebalancer
# Test connectivity
docker exec wirebalancer ping 8.8.8.8# Test SOCKS5 proxy
curl -v -x socks5://localhost:9930 https://google.com
# Check if ports are open
netstat -tlnp | grep 9930# Edit config
nano config.yml
# Restart
docker compose restart- Check WireGuard configuration files are valid
- manual builds/outside docker: Ensure container has proper capabilities (
NET_ADMIN,SYS_MODULE) - manual builds/outside docker: Verify kernel modules are loaded:
lsmod | grep wireguard
- Check WireGuard connection:
docker exec wirebalancer wg show - Verify routing:
docker exec wirebalancer ip route - Test connectivity:
docker exec wirebalancer ping 8.8.8.8 - Check logs:
docker compose logs -f wirebalancer
# Build
make build
# Run (requires root for WireGuard)
sudo ./wirebalancer -config config.yml# Install as systemd service
sudo cp wirebalancer /usr/local/bin/
sudo cp wirebalancer.service /etc/systemd/system/
sudo systemctl enable wirebalancer
sudo systemctl start wirebalancerYou can run multiple instances on different ports by:
- Copy the directory
- Change port numbers in config.yml
- Run with different compose project names:
docker compose -p wirebalancer2 up -d- Buffer Size: Increase
buffer_sizein config for high-bandwidth connections - Health Checks: Adjust
health_check_intervalbased on your needs (lower = more accurate, higher = less overhead) - Network Mode: Use
hostnetwork mode for best performance