NixOS-Config/system/server/firewall.nix

58 lines
2.3 KiB
Nix
Raw Normal View History

{outputs, ...}: {
2024-08-24 22:16:51 -04:00
# Allow forwarding
boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
# Configure firewall
networking = let
2024-08-24 22:32:58 -04:00
ips = import ../modules/ips.nix;
2024-09-18 13:49:57 -04:00
mailPorts = "{ 25, 143, 465, 587, 993, 4190 }";
2024-08-24 22:16:51 -04:00
in {
firewall = {
allowPing = false;
# Add extra input rules using nftables
extraInputRules = ''
2024-09-23 14:16:30 -04:00
ip saddr { ${ips.localSpan}.0/24, ${ips.wgSpan}.0/24 } tcp dport 2049 accept comment "Accept NFS"
ip saddr { ${ips.pc}, ${outputs.secrets.lunaIP}, ${outputs.secrets.cornIP}, ${outputs.secrets.vertIP} } tcp dport { 1935, 1945 } accept comment "Accept RTMP"
2024-09-18 13:49:57 -04:00
ip saddr ${ips.wgSpan}.3 tcp dport ${mailPorts} accept comment "Accept mail"
2024-08-24 22:16:51 -04:00
'';
};
# Enable nftables and forwarding
nftables = {
enable = true;
tables = {
forwarding = {
family = "ip";
content = ''
chain PREROUTING {
type nat hook prerouting priority dstnat; policy accept;
tcp dport 2211 dnat to ${ips.pc}:22 comment "SSH to PC"
2024-09-12 01:31:59 -04:00
tcp dport 2233 dnat to ${ips.wgSpan}.3:22 comment "SSH to Oracle VM"
udp dport { 27005, 27015, 7777 } dnat to ${ips.pc} comment "PC Hosted Games"
2024-09-12 01:31:59 -04:00
tcp dport { 58010, 57989, 57984 } dnat to ${ips.pc} comment "PC Sunshine TCP"
udp dport { 57998, 57999, 58000 } dnat to ${ips.pc} comment "PC Sunshine UDP"
2024-09-12 01:31:59 -04:00
tcp dport { 38010, 37989, 37984 } dnat to ${ips.vm} comment "VM Sunshine TCP"
udp dport { 37998, 37999, 38000 } dnat to ${ips.vm} comment "VM Sunshine UDP"
2024-09-12 01:31:59 -04:00
udp dport { 7790, 7791, 7792 } dnat to ${ips.hx} comment "Deus Ex"
2024-09-12 01:31:59 -04:00
ip saddr ${outputs.secrets.cornIP} tcp dport { 9943, 9944 } dnat to ${ips.vm} comment "VM ALVR TCP"
ip saddr ${outputs.secrets.cornIP} udp dport { 9943, 9944 } dnat to ${ips.vm} comment "VM ALVR UDP"
2024-08-24 22:16:51 -04:00
}
chain POSTROUTING {
type nat hook postrouting priority 100; policy accept;
oifname "${ips.netInt}" masquerade
2024-09-12 23:15:40 -04:00
iifname "${ips.netInt}" oifname "${ips.wgInt}" masquerade comment "Traffic from public to WireGuard"
2024-09-18 13:49:57 -04:00
tcp dport ${mailPorts} oifname != "${ips.wgInt}" drop comment "Send mail"
2024-08-24 22:16:51 -04:00
}
'';
};
};
};
};
}