From acabd34f28bb86ca25cd4f575628c3eb0d75f6b6 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 12 Dec 2022 05:21:29 +0000 Subject: [PATCH] servo: net: forward http requests from vpn -> host w/o NATing the source address this ensures we have access to the source IP in our host-side logs --- hosts/servo/net.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hosts/servo/net.nix b/hosts/servo/net.nix index ceb68d59a..f97dc4245 100644 --- a/hosts/servo/net.nix +++ b/hosts/servo/net.nix @@ -130,16 +130,19 @@ # this exists so LetsEncrypt can procure a cert for the MX over http. # TODO: we could use _acme_challence.mx.uninsane.org CNAME to avoid this forwarding # - - ${in-ns} ${iptables} -A PREROUTING -t nat -p tcp --dport 80 -j DNAT --to-destination ${veth-host-ip}:80 - ${in-ns} ${iptables} -A POSTROUTING -t nat -p tcp --dport 80 -j SNAT --to-source ${veth-local-ip} + ${in-ns} ${iptables} -A PREROUTING -t nat -p tcp --dport 80 -m iprange --dst-range ${vpn-ip} \ + -j DNAT --to-destination ${veth-host-ip}:80 - # we also bridge DNS traffic (TODO: figure out why TCP doesn't work. do we need to rewrite the source addr?) - ${in-ns} ${iptables} -A PREROUTING -t nat -p udp --dport 53 -m iprange --dst-range ${vpn-ip} -j DNAT --to-destination ${veth-host-ip}:53 - ${in-ns} ${iptables} -A PREROUTING -t nat -p tcp --dport 53 -m iprange --dst-range ${vpn-ip} -j DNAT --to-destination ${veth-host-ip}:53 + # we also bridge DNS traffic + ${in-ns} ${iptables} -A PREROUTING -t nat -p udp --dport 53 -m iprange --dst-range ${vpn-ip} \ + -j DNAT --to-destination ${veth-host-ip}:53 + ${in-ns} ${iptables} -A PREROUTING -t nat -p tcp --dport 53 -m iprange --dst-range ${vpn-ip} \ + -j DNAT --to-destination ${veth-host-ip}:53 # in order to access DNS in this netns, we need to route it to the VPN's nameservers # - alternatively, we could fix DNS servers like 1.1.1.1. - ${in-ns} ${iptables} -A OUTPUT -t nat -p udp --dport 53 -m iprange --dst-range 127.0.0.53 -j DNAT --to-destination ${vpn-dns}:53 + ${in-ns} ${iptables} -A OUTPUT -t nat -p udp --dport 53 -m iprange --dst-range 127.0.0.53 \ + -j DNAT --to-destination ${vpn-dns}:53 ''; };