12 Replies Latest reply: Apr 28, 2012 1:32 PM by EdStevens RSS

    VirtualBox - somewhat off-topic

    EdStevens
      I know this is somewhat off-topic, but I'm hoping there's some expertise here that will be a bit more helpful than when I asked this on the VirtualBox forums.

      For a coupe of years now I've been running my own private test lab on my laptop, using VMworkstation. It's been working to my satisfaction, but with all the recommendations to use VirtualBox (after all, it's free) I thought I'd give it a try. This was a few months back, and I ran into a real problem with the way VB appears to handle networking vs. VMware.

      With VMware, I set all my virtual machines to use NAT. This allows me to give the vm a fixed IP address, not reveal itself outside the host OS, and still reach the internet for things like yum updates. Obviousely, bridged network would allow me to access the inernet, but would make me have to play by the rules of whatever network I'm on -- my company or my home ISP. Host only would address that but not allow me to pull updates from the internet.

      Now, with VirtualBox, I couldn't get NAT to work with a fixed IP address that I assigned to the vm. The guys at the VB forum couldn't seem to understand why that was an issue. They just kept saying to allow the vm to use a DHCP assigned address and 'everything just works'.

      I don't have VB installed at the moment, so can't re-run tests, but thought I'd throw this out to see if it rings a bell with anyone, and if so if there might be a solution. I still tend to believe VB will do a fixed guest IP with NAT and I just wasn't seeing how to make it work, but perhaps not.

      Comments?
        • 1. Re: VirtualBox - somewhat off-topic
          Catch-22
          In NAT mode, the guest network interface is assigned to the IPv4 range 10.0.x.0/24 by default where x corresponds to the instance of the NAT interface +2. So x is 2 when there is only one NAT instance active. In that case the guest is assigned to the address 10.0.2.15, the gateway is set to 10.0.2.2 and the name server can be found at 10.0.2.3.

          If, for any reason, the NAT network needs to be changed, this can be achieved with the following command:

          VBoxManage modifyvm "VM name" --natnet1 "192.168/16"

          This command would reserve the network addresses from 192.168.0.0 to 192.168.254.254 for the first NAT network instance of "VM name". The guest IP would be assigned to 192.168.0.15 and the default gateway could be found at 192.168.0.2.

          I suggest to review the documentation for more details

          http://www.virtualbox.org/manual/ch06.html
          • 2. Re: VirtualBox - somewhat off-topic
            EdStevens
            Dude wrote:
            In NAT mode, the guest network interface is assigned to the IPv4 range 10.0.x.0/24 by default where x corresponds to the instance of the NAT interface +2. So x is 2 when there is only one NAT instance active. In that case the guest is assigned to the address 10.0.2.15, the gateway is set to 10.0.2.2 and the name server can be found at 10.0.2.3.

            If, for any reason, the NAT network needs to be changed, this can be achieved with the following command:

            VBoxManage modifyvm "VM name" --natnet1 "192.168/16"

            This command would reserve the network addresses from 192.168.0.0 to 192.168.254.254 for the first NAT network instance of "VM name". The guest IP would be assigned to 192.168.0.15 and the default gateway could be found at 192.168.0.2.

            I suggest to review the documentation for more details

            http://www.virtualbox.org/manual/ch06.html
            Sorry for the delayed response. I've just now re-installed VBox and created a 64-bit Oracle Linux 5.7 machine.

            After reading yet again the networking chapter in the VBox user manual, I'm afraid I'm just as confused as ever. Perhaps if I detail exactly how I'm used to setting things up with VMware and the resulting behavior, we can see the corollary for VBox.

            When I install VMware, it creates two network adapters on the host OS, vmnet1 and vmnet8. vmnet8 is used for NAT. I've installed on several machines and vmnet8 is always assigned an address of 192.168.something.1. The 'something' seems to vary from install to install. I'm not sure what controls the assigned value there, but have never really needed to explore that. My current setup is at 192.168.111.1.

            Next, I create a virtual machine. There I configure eth0 to use a fixed IP address of 192.168.xxx.yyy, where 'xxx' matches the value of the vmnet8 adapter on the host os, and 'yyy' is assigned sequentially, starting with 101 for the first machine I create, 102 for the next, etc. When creating these machines, I've found I have to set the gateway and DNS address to 192.168.xxx.2.

            With that setup,
            - my guest vm can ping the host
            - the host can ping the guest vm
            - I can create an entry in the host os's 'hosts' file pointing to the guest vm (ie: 192.168.111.101 vmlnxsrv01.vmdomain vmlnsxrv01), then use that name to refer to the vm
            - I can use an ssh client like putty (on the host os) to connect to the vm, exactly like I would connect to a remote box on my company's network
            - The vm can reach the internet to do web browsing, download rpms, etc.


            Now, when i installedVbox, it created one additional network adapter on the host os. It is running at 192.168.56.1
            I created the virtual machine, giving it a fixed IP address of 192.168.56.111, gateway and dns address of 192.168.56.2
            Ping of the vm ip address from the host returns 'host unreachable' doesn't work either direction
            C:\Users\ed>ping 192.168.56.111
            
            Pinging 192.168.56.111 with 32 bytes of data:
            Reply from 192.168.56.1: Destination host unreachable.
            
            Ping statistics for 192.168.56.111:
                Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
            Control-C
            ^C
            Same from the other end, pinging 192.168.56.1 and 192.168.56.2 from the vm

            Tried the vboxmanage, but not sure if I gave it the correct parameters.
            C:\Program Files\Oracle\VirtualBox>vboxmanage modifyvm "lnxsrv11" --natpf1 "gue
            tssh,tcp,,2222,192.168.56.111,22"
            
            C:\Program Files\Oracle\VirtualBox>ping 192.168.56.111
            
            Pinging 192.168.56.111 with 32 bytes of data:
            Reply from 192.168.56.1: Destination host unreachable.
            Also at this point, an attempt to establish a putty session to 192.168.56.111 times out.
            • 3. Re: VirtualBox - somewhat off-topic
              Catch-22
              NAT is typically used to enable a private network to be able to communicate with a public network by translating the IP address. You can configure NAT to forward traffic from your NAT device to your internal network, but you cannot directly address an IP number that is behind a NAT device. NAT hides the IP address space behind it. When you connect using NAT to another machine, the other machine will only see the IP address of the the NAT device.

              Perhaps you can explain in more detail what you are trying to accomplish, but if your goal is to create a separate network for your virtual machine, you can simply bridge your network by creating a VirtualBox bridged adapter and assign it the IP address you desire. It will operate side by side with your host adapter and work based on standard IP broadcast and routing rules and guidelines.
              • 4. Re: VirtualBox - somewhat off-topic
                EdStevens
                Dude wrote:
                NAT is typically used to enable a private network to be able to communicate with a public network by translating the IP address. You can configure NAT to forward traffic from your NAT device to your internal network, but you cannot directly address an IP number that is behind a NAT device. NAT hides the IP address space behind it. When you connect using NAT to another machine, the other machine will only see the IP address of the the NAT device.

                Perhaps you can explain in more detail what you are trying to accomplish, but if your goal is to create a separate network for your virtual machine, you can simply bridge your network by creating a VirtualBox bridged adapter and assign it the IP address you desire. It will operate side by side with your host adapter and work based on standard IP broadcast and routing rules and guidelines.
                Sorry my replies are delayed. I'm only able to chip at this on a sporadic basis.

                Here's my bottom line requirement
                1 - guest vm must have a fixed ip.
                2 - guest vm must be able to reach the internet for browsing and downloading (mostly to access a yum server)
                3 - guest vm must be invisible to company network nazis. (that's why I'm trying to use NAT)
                4 - Host OS must be able to talk to guest vm, just as if it were any other server on the network. Using putty for the linux vm, Remote Desktop for the Windows vm.

                To achive this with VMworkstation, I simply give the guest vm an ip address that is in the same subnet as the VMnet8 network adapter on the Host, to wit:
                1 - host os (win7 home premium) reports the following:
                Ethernet adapter VMware Network Adapter VMnet8:
                
                   Connection-specific DNS Suffix  . :
                   Link-local IPv6 Address . . . . . : fe80::6106:652f:ec9:da9d%15
                   IPv4 Address. . . . . . . . . . . : 192.168.111.1
                   Subnet Mask . . . . . . . . . . . : 255.255.255.0
                   Default Gateway . . . . . . . . . :
                and on the vm guest
                [root@lnxsrv01 ~]# ifconfig
                eth0      Link encap:Ethernet  HWaddr 00:0C:29:C3:F2:F0
                          inet addr:192.168.111.101  Bcast:192.168.111.255  Mask:255.255.255.0
                          inet6 addr: fe80::20c:29ff:fec3:f2f0/64 Scope:Link
                          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                          RX packets:21415 errors:0 dropped:0 overruns:0 frame:0
                          TX packets:1481 errors:0 dropped:0 overruns:0 carrier:0
                          collisions:0 txqueuelen:1000
                          RX bytes:1939838 (1.8 MiB)  TX bytes:177090 (172.9 KiB)
                
                lo        Link encap:Local Loopback
                          inet addr:127.0.0.1  Mask:255.0.0.0
                          inet6 addr: ::1/128 Scope:Host
                          UP LOOPBACK RUNNING  MTU:16436  Metric:1
                          RX packets:8213 errors:0 dropped:0 overruns:0 frame:0
                          TX packets:8213 errors:0 dropped:0 overruns:0 carrier:0
                          collisions:0 txqueuelen:0
                          RX bytes:490344 (478.8 KiB)  TX bytes:490344 (478.8 KiB)
                Also, when setting up the vm I specified default gateway and dns server both as 192.168.111.2. Not really sure, when starting out I would have thought 192.168.111.1, but that's what it took to make it work. (there is no dns server, but the linux setup wouldn't let me NOT specify one.)

                The vmnet config tool shows VMnet8 is NAT with a subnet address of 192.168.111.0 and a gateway address of 192.168.111.2

                and that's pretty much it. All of my above requirements are satisfied.
                • 5. Re: VirtualBox - somewhat off-topic
                  Tommyreynolds-Oracle
                  Give the VirtualBox guest two NIC's:
                  1) Regular NAT interface; it will leverage the host's IP address to get to Internet.
                  2) Host-only network. In a host-only network, you can use fixed IP addresses, so stuff like RDBMS is happy, and the network is visible only to the physical host and any VBOX guests you permit.
                  • 6. Re: VirtualBox - somewhat off-topic
                    Catch-22
                    According to my research, VMware Server always bridges the default network device on your hosts and therefore you have direct network access from the host to your machine behind the NAT interface. To my knowledge, this does not exist in VirtualBox.

                    You can create a network adapter choosing "host only", which will allow you setup your machines as desired, but the virtual machine will not be able to access the internet beyond your host network.
                    • 7. Re: VirtualBox - somewhat off-topic
                      Tommyreynolds-Oracle
                      You can create a network adapter choosing "host only", which will allow you setup your machines as desired, but the virtual machine will not be able to access the internet beyond your host network.
                      Yup, that's why I suggested two NIC's; virtual NIC's are cheap :)
                      • 8. Re: VirtualBox - somewhat off-topic
                        Catch-22
                        I thought about that too, but then one pretty much ends up the same as creating a bridged network in the first place, or not?
                        • 9. Re: VirtualBox - somewhat off-topic
                          Catch-22
                          This might be interesting:

                          http://www.linuxjournal.com/content/tech-tip-port-forwarding-virtualbox-vboxmanage
                          • 10. Re: VirtualBox - somewhat off-topic
                            Catch-22
                            Sorry, I guess I see what you mean now.

                            .... to create 2 adapters inside VirtualBox, one for NAT (DHCP) and one or private (host-only).

                            Well that works, I just tried it. You were right.

                            In the VirtualBox Application preferences I created a new network adapter "vboxnet0" for host-only.
                            It allows me to set the IP address, e.g. 192.168.56.1/255.255.255.0

                            In the virtual machine settings I create 2 network adapters:
                            1. NAT
                            2. host only, using vboxnet0

                            In the guest OS I selected:
                            eth0: DHCP
                            eth1: 192.168.56.100/255.255.255.0

                            I can access 192.168.56.100 from my host at 10.0.0.1 and vice versa without any issues
                            It is important not to set any default IP Gateway for eth1, otherwise NAT will fail.
                            • 11. Re: VirtualBox - somewhat off-topic
                              EdStevens
                              Dude wrote:
                              According to my research, VMware Server always bridges the default network device on your hosts and therefore you have direct network access from the host to your machine behind the NAT interface. To my knowledge, this does not exist in VirtualBox.
                              Sounds like that may be the key right there.

                              A lot to digest and try in this latest spate of responses. Let me work on it and I'll get back.
                              You can create a network adapter choosing "host only", which will allow you setup your machines as desired, but the virtual machine will not be able to access the internet beyond your host network.
                              • 12. Re: VirtualBox - somewhat off-topic
                                EdStevens
                                Ok, finding time to address this again. Dude and Tommy, I really appreciate your input. With your help I was finally able to crack this one.

                                Here's what I've done and where I stand at the moment.

                                Created a fresh VM with OL 5.7 64-bit, pretty much default all the way. Eth0 is NAT and I can run firefox on the vm and get to various locations on the web. So far so good.
                                Next I shut the vm down and added another NIC, eth1. Started the vm, conifgured eth1 as host-only and assigned an ip of 192.168.156.111, mask 255.255.255.0. I chose that IP address because when I check the adapters running on the host, the vbox adapter shows as this, and it seemed to make sense that the guest OS should have an ip on the same subnet.
                                Ethernet adapter VirtualBox Host-Only Network:
                                
                                   Connection-specific DNS Suffix  . :
                                   Link-local IPv6 Address . . . . . : fe80::9878:bcd3:f0ed:afde%20
                                   IPv4 Address. . . . . . . . . . . : 192.168.56.1
                                   Subnet Mask . . . . . . . . . . . : 255.255.255.0
                                   Default Gateway . . . . . . . . . :
                                After that I restarted the net services and re-tested. The guest was able to browse the web, the host was able to ping the guest, I could connect from the host to the guest with puTTY, and run xclock with the output redirected back to the host (using xming as my xserver on the host). While the method of configuration wasn't exactly the same as with VMware, it does make sense and the end result is exactly what I need. This is the furthest I've ever gotten with VBox, and while I've still got a few issues to iron out, this was a huge leap forward.