Networking: Difference between revisions
imported>Ento m Fix indentation |
imported>Onny Add section on port forwarding |
||
| Line 1: | Line 1: | ||
This site provides snippets for configuring your network ''just right'' for the use case you are looking for. All configuration is for <code>configuration.nix</code> | This site provides snippets for configuring your network ''just right'' for the use case you are looking for. All configuration is for <code>configuration.nix</code> | ||
== Configuration == | |||
== Hosts file == | === Hosts file === | ||
To edit <code>/etc/hosts</code> just add something like this to your <code>configuration.nix</code>: | To edit <code>/etc/hosts</code> just add something like this to your <code>configuration.nix</code>: | ||
| Line 12: | Line 13: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Port forwarding === | |||
In this example we're going to forward the port <code>80</code> via NAT from our external network interface <code>ens3</code> to the host <code>10.100.0.3</code> on our internal interface <code>wg0</code>. | |||
<syntaxhighlight lang="nix"> | |||
networking = { | |||
firewall = { | |||
enable = true; | |||
allowedTCPPorts = [ 80 ]; | |||
extraCommands = "iptables -t nat -A POSTROUTING -d 10.100.0.3 -p tcp -m tcp --dport 80 -j MASQUERADE"; | |||
}; | |||
nat = { | |||
enable = true; | |||
internalInterfaces = [ "wg0" ]; | |||
externalInterface = "ens3"; | |||
forwardPorts = [ | |||
{ | |||
sourcePort = 80; | |||
proto = "tcp"; | |||
destination = "10.100.0.3:80"; | |||
} | |||
]; | |||
}; | |||
}; | |||
</syntaxhighlight> | |||
= IPv6 = | = IPv6 = | ||