Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation: DNAT examples #14

Open
steveej opened this issue Dec 28, 2023 · 0 comments
Open

documentation: DNAT examples #14

steveej opened this issue Dec 28, 2023 · 0 comments

Comments

@steveej
Copy link

steveej commented Dec 28, 2023

i'd like to add to the wishlist 🙂 e.g.

  1. redirect a destination port to a different port on localhost
  2. redirect a destination port to a different host on lan
  3. redirect all traffic except for the ssh port to a host on lan

these should be relatively common use-cases and, being new to both nftables and this library, it's not obvious to me how to do this here.

as this is my first post in this repo, thank you for creating this library 🙌

Originally posted by @steveej in #12 (comment)


creating this issue to start contributing documentation. here's an example for exposing a host (case 3 and 1 from above)

networking.nftables = {
  firewall = {
    enable = true;
    zones = {
      wan.interfaces = ["wan" "lan0"];
    };
  };
  chains = {
    prerouting = {
      "redirectweb" = {
        after = ["hook"];
        rules = let
          wanInterfaces = builtins.concatStringsSep ", " config.networking.nftables.firewall.zones.wan.interfaces;
          exposedHost = "192.168.0.23";
         in [
          "iifname { ${wanInterfaces} } tcp dport 220 redirect to 22"
          "iifname { ${wanInterfaces} } dnat ip to ${exposedHost}"
        ];
      };
    };
  };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant