Port Forwarding for Client/Server on VMs on Different Subnets

This is for discussing general topics about how to use VirtualBox.
Post Reply
VysePresident
Posts: 1
Joined: 7. Nov 2022, 10:27

Port Forwarding for Client/Server on VMs on Different Subnets

Post by VysePresident »

Hello, I am new to both VirtualBox and networking in general, and attempting to learn. I've read up on the documentation & searched online for information, but I'm quite overwhelmed and would greatly appreciate some guidance.

I am attempting to create two independent subnets, one of which will contain a client node and the other of which will contain some number of server nodes (One server for now, ideally two later). I want my client to be able to communicate with all server nodes through a socket program in Python by first sending and receiving a message and then printing the server ip addresses. I am very new to networking and my hope is to try to gain a better understanding of communication between subnets in particular.

As part of this, my goal is for the client to be able to communicate with the server without knowing the port number from which the server is listening. I tried using NAT Networks to achieve this & easily created two subnets, but it appears that to set port forwarding rules, you cannot simply forward from all incoming ports. You have to set rules for each individual port.

Would it be better to try using bridging or some other method instead? Or is there a way to use NAT Networks to achieve what I want? If I have to use a method like bridging, if anyone has any newbie-friendly resources on how to set that up, I would be immensely grateful.

For context, I am a student trying to finish an extra credit project in a challenging class. While I have a lot of leeway in what sources I can use, I'm only looking for guidance on using VirtualBox - specifically on how to handle port forwarding between two virtual machine subnets. I mention this detail mainly because it means that the parameters of my project can't really be changed to something simpler.

My thanks to anyone who responds.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Port Forwarding for Client/Server on VMs on Different Subnets

Post by scottgus1 »

Networking works in Virtualbox the same way it works in real PCs, as long as you get the correct Virtualbox network type. See Virtualbox Networks: In Pictures
VysePresident wrote:create two independent subnets, one of which will contain a client node and the other of which will contain some number of server nodes (One server for now, ideally two later). I want my client to be able to communicate with all server nodes
Does "two independent subnets" mean something like 172.16.0.0/24 and 10.0.0.0/24 both operating on the same network switch & cables? Or does it mean two separate sets of network hardware, both connected to the client? And will the host also communicate into this test network?

Can you please draw a picture of what you want the setup to look like, then we can possibly guide you to the correct Virtualbox networking setup. Use Upload Attachment to post the picture.
Post Reply