Skip to content

Configuration

Every Gluetun setup requires a VPN service provider:

var vpn = builder.AddGluetun("vpn")
.WithVpnProvider("mullvad");

See the Gluetun wiki for the full list of supported providers.

// String key (for development/testing)
vpn.WithWireGuard("my-private-key");
// Aspire parameter resource (recommended for secrets)
vpn.WithWireGuard(builder.AddParameter("wireguard-key", secret: true));

Sets VPN_TYPE=wireguard and WIREGUARD_PRIVATE_KEY.

// String credentials (for development/testing)
vpn.WithOpenVpn("username", "password");
// Aspire parameter resources (recommended for secrets)
vpn.WithOpenVpn(
builder.AddParameter("openvpn-user"),
builder.AddParameter("openvpn-pass", secret: true));

Sets VPN_TYPE=openvpn, OPENVPN_USER, and OPENVPN_PASSWORD.

vpn.WithServerCountries("US", "Canada", "Germany");
vpn.WithServerCities("New York", "Toronto");

Values are comma-joined and set as SERVER_COUNTRIES / SERVER_CITIES environment variables.

Gluetun includes built-in HTTP and Shadowsocks proxies:

vpn.WithHttpProxy(); // HTTPPROXY=on
vpn.WithHttpProxy(false); // HTTPPROXY=off
vpn.WithShadowsocks(); // SHADOWSOCKS=on
vpn.WithShadowsocks(false); // SHADOWSOCKS=off

To expose the proxy ports, pass them when creating the resource:

var vpn = builder.AddGluetun("vpn", httpProxyPort: 8888, shadowsocksPort: 8388)
.WithHttpProxy()
.WithShadowsocks();
vpn.WithFirewallOutboundSubnets("10.0.0.0/8", "192.168.0.0/16");
vpn.WithTimezone("America/New_York");

WithFirewallOutboundSubnets sets FIREWALL_OUTBOUND_SUBNETS, useful for allowing traffic to local network resources outside the VPN tunnel.

For any Gluetun environment variable not covered by the typed methods:

// String value
vpn.WithGluetunEnvironment("DNS_ADDRESS", "1.1.1.1");
// Aspire parameter resource
vpn.WithGluetunEnvironment("UPDATER_PERIOD", builder.AddParameter("updater-period"));

This is useful for provider-specific settings. See the Gluetun wiki for the full list of environment variables.