Accessing NATted VMs from Host machine using Port Forwarding
Usually when we create VMs in Virtualbox and select the Networking option as NAT, the IPs assigned would be 10.0.2.0/24 -
The IP address range for VMs can be managed by creating a NAT network in Virtualbox and specifying the IP range File->Preferences->Network + new nat network. Give the name and set the IP address range
Then these IP addresses that are assigned to the launched VMs are not accessible from host.
E.g. if host IP is 10.20.10.186 and VM IP is 10.0.2.15 , then you can ping 10.0.2.15 from 10.20.10.186, but the reverse is possible, i.e you can ping 10.20.10.186 from 10.0.2.15.
so now to connect to the VMs through SSH, we need to enable and configure port forwarding in virtualbox.
so go to File->Preferences->Network->NatNetwork (given name to the nat network). Then click on Port Forwarding and add rules for each VM
E.g
Rule 1 Protocol: TCP Host IP: 127.0.0.1 Host Port: 2000 Destination IP: 10.0.2.15 Dest Port: 22
Rule 2 Protocol: TCP Host IP: 127.0.0.1 Host Port: 2001 Destination IP: 10.0.2.4 Dest Port: 22
with the above rules, the host can connect to the launched VMs
E.g to connect to VM with IP 10.0.2.15, SSH to 127.0.0.1:2000
to connect to VM with IP 10.0.2.4, SSH to 127.0.0.1:2001
The IP address range for VMs can be managed by creating a NAT network in Virtualbox and specifying the IP range File->Preferences->Network + new nat network. Give the name and set the IP address range
Then these IP addresses that are assigned to the launched VMs are not accessible from host.
E.g. if host IP is 10.20.10.186 and VM IP is 10.0.2.15 , then you can ping 10.0.2.15 from 10.20.10.186, but the reverse is possible, i.e you can ping 10.20.10.186 from 10.0.2.15.
so now to connect to the VMs through SSH, we need to enable and configure port forwarding in virtualbox.
so go to File->Preferences->Network->NatNetwork (given name to the nat network). Then click on Port Forwarding and add rules for each VM
E.g
Rule 1 Protocol: TCP Host IP: 127.0.0.1 Host Port: 2000 Destination IP: 10.0.2.15 Dest Port: 22
Rule 2 Protocol: TCP Host IP: 127.0.0.1 Host Port: 2001 Destination IP: 10.0.2.4 Dest Port: 22
with the above rules, the host can connect to the launched VMs
E.g to connect to VM with IP 10.0.2.15, SSH to 127.0.0.1:2000
to connect to VM with IP 10.0.2.4, SSH to 127.0.0.1:2001
Thank you for your information.it is very nice article.
ReplyDeleteAWS Online Training