nix/nixos/hosts/osaka-linode-01/firewall.nix

101 lines
4.6 KiB
Nix
Raw Normal View History

2023-12-05 05:27:06 +01:00
{ config, lib, pkgs, ... }: {
networking.firewall.allowedUDPPorts = [
3478 # Headscale DERP UDP
10000 # Jitsi
];
networking.firewall.allowedTCPPorts = [
80 # HTTP
443 # HTTPS
25 # SMTP (explicit TLS => STARTTLS)
465 # ESMTP (implicit TLS)
587 # ESMTP (explicit TLS => STARTTLS)
143 # IMAP4 (explicit TLS => STARTTLS)
993 # IMAP4 (implicit TLS)
4190 # Sieve support
42420 # Vintage Story
25565 # Minecraft
1443 # Headscale DERP
4443 # jitsi-jvb
5222 # Jitsi
5347 # Jitsi
5280 # Jitsi
];
networking.firewall.extraCommands = ''
2023-12-06 12:38:38 +01:00
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
2023-12-06 12:56:23 +01:00
iptables -t nat -A POSTROUTING -o eth0 -s 10.100.0.2/32 ! -d 10.100.0.2/32 -j MASQUERADE
2023-12-06 12:50:56 +01:00
iptables -A FORWARD -s 10.100.0.2/32 -j ACCEPT
iptables -A FORWARD -d 10.100.0.2/32 -j ACCEPT
iptables -A FORWARD -s ! 10.100.0.2/32 -j DROP
2023-12-06 12:38:38 +01:00
# TCP PORTS ##################################################################################################
# PORT 80
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 80 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 443
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 443 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 25
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 25 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 465
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 465 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 587
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 587 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 143
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 143 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 993
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 993 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 4190
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 4190 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 42420
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 42420 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 25565
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 25565 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 1443
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 1443 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 4443
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 4443 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 5222
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 5222 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 5347
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 5347 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 5280
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p tcp --dport 5280 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p tcp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# UDP PORTS ##################################################################################################
# PORT 10000
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p udp --dport 10000 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p udp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-06 12:38:38 +01:00
# PORT 3478
2023-12-06 12:50:56 +01:00
iptables -t nat -A PREROUTING -d 172.234.84.222 -p udp --dport 3478 -j DNAT --to-destination 10.100.0.2
iptables -t nat -A POSTROUTING -p udp -s 10.100.0.2 -j SNAT --to 10.100.0.2
2023-12-05 05:27:06 +01:00
'';
}