Need to run dhclient on guest to get ipaddress in NAT mode

Discussions about using Linux guests in VirtualBox.
Post Reply
TheFunkSoulBrother
Posts: 1
Joined: 18. Apr 2022, 18:32

Need to run dhclient on guest to get ipaddress in NAT mode

Post by TheFunkSoulBrother »

Hi,

I'm a bit new to networking in general, and very new to Oracle VirtualBox. I ran into something I don't understand, and was wondering if someone can explain to me what is going on.

I'm running Ubuntu 20.04.4 LTS (Focal Fossa) on my host. Installed VirtualBox from the default Ubuntu repo (version 6.1). I've created a VM based on Centos 7.9, with all the default settings. When I run the VM, I can't communicate out (e.g. pinging google doesn't work). When I run ip a show, I get the following output:

Code: Select all

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/ether 08:00:27:89:cc:31 brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:e7:63:59 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:e7:63:59 brd ff:ff:ff:ff:ff:ff
After running `dhclient`, it does work, and I get the following output.

Code: Select all

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/ether 08:00:27:89:cc:31 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3
       valid_lft 86308sec preferred_lft 86308sec
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:e7:63:59 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:e7:63:59 brd ff:ff:ff:ff:ff:ff
It seems the guest doesn't contact the DHCP server automatically or something?
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Need to run dhclient on guest to get ipaddress in NAT mode

Post by scottgus1 »

Looks like we missed this one.

If I gather correctly, your VM's OS does not get an IP address unless you run a 'dhclient' command inside the VM.
TheFunkSoulBrother wrote:2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/ether 08:00:27:89:cc:31 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24
The 10.0.2.15 IP address the VM sees is the default for Virtualbox's NAT type of network, default because it's the easiest to use because it always works.

So far this appears to be an issue in the OS inside the VM, not in Virtualbox.

Please try an Ubuntu VM with the usual Ubuntu or Mint ISO, see if it gets an IP automatically.
Post Reply