Networking: Difference between revisions
m →Virtualization: minor formatting fix |
|||
| (2 intermediate revisions by 2 users not shown) | |||
| 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 | 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 = { | networking = { | ||
firewall = { | firewall = { | ||
enable = true; | enable = true; | ||
trustedInterfaces = [ | # Allows the entire interface through the firewall. | ||
# trustedInterfaces = [ "virbr0" ]; | |||
]; | |||
# Allows individual ports through the firewall. | |||
interfaces = { | |||
virbr0 = { | |||
allowedUDPPorts = [ | |||
# DNS | |||
53 | |||
# DHCP | |||
67 | |||
# You may want to allow more ports such as ipv6 and other services here. | |||
]; | |||
}; | |||
}; | |||
}; | }; | ||
nat = { | nat = { | ||
enable = true; | enable = true; | ||
internalInterfaces = [ | internalInterfaces = [ "virbr0" ]; | ||
}; | }; | ||
}; | }; | ||
| Line 231: | Line 241: | ||
<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 287: | Line 297: | ||
{{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 335: | Line 345: | ||
{{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>}} | ||