Skip to content
المشاريع

حول

A NixOS module that lets you route traffic from systemd services through a VPN while preventing DNS leaks.

الأنظمة والبنية التحتية

كيف تُقاس هذه الأرقام

266 نجمة24 التفرعات +1 خلال 24 ساعة

النمو المقاس للنجوم

خلال 24 ساعة
+١
خلال 7 أيام
+٦
خلال 15 يومًا
+٧
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

⛓️ VPN-Confinement ⛓️

A NixOS module that lets you route traffic from systemd services through a VPN while preventing DNS leaks.


[!IMPORTANT] To "prevent" DNS leaks, this module simply makes the NSCD socket inaccessible to a systemd service. This might cause other problems, and leaks have only been tested when resolving DNS over UDP. Other ways of resolving DNS like DoT and DoH have not been tested, and DNS can leak in other ways, so you are always advised to monitor and test for DNS leaks yourself.

Installation

Nix Flake

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    vpn-confinement.url = "github:Maroka-chan/VPN-Confinement";
  };

  outputs = { self, nixpkgs, vpn-confinement, ... }:
  {
    # Change hostname, system, etc. as needed
    nixosConfigurations.hostname = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
        vpn-confinement.nixosModules.default
      ];
    };
  };
}

Usage

Define VPN network namespace

vpnNamespaces.<name> = { # The name is limited to 7 characters
  enable = true;
  wireguardConfigFile = <path to secret wireguard config file>;
  allowedIngress = [
    "<ip or subnet>"
  ];
  allowedEgress = [ # Destinations the namespace may reach outside the tunnel
    "<ip or subnet>"
  ];
  portMappings = [
    <port> # Coerced to { from = <port>; to = <port>; protocol = "tcp"; }
    {
      from = <port on host>;
      to = <port in VPN network namespace>;
      protocol = "<transport protocol>"; # protocol = "tcp" (default), "udp", or "both"
    }
  ];
  vpn.allowedTCPPorts = [ <TCP ports to allow inbound on the VPN interface.> ];
  vpn.allowedUDPPorts = [ <UDP ports to allow inbound on the VPN interface.> ];
};

Add systemd service to VPN network namespace

systemd.services.<name>.vpnConfinement = {
  enable = true;
  vpnNamespace = "<network namespace name>";
};

Example

# configuration.nix
{ pkgs, lib, config, ... }:
{
  # Define VPN network namespace
  vpnNamespaces.wg = {
    enable = true;
    wireguardConfigFile = /. + "/secrets/wg0.conf";
    allowedIngress = [
      "192.168.0.0/24"
    ];
    portMappings = [
      9091 # Coerced to { from = 9091; to = 9091; protocol = "tcp"; }
    ];
    vpn.allowedTCPPorts = [ 60729 ];
    vpn.allowedUDPPorts = [ 60729 ];
  };

  # Add systemd service to VPN network namespace
  systemd.services.transmission.vpnConfinement = {
    enable = true;
    vpnNamespace = "wg";
  };

  services.transmission = {
    enable = true;
    settings = {
      "rpc-bind-address" = "192.168.15.1"; # Bind RPC/WebUI to VPN network namespace address

      # RPC-whitelist examples
      "rpc-whitelist" = "192.168.15.5"; # Access from default network namespace
      "rpc-whitelist" = "192.168.1.*";  # Access from other machines on specific subnet
      "rpc-whitelist" = "127.0.0.1";    # Access through loopback within VPN network namespace
    };
  };
}

[!NOTE] Access from the default network namespace is done using the VPN network namespace address.
curl 192.168.15.1:9091

See all options and their descriptions in the module file.

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…