Networking: Difference between revisions
m fix formatting |
|||
| Line 39: | Line 39: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
networking.hosts = { | networking.hosts = { | ||
"127.0.0.2" = ["other-localhost"]; | "127.0.0.2" = [ "other-localhost" ]; | ||
"192.0.2.1" = ["mail.example.com" "imap.example.com"]; | "192.0.2.1" = [ "mail.example.com" "imap.example.com" ]; | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 120: | Line 120: | ||
=== Virtualization === | === Virtualization === | ||
Sometimes complex network configurations with VPNs or firewall rules you may need extra configurations in order for your VMs to have network access. It is recommended to use more granular control over the ports instead of simply allowing the entire interface.<syntaxhighlight lang="nix">networking = { | Sometimes complex network configurations with VPNs or firewall rules you may need extra configurations in order for your VMs to have network access. It is recommended to use more granular control over the ports instead of simply allowing the entire interface.<syntaxhighlight lang="nix"> | ||
networking = { | |||
firewall = { | firewall = { | ||
enable = true; | enable = true; | ||
| Line 145: | Line 146: | ||
enable = true; | enable = true; | ||
internalInterfaces = [ | internalInterfaces = [ "virbr0" ]; | ||
}; | }; | ||
};</syntaxhighlight> | }; | ||
</syntaxhighlight> | |||
== IPv6 == | == IPv6 == | ||
| Line 243: | Line 243: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
networking = { | |||
hostId = "deadb33f"; | |||
hostName = "nixos"; | |||
domain = "example.com"; | |||
dhcpcd.enable = false; | |||
interfaces.enp2s1.ipv4.addresses = [{ | |||
address = "192.168.1.2"; | |||
prefixLength = 28; | |||
}]; | |||
vlans = { | |||
vlan100 = { id=100; interface="enp2s0"; }; | |||
vlan101 = { id=101; interface="enp2s0"; }; | |||
}; | |||
interfaces.vlan100.ipv4.addresses = [{ | |||
address = "10.1.1.2"; | |||
prefixLength = 24; | |||
}]; | |||
interfaces.vlan101.ipv4.addresses = [{ | |||
address = "10.10.10.3"; | |||
prefixLength = 24; | |||
}]; | |||
defaultGateway = "192.168.1.1"; | |||
nameservers = [ "1.1.1.1" "8.8.8.8" ]; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 299: | Line 299: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
networking.networkmanager.ensureProfiles.profiles = { | |||
"Bond connection 1" = { | |||
bond = { | |||
miimon = "100"; # Monitor MII link every 100ms | |||
mode = "802.3ad"; | |||
xmit_hash_policy = "layer3+4"; # IP and TCP/UDP hash | |||
}; | |||
connection = { | |||
id = "Bond connection 1"; | |||
interface-name = "bond0"; # Make sure this matches the controller properties | |||
type = "bond"; | |||
}; | |||
ipv4 = { | |||
method = "auto"; | |||
}; | |||
ipv6 = { | |||
addr-gen-mode = "stable-privacy"; | |||
method = "auto"; | |||
}; | }; | ||
# No more automatically generated "Wired connection 1" | proxy = { }; | ||
}; | |||
# No more automatically generated "Wired connection 1" | |||
"bond0 port 1" = { | |||
connection = { | |||
id = "bond0 port 1"; | |||
type = "ethernet"; | |||
interface-name = "enp2s0"; | |||
controller = "bond0"; | |||
port-type = "bond"; | |||
}; | }; | ||
}; | |||
"bond0 port 2" = { | |||
connection = { | |||
id = "bond0 port 2"; | |||
type = "ethernet"; | |||
interface-name = "enp3s0"; | |||
controller = "bond0"; | |||
port-type = "bond"; | |||
}; | }; | ||
}; | }; | ||
}; | |||
</nowiki>}} | </nowiki>}} | ||
| Line 347: | Line 347: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
networking.bonds = { | |||
bond0 = { | |||
interfaces = [ "enp2s0" "enp3s0" ]; | |||
driverOptions = { | |||
miimon = "100"; # Monitor MII link every 100ms | |||
mode = "802.3ad"; | |||
xmit_hash_policy = "layer3+4"; # IP and TCP/UDP hash | |||
}; | }; | ||
}; | }; | ||
}; | |||
</nowiki>}} | </nowiki>}} | ||