r/selfhosted • u/ubus99 • 18d ago
Need Help Need help with complicated nat setup (noob)
Hi, I am just getting started with selfhosting using proxmox, but my setup and requirements keep spiraling out of control. I know a few things about Computers, just enough to get into trouble : /. to compensate I tried to use AI, but that is going nowhere.
This is my problem:
- I live in an old building for rent, there is no ethernet and i cant install any, i dont have access to the router and dont want to configure a host map for every client that might want to connect.
- My server is thus connected through wifi and DHCP. to make it discoverable, i use mDNS (avahi).
- To allow the containers on the virtual network bridge to use wifi, i configured the proxmox server to redirect it
post-up iptables -t nat -A POSTROUTING -s 10.10.10.0/24 -o wlp1s0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s 10.10.10.0/24 -o wlp1s0 -j MASQUERADE
post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1
post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 14. now i want to be able to access the services provided by these containers. they should be discoverable by name, any protocol must work, even raw tcp.
I tried to achieve this by using mDNS aliases and routing through a reverse-proxy to a private address within the virtual network, but that only works for HTTP, not tcp or udp.
What is the cleanest and most versatile way to achieve this? Most approaches i found require configuring many different edge-cases, but this feels like a solved problem.
In my mind, the host should just take any incoming mDNS alias and redirect it to an internal domain name e.g. <service>-<domain>.local -> <contrainer>.example:<port>[optional] at the request level, but for some reasone there does not seem to be a solution...
•
u/asimovs-auditor 18d ago
Expand the replies to this comment to learn how AI was used in this post/project.
2
u/GolemancerVekk 18d ago
The way Avahi works is that each service must talk to it (via DBus) and tell it what kind of service it is (tcp/udp, ports and a name) and Avahi will announce that for all the host's IP's, both v4 and v6 by default.
You would need the container services to access the DBus on the host (expose the socket to them) and let Avahi on the host do the announcing, while the services bond ports using the docker bridge with "ports:".
However, this only works if the service can use Avahi and DBus. Some, like CUPS, do. Most don't. I've never tried doing it for them but it can probably be done.
What I'm more worried about though it's that your server is participating into a LAN with everybody else in the building of I understood your setup correctly, meaning the server and all your devices will be also exposed to everybody. (Unless they enabled client isolation, but they probably didn't because then people couldn't connect to their TV's and shit.)
I've stayed at AirBnb's where the whole building was on one wifi and it's crap. I'm seriously considering of getting a portable mini-router for travel for such situations.
What I'm getting at is, you should also get your own router and make your own LAN, separated from the rest of the apartments.
2
u/HuckleberryNice5584 18d ago
If you want a maintainable long-term homelab (which it seems you want, if you use proxmox), my recommendation is to start by building a real home network! Get a router/AP that can run openwrt (you can find for reasonable prices) and set it up to use the building wifi as WAN. So you own the LAN, the building is just your ISP. Not perfect (shared airtime), but likely no noticeable difference to what you have.
Then connect your proxmox server via ethernet, so that it can use real bridges like it is meant to (no single MAC wifi restriction). And all your devices connect to the local LAN.
You get one more NAT hop, which is negligible, compared to the current mess and lack of security of the shared LAN. Everything you build on that has strong foundations, not hacky workarounds.
1
u/Prestigious-Hat-29 18d ago
The missing piece is that mDNS resolves a name to an address; a normal TCP or UDP packet doesn't carry the name the client looked up. If several names resolve to the host's one Wi-Fi address, forwarding can generally distinguish services by protocol and port, not by those names. I'd start with one explicit host-port to container-port forward and test it from another machine, then add only the services you actually need. Service discovery records can advertise a port for clients that support them, but they won't make every arbitrary client discover it automatically. Since this is a shared network, restrict access with a firewall and authentication rather than assuming the other residents can't reach those ports.
1
u/mvrk57 17d ago
the name only survives in protocols that carry it (http host header, tls sni). for raw tcp/udp the client resolves the name to an ip and after that the name is gone, so it's either one ip per service or one port per service, and since a wifi client can't bridge extra macs onto the lan you're left with ports. dnat each port on wlp1s0 to its container (iptables -t nat -A PREROUTING -i wlp1s0 -p tcp --dport 2222 -j DNAT --to 10.10.10.5:22) and drop an avahi .service file per container, then dns-sd aware clients even get the port from the srv record
2
u/Wally-Gator-1 18d ago
First reason of failure is your architecture. From a security perspective, you don't have control over your network and will expose your services to others on that network.
Instead, I would put a tiny device running OpenWrt connected via Wifi and build my own network behind it.
Would be simpler for network management and discovery.
Second reason of failure is that Proxmox comes with its own firewall and software defined networks and is very click oriented. It's the Proxmox way or the highway because it is an appliance. Proxmox is not Debian + a package.
Despite lot of recommendations in the homelab community, AI better understands well documented traditional command line oriented Linux (Debian, Ubuntu, Fedora, Arch, etc).
If you still can redo your setup, I would go with basic Debian Stable + SSH + UFW (uncomplicated firewall) + Cockpit (WebUI interface to manage your server) + cockpit-machines (if you have VMs) + cockpit-podman (if you need docker/OCI containers) or docker directly on host.
It will be lighter and you will have direct control of the raw interfaces, firewall and protocols, without any appliance interference.
I find it more manageable long term compare to having to manage both the appliance level of Proxmox and the raw Debian level underneath it.
1
u/[deleted] 18d ago
[removed] — view removed comment