SOCKS5 and HTTP proxy server that forwards connections based on hostname rules to other SOCKS5 servers or serves them directly.
- SOCKS5 Protocol Support: Built-in SOCKS5 server
- HTTP Proxy Support: Built-in HTTP/HTTPS proxy server
- Rule-Based Forwarding: Configure hostname patterns to forward requests through different upstream SOCKS5 proxies
- Direct Host Override: Configure hosts that will always be served directly, bypassing all forwarding rules
- Direct Connections: Serve requests directly if no forwarding rule matches
- Wildcard Matching: Support for wildcard patterns in hostname rules and direct hosts (e.g.,
*.example.com) - Default Forwarding: Optional default SOCKS5 server for unmatched requests
By default, the SOCKS5 proxy listens on port 1080 and the HTTP proxy on port 8080.
docker run -p 1080:1080 -p 8080:8080 \
-v "config.yaml:/etc/socks-forwarder/config.yaml:ro" \
ghcr.io/jbrunner/socks-forwardermake deps
make build
./socks-forwarder -help# Test SOCKS5 proxy
curl --socks5 localhost:1080 http://example.com
# Test SOCKS5 proxy resolving DNS over SOCKS
curl --socks5-hostname localhost:1080 http://example.com
# Test HTTP proxy
curl --proxy localhost:8080 http://example.comAll features and routing logic are configured via the YAML file: config.yaml.
- Client Connection: The application accepts SOCKS5 connections from clients
- Direct Host Check: First checks if the target hostname is configured as a direct host
- Rule Evaluation: If not a direct host, checks the target hostname against configured forwarding rules
- Forwarding Decision:
- If hostname is in
directHosts: Establish a direct connection (bypasses all rules) - If a rule matches: Forward the request through the specified SOCKS5 server
- If no rule matches but
defaultTargetis set: Forward through the default SOCKS5 server - If no rule matches and no default target: Establish a direct connection
- If hostname is in
- Data Relay: Bidirectionally relay data between the client and target connections
The application exposes comprehensive Prometheus metrics for monitoring and observability if metricsEnabled.
The application provides Kubernetes-compatible health check endpoints:
/health- General health check combining readiness and liveness/readyz- Readiness probe indicating when SOCKS listener is ready to accept traffic/livez- Liveness probe with internal health validations (memory, goroutines, config validity)
All endpoints return JSON responses with detailed status information and appropriate HTTP status codes (200 OK / 503 Service Unavailable).
socks5_active_connections- Number of currently active SOCKS5 connectionssocks5_active_connections_by_rule{rule_name}- Number of currently active SOCKS5 connections by rulesocks5_connections_total{status}- Total number of SOCKS5 connections handled (success/failed)socks5_connection_duration_seconds{routing_type,rule_name}- Connection duration histogram
socks5_bytes_transferred_total{direction,routing_type,rule_name}- Total bytes transferredsocks5_data_transfer_rate_bytes_per_second{direction,rule_name}- Data transfer rate histogram
socks5_routing_decisions_total{decision,rule_name}- Routing decisions madesocks5_rule_matches_total{rule_target,rule_name}- Rule matchessocks5_direct_host_matches_total- Direct host matchessocks5_active_rules- Number of active forwarding rulessocks5_active_direct_hosts- Number of active direct host patterns
socks5_connection_errors_total{error_type,rule_name}- Connection errorssocks5_proxy_errors_total{error_type,rule_name}- Proxy-related errors
socks5_connection_establishment_seconds{connection_type,rule_name}- Connection establishment time
The built-in HTTP proxy server allows you to forward HTTP(S) traffic using the same rules and directHosts as the SOCKS5 proxy. This is useful for tools and environments that do not support SOCKS5 proxies natively.
- Enable or disable the HTTP proxy with
proxyEnabledin your config. - The HTTP proxy listens on
proxyPort(default: 8080). - All routing, directHosts, and rules work exactly as with SOCKS5.
- Prometheus metrics are collected for HTTP proxy traffic as well.
This project is licensed under the MIT License - see the LICENSE file for details.