wg-home: rewrite forwarding rules to avoid naming any interface
This commit is contained in:
@@ -101,22 +101,15 @@ in
|
|||||||
in
|
in
|
||||||
mkClientPeers peer-list
|
mkClientPeers peer-list
|
||||||
;
|
;
|
||||||
} // (lib.optionalAttrs cfg.forwardToWan (let
|
} // (lib.optionalAttrs cfg.forwardToWan {
|
||||||
# TODO: don't hardcode the interface, but rather some type of "default", or NAT to an IP address
|
|
||||||
iface = if config.networking.usePredictableInterfaceNames then
|
|
||||||
"ens1"
|
|
||||||
else
|
|
||||||
"eth0"
|
|
||||||
;
|
|
||||||
in {
|
|
||||||
# documented here: <https://nixos.wiki/wiki/WireGuard#Server_setup_2>
|
# documented here: <https://nixos.wiki/wiki/WireGuard#Server_setup_2>
|
||||||
postSetup = ''
|
postSetup = ''
|
||||||
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING --source ${cfg.ip}/24 --out-interface ${iface} -j MASQUERADE
|
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING --source ${cfg.ip}/24 ! --destination ${cfg.ip}/24 -j MASQUERADE
|
||||||
'';
|
'';
|
||||||
postShutdown = ''
|
postShutdown = ''
|
||||||
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING --source ${cfg.ip}/24 --out-interface ${iface} -j MASQUERADE
|
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING --source ${cfg.ip}/24 ! --destination ${cfg.ip}/24 -j MASQUERADE
|
||||||
'';
|
'';
|
||||||
})));
|
}));
|
||||||
|
|
||||||
# plug into my VPN abstractions so that one may:
|
# plug into my VPN abstractions so that one may:
|
||||||
# - `sane-vpn up wg-home` to route all traffic through servo
|
# - `sane-vpn up wg-home` to route all traffic through servo
|
||||||
|
Reference in New Issue
Block a user