I have an Ubuntu VM (in Virtualbox) and a Win11 local machine.
I would like to send HTTP requests (for example 127.0.0.1:{PORT}/api/1/) to the virtual machine. The VM has an app running that only accepts requests to localhost, so I need to send the request from local to guest, and redirect the request in the VM to its localhost. I also need to achieve this using Iptables.
I have tried a bunch of iptables commands but without any success. I am getting "request timed out" or "connrefused" errors. Meanwhile I am able to run simple python servers on both machines and I am able to curl them from both local and vm.
In my understanding I need to configure Iptables inside the VM to accept requests to its IP and some port, but forward them to localhost and the needed port. But I struggle to implement this anyway.
I've tried variations of this command, but I believe this is closer to how it should look like (first I enable port forwarding):
sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp 80 -j DNAT --to-destination
127.0.0.1:4040
In my understanding if now I send a request from my host like this, then the vm should receive this request and re-route it to its localhost port 4040, and I should receive the response from API: curl 172.20.10.4:80/api/v1/... But nothing happens, I get "request timed out". If I curl the "172.20.10.4:80", nothing happens too
Thank you in advance!
history
.