NAT Network and internet impossible ?

This is for discussing general topics about how to use VirtualBox.
Post Reply
Hortiks
Posts: 4
Joined: 29. Sep 2021, 11:24

NAT Network and internet impossible ?

Post by Hortiks »

Hello,
with some researches, i found that apparently, it was not possible to get a configuration in NAT network + internet.
I would get your opinion about this.

The configuration that i'm trying to create is :
-a network of 3 VMs on a network 192.168.122.x/24 being able to communicate each other
-get access to internet to communicate and use SSH

For the 1st part, it's easy with the wizard virtualbox and the NATNetwork option, but after, i'm stuck.

Thanks for the answers.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: NAT Network and internet impossible ?

Post by mpack »

"NAT network" should have no problem providing Internet access to VMs, provided of course that the host has Internet access - since NAT simply uses the host connection.

What is the guest OS?

Btw, if you create a NAT network they will be using 10.x.x.x addresses, not 192.168.x.x. NAT network is its own little isolated virtual network. Don't be misled into believing that the address has to be compatible with your home network, which none of your VMs are using. Inappropriate assignment of addresses would usually result in failure at best, messing up your home network at worst.

I suggest that you simply create the NAT network and not mess with it. Leave messing until after you have it working, so at least then you can know which change killed it.
Hortiks
Posts: 4
Joined: 29. Sep 2021, 11:24

Re: NAT Network and internet impossible ?

Post by Hortiks »

Hello again,
1st, thanks for the answer :)

The guest OS is a Debian 9 (goal = nodeManager with GUI), and CentOS 7 for 2 others machines of test on the network.

You are right, i modified the
/etc/network/interfaces for the Debian 9 to fix the IP, i guess it could come from this,

and i did similar with the CentOS 7 with file
/etc/sysconfig/network-scripts/ifcfg-eth1:0

After a new VM of the Debian 9, i've internet access with IP 10.0.0.20/24
But is it possible to change the IP to create its own parameters and keep access to internet ?

PS: final goal = 3 machines (1 nodeManager, 2 machines test) on the same network, being able to communicate each other, and with internet access + SSH
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: NAT Network and internet impossible ?

Post by mpack »

Hortiks wrote: After a new VM of the Debian 9, i've internet access with IP 10.0.0.20/24
But is it possible to change the IP to create its own parameters and keep access to internet ?
As I already mentioned, NAT networking gives you Internet access out of the box. The IP address isn't relevant to this.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: NAT Network and internet impossible ?

Post by scottgus1 »

Actually, NAT Network will start failing to provide internet if the IP address range of the NAT Network is changed after the Network is used for the first time. See Virtualbox Networks: In Pictures: NAT network , especially the point about the DHCP server not following the IP range change.

I'd recommend a new NAT Network, set to a desired IP address range if necessary for your project before using a VM attached to it, attach all your VMs to it, and check that the VMs are set to get IP info from DHCP.
Hortiks
Posts: 4
Joined: 29. Sep 2021, 11:24

Re: NAT Network and internet impossible ?

Post by Hortiks »

You are right when you[mpack] say that "The IP address isn't relevant to this" but for my tests, it's important.
After some researches, i found the solution that [scottgus1] recommended in the previous message, i created a new NAT network with the DHCP in 192.168.122.0/24.

in cmd :
cd <path_to_virtualbox>
VBoxManage natnetwork add --netname natnet1 --network "192.168.122.0/24" --enable

Parametered my 3 VMs to NAT network on "natnet1" previously created, and it worked.
BTW, if like me, you have a VM on CentOS and configured with a DHCP, you'll have to change the default network name enp0s3 to eth0

Just last question :
do you know if it's possible to restrict the range of the DHCP on the NAT network ?
in my case, it starts to 6 (192.168.122.6) and ideally, i would start by 10 (192.168.122.10)

Thanks for the answers.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: NAT Network and internet impossible ?

Post by scottgus1 »

Apparently, adjusting the NAT Network's DHCP server can only be done by command line: see https://www.virtualbox.org/manual/ch08. ... dhcpserver

This will show you what DHCP servers your Virtualbox has now, and the "NetworkName" that is used in the "modify" command below:

Code: Select all

vboxmanage list dhcpservers
Then this one might edit the range:

Code: Select all

VBoxManage dhcpserver modify < --network=netname | --interface=ifname > [--server-ip=address] [--lower-ip=address] [--upper-ip=address] [--netmask=mask] [ --enable | --disable ]
Probably best to run a "vboxmanage list dhcpservers" after the "modify" to see if the change took.
Hortiks
Posts: 4
Joined: 29. Sep 2021, 11:24

Re: NAT Network and internet impossible ?

Post by Hortiks »

Thanks a lot, it's working perfectly :)

PS: it's my 1st time on the forum, tell me if i've to "close the topic, or similar"
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: NAT Network and internet impossible ?

Post by scottgus1 »

Glad you're up and running!

No need to close the topic, it can be just as it is.
Post Reply