From 09fbb9d2fb3c0fba1c67d47b243160ca912f4e5e Mon Sep 17 00:00:00 2001 From: un-oeil Date: Fri, 30 Oct 2026 10:53:09 +0100 Subject: [PATCH] proxmox: public web (80/443 -> Caddy), Forgejo SSH 2222, hairpin NAT --- playbooks/utils.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/playbooks/utils.yml b/playbooks/utils.yml index f0c8e71..b9b1bff 100644 --- a/playbooks/utils.yml +++ b/playbooks/utils.yml @@ -414,6 +414,15 @@ hosts: hypervisors gather_facts: false tags: [proxmox] + vars: + # Written exactly as `iptables -t nat -S` prints them, minus "-A ". + utils_public_nat_rules: + - PREROUTING -i vmbr0 -p tcp -m tcp --dport 443 -j DNAT --to-destination 10.0.0.10:443 + - PREROUTING -i vmbr0 -p tcp -m tcp --dport 80 -j DNAT --to-destination 10.0.0.10:80 + - PREROUTING -i vmbr0 -p tcp -m tcp --dport 2222 -j DNAT --to-destination 10.0.0.14:2222 + - PREROUTING -d 138.195.128.200/32 -i vmbr1 -p tcp -m multiport --dports 80,443 -j DNAT --to-destination 10.0.0.10 + - PREROUTING -d 138.195.128.200/32 -i vmbr1 -p tcp -m tcp --dport 2222 -j DNAT --to-destination 10.0.0.14:2222 + - POSTROUTING -s 10.0.0.0/24 -m conntrack --ctstate DNAT --ctorigdst 138.195.128.200 -j MASQUERADE tasks: # The file was fully commented out, so the host got no PVE updates at all. - name: Enable the pve-no-subscription repository @@ -461,6 +470,33 @@ line: -A PREROUTING -i vmbr0 -p udp -m udp --dport 443 -j DNAT --to-destination 10.0.0.250:51820 insertafter: ^-A PREROUTING -i vmbr0 -p udp -m udp --dport 51820 -j DNAT + # Public web (2026-10-30): tcp 80/443 -> Caddy, 2222 -> Forgejo SSH. Caddy + # aborts every site not meant for the internet (wg_only snippet), so only + # vault, forgejo, md, pad, pterodactyl and wings answer from outside. + # The vmbr1 rules are hairpin NAT: guests that resolve a public name reach + # Caddy too, and show up as 10.0.0.1 (allowed by wg_only). + - name: Public web and Forgejo SSH (live) + ansible.builtin.command: iptables -t nat -C {{ item }} + register: utils_public_nat + changed_when: false + failed_when: false + loop: "{{ utils_public_nat_rules }}" + + - name: Public web and Forgejo SSH (add missing live rules) + ansible.builtin.command: iptables -t nat -A {{ item.item }} + loop: "{{ utils_public_nat.results | selectattr('rc', '!=', 0) | list }}" + loop_control: + label: "{{ item.item }}" + changed_when: true + + - name: Public web and Forgejo SSH (rules.v4) + ansible.builtin.lineinfile: + path: /etc/iptables/rules.v4 + line: -A {{ item }} + insertbefore: ^-A POSTROUTING -s 10.0.0.0/24 -o vmbr0 -j MASQUERADE + firstmatch: true + loop: "{{ utils_public_nat_rules }}" + - name: WireGuard hub hosts: wireguard gather_facts: false