Proxying traffic to VMs from one IP

  • Thread starter Thread starter Deleted member 149439
  • Start date Start date
D

Deleted member 149439

Guest
I've got a bit of a weird setup with my server networking. I have one public IP address, a Proxmox system, and some VMs. All of them need to have specific routing to each other, and I'm using Caddy for this on the main Proxmox machine. This setup is necessary due to only having that one IP and routing everything from there. So my question is, how would I set up Caddy or some other tool to redirect traffic to certain VMs depending on the subdirectory, and more generally TCP/UDP traffic. Any help with this is greatly appreciated.
 
I'm not familiar with Caddy but this is the sort of question that gets asked a lot.

There are two ways to approach this
1. is via custom ip-tables commands in your /etc/network/interfaces file - e.g
Code:
post-up   echo 1 > /proc/sys/net/ipv4/ip_forward
post-up   iptables -t nat -A POSTROUTING -s 172.16.100.0/24 -o ens16 -j SNAT --to-source <public-ip>
post-down iptables -t nat -D POSTROUTING -s 172.16.100.0/24 -o ens16 -j SNAT --to-source <public-ip>
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 1
post-up   iptables -t nat -A PREROUTING -i ens16 -p tcp --dport 80 -j DNAT --to 172.16.100.2:80
post-up   iptables -t nat -D PREROUTING -i ens16 -p tcp --dport 80 -j DNAT --to 172.16.100.2:80

where your virtual machines are on a 172.16.100.0 network and the public-ip is on ens16

2. is via a virtual machine running a firewall/router such as pfSense
1650221587747.png

If you need to host multiple websites behind one public IP you would need additional software such as nginx
https://github.com/nginx