Can hostonly interface use dhcp?

Discussions about using Solaris guests in VirtualBox.
Post Reply
cseg
Posts: 6
Joined: 16. Jan 2010, 17:16
Primary OS: MS Windows XP
VBox Version: PUEL
Guest OSses: OpenSolaris

Can hostonly interface use dhcp?

Post by cseg »

I am on an XP host with an Open Solaris (JeOS) guest with VB 3.1.2 r56127.

My first nic (e1000g0) is a NAT and that looks like it is working fine. I can ssh into my guest from my host (using the three external data settings) and I can ping my host from my guest. My ifconfig looks like this:
$ ifconfig e1000g0
e1000g0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 2
inet 10.0.2.15 netmask ffffff00 broadcast 10.0.2.255
$ ifconfig e1000g1
ifconfig: status: SIOCGLIFFLAGS: e1000g1: no such interface
Now I would like to set up an hostonly adapter so that I can use create a samba share in my guest that I can access from my host.

I have made exactly two changes to support this. First, I added a second nic (e1000g1) configured for hostonly:

VBoxManage modifyvm "$VMName" --nic2 hostonly
VBoxManage modifyvm "$VMName" --hostonlyadapter2 'VirtualBox Host-Only Ethernet Adapter'
My local XP ipconfig looks (partially) like this:
ipconfig
...
Ethernet adapter VirtualBox Host-Only Network:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 192.168.56.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
[/b]
When I start my VM, my ifconfig looks like this:
$ ifconfig e1000g1
e1000g1: flags=4001000842<BROADCAST,RUNNING,MULTICAST,IPv4,DUPLICATE> mtu 1500 index 3
inet 0.0.0.0 netmask ff000000 broadcast 192.255.255.255
Now I'm a little confused. My hostonly adapter already had an IP address as shown in XP's ipconfig above. Shouldn't that interface in OpenSolaris also have an IP address? Well, it does not, so I try giving it one. First I try the same one as XP (192.168.56.1), but that doesn't work. So I try the next one (192.168.56.2):
# ifconfig e1000g1 192.168.56.2 netmask 0xffffff00 broadcast 192.168.56.255 up
e1000g1: flags=4001000842<BROADCAST,RUNNING,MULTICAST,IPv4,DUPLICATE> mtu 1500 index 3
inet 192.168.56.2 netmask ffffff00 broadcast 192.168.56.255
Well, hallelujah, that worked! I can even see 192.168.56.2 from my host.

Still, why can't I use dhcp to configure the address on e1000g1? I had tried ifconfig e1000g1 dhcp start without success. Dhcp is working on my NAT interface. Why not the hostonly one?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Can hostonly interface use dhcp?

Post by Perryg »

See VBoxManage dhcpserver, section 8.2. Commands overview of the VBox users guide.
cseg
Posts: 6
Joined: 16. Jan 2010, 17:16
Primary OS: MS Windows XP
VBox Version: PUEL
Guest OSses: OpenSolaris

Re: Can hostonly interface use dhcp?

Post by cseg »

Thank you for your response.

My host dhcp servers look like this (which is the out-of-the-box configuration):
$ VBoxManage.exe list dhcpservers
VirtualBox Command Line Management Interface Version 3.1.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

NetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter
IP: 192.168.56.100
NetworkMask: 255.255.255.0
lowerIPAddress: 192.168.56.101
upperIPAddress: 192.168.56.254
Enabled: Yes
My /etc/nwam/llp looks like this:
$ cat /etc/nwam/llp
e1000g0 dhcp
e1000g1 dhcp
My NAT interface (e1000g0) obtains an IP address, but my hostonly interface does not:
$ ifconfig e1000g0
e1000g0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 2
inet 10.0.2.15 netmask ffffff00 broadcast 10.0.2.255
$ ifconfig e1000g1
e1000g1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
inet 0.0.0.0 netmask ff000000 broadcast 0.255.255.255
Now I see that my NAT (e1000g0) is getting a address which is outside of the range of my dhcp server (?).

Am I not using the VB dhcpserver?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Can hostonly interface use dhcp?

Post by Perryg »

Here is what I get.
perry@opensolaris:~$ ifconfig e1000g0
e1000g0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 2
inet 10.0.2.15 netmask ffffff00 broadcast 10.0.2.255
perry@opensolaris:~$ ifconfig e1000g1
e1000g1: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 3
inet 192.168.56.101 netmask ffffff00 broadcast 192.168.56.255
perry@opensolaris:~$ ping 192.168.56.68
192.168.56.68 is alive This is the host address for host-only
perry@opensolaris:~$ ping yahoo.com
yahoo.com is alive
perry@opensolaris:~$
By default OpenSolaris is set to automatic network configuration which is good for most things but I could not get two adapters to work that way. I switched it to manual and activated both interfaces at the same time. (System -> Network) The first adapter is e1000g0 and is set to NAT, the second one e1000g1 is set to Host-Only both using DHCP.
cseg
Posts: 6
Joined: 16. Jan 2010, 17:16
Primary OS: MS Windows XP
VBox Version: PUEL
Guest OSses: OpenSolaris

Re: Can hostonly interface use dhcp?

Post by cseg »

Thank you. I have switched over to "classic" dhcp and I can get my two interfaces working with dhcp.
:> /etc/hostname.e1000g0
:> /etc/dhcp.e1000g0
:> /etc/hostname.e1000g1
:> /etc/dhcp.e1000g1
/usr/sbin/svcadm disable svc:/network/physical:nwam
/usr/sbin/svcadm enable svc:/network/physical:default
However, OpenSolaris appears to be using my network dhcp and not the VB dhcp.

How do I get my VM to use VB's dhcpserver and not my network dhcp server?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Can hostonly interface use dhcp?

Post by Perryg »

See section 6.6. Host-only networking & 8.28. VBoxManage dhcpserver in the VirtualBox Users Guide.
cseg
Posts: 6
Joined: 16. Jan 2010, 17:16
Primary OS: MS Windows XP
VBox Version: PUEL
Guest OSses: OpenSolaris

Re: Can hostonly interface use dhcp?

Post by cseg »

"For host-only networking, like with internal networking, you may find the DHCP server useful that is built into VirtualBox. This can be enabled to then manage the IP addresses in the host-only network since otherwise you would need to configure all IP addresses statically."

So it sounds like VB's dhcp server is only available to host-only interfaces (and "internal networking"). Since I don't see any mention of DHCP in the NAT section, I am correct in understanding that a NAT interface can only with your network's DHCP server and not the VB's dhcpserver?

What if you don't have a DHCP server on your network? How will your NAT interface get an address?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Can hostonly interface use dhcp?

Post by Perryg »

The NAT interface receives the same address all the time. It is built into VBox. It will always be the same.
It does not join the domain or the dhcp server of any other OS. That is the reason for NAT. To be able to run several OSes as guest and not conflict with addressing schemes, and is used to be able to get Internet access for the guest. VBox has its own built in router to achieve this. You can tune the NAT server by reading 9.14. Fine-tuning the VirtualBox NAT engine

It's all covered here 6.3. Network Address Translation (NAT)
cseg
Posts: 6
Joined: 16. Jan 2010, 17:16
Primary OS: MS Windows XP
VBox Version: PUEL
Guest OSses: OpenSolaris

Re: Can hostonly interface use dhcp?

Post by cseg »

OK, I have moved my windows host into an environment which is not using dhcp.

VB has one dhcpserver active as indicated by this command:
$ VBoxManage.exe list dhcpservers
VirtualBox Command Line Management Interface Version 3.1.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

NetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter
IP: 192.168.56.100
NetworkMask: 255.255.255.0
lowerIPAddress: 192.168.56.101
upperIPAddress: 192.168.56.254
Enabled: Yes
I am freshly loaded the OVF for OpenSolaris JeOS (http://dlc.sun.com/osol/jeos/2009/osol- ... ox-ovf.zip) using this command:
$ VBoxManage import "$jeosOVFFile" \
--vsys 0 --ostype OpenSolaris \
--vsys 0 --vmname "$vmName"
Unlike my previous scenario, the vanilla distribution of OpenSolaris JeOS uses a bridged nic:
$ VBoxManage.exe showvminfo "$vmName" | grep "NIC 1"
NIC 1: MAC: 0800270EAE20, Attachment: Bridged Interface 'Broadcom 802.11a/b/g WLAN', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps
When I boot this VM in an environment which has a dhcp server, it uses the available dhcp server to get an address for the bridge nic.

However, when I boot this VM in an environment which does not have a dhcp server (my current environment), the interface does not get an address:
$ ifconfig e1000g0
e1000g0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 2
inet 0.0.0.0 netmask ff000000
The "VBoxManage dhcpserver" section of the user manual says:

"(Theoretically, you can enable [the VBox dhcp server] for a bridged network as well, but that will likely cause conflicts with other DHCP servers in your physical network.)"

This is exactly what I want to do and since I don't have a local dhcp server there should be no conflicts. But I don't see any instructions in the user manual.

How do I get a bridged nic to use the VBox dhcpserver?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Can hostonly interface use dhcp?

Post by Perryg »

You say that you have moved this to an environment where you do not have a dhcp server. Does it have a router?
If yes then what is the address range of that network?
You would need to change the VirtualBox dhcp server to be in that range for it to work.
cseg
Posts: 6
Joined: 16. Jan 2010, 17:16
Primary OS: MS Windows XP
VBox Version: PUEL
Guest OSses: OpenSolaris

Re: Can hostonly interface use dhcp?

Post by cseg »

Of course. That makes sense: the bridged network adapter is on the physical network and so it must have an IP address compatible with that network.

I found that if I changed the bridged network interface to a hostonly network interface using these commands:
$ VBoxManage modifyvm "$vmName" --nic1 hostonly
$ VBoxManage modifyvm "$vmName" --hostonlyadapter1 'VirtualBox Host-Only Ethernet Adapter'
(I'm not sure if I need both commands but it works...)

that I get exactly the behavior that I'm looking for: the VBox's internal dhcpserver is used whether I'm on a physical network that has dhcp or not.

Thank you!
Post Reply