Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I hope this is the correct place for this question. I thought about posting it to Super User first, but it seems to be more relevant to this place. Anyway, here goes:

I need to connect a device plugged into a physical ethernet port of my workstation to an existing virtual switch. The physical device and a VM need to share the same network, both need to be connected to the internet via NAT and a second network adapter of my PC.

As a picture often is better than a thousand words, here is a little ASCII art drawing of what I want to achieve:

                        The internets!
                              |
                             __
                            |  |   router, 
                          __|__|__ firewall, etc.
                              |
           ___________________________________________________________
          |                       |        |        |        |        |  
         __
        |  |                        (other machines on the physical network)
      __|__|__  my workstation
          |     (doing NAT)
     ___________
    |           |
   __          __
  |  |        |  |
__|__|__    __|__|__
physical    virtual
device      machine

I can't simply connect the physical device to a physical switch and bridge the VM into the main network because for my testing the VM needs to run a DHCP server among other things, and the admins would be coming after me with torches and pitchforks if I put a rogue DHCP server into our main network.

My problem is, I have absolutely no idea what I need to do to "plug" the physical port into the virtual switch, and I would be grateful for any input on how to do it.

If this isn't possible with VMware Player or Workstation, is there other software able to do what i want? Virtualbox, maybe?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Hmm. I believe that your best bet may be to bridge your VM onto the private network NIC that your physical device is connected to and use NAT (Internet connection sharing in Windows, iptables in Linux) to provide internet access to the two boxes.

I'll try to elaborate.. I apologize in advance for not being very good with descriptions:

  • Configure the NIC in the PC for the private network. Here is where you'd want to set up the internet connection sharing if you're using windows. How that's done depends on what version of windows you're running. If you're not running windows, there's iptables NAT in Linux. I'm not familiar enough with OSX to know how to set up NAT. I suspect it's similar to Linux. Another search on here should provide information on how to do this. (EDIT: For Windows, as soon as you share the connection of your NIC in the public network to the one in the private network, the NIC in the private network is assigned a static IP address by windows which doesn't neccessarily match your private network's configuration. Just change the IP accordingly and also set your computer's IP in the private network as the preferred DNS server and you're good to go. – Tobias Gies)

  • Plug your physical device into a switch or directly to your PC with a crossover cable. I would suggest using a small switch - that is just personal preference, though. IP your physical device as appropriate on the private network with a default gateway pointing to the private network IP of your PC.

  • Place the network adapter of the VM in bridged mode onto the private network NIC and give your VM an IP in the private network range with a default gateway pointing to the private network IP of the PC.

In theory, if you have the NAT set up correctly, you should have a completely private network with the VM and physical device, while still providing internet access to both. This keeps your DHCP server off of the public network, and keeps the pitchfork-laden admins away. :)

share|improve this answer
    
That sounds like it might just work. I'll try that and report back - it's probably going to be next week before I can get to it though. Thanks! –  Tobias Gies Jul 15 '11 at 7:59
    
I hope it works out! –  haymaker Jul 17 '11 at 7:44
    
It worked exactly like you described! One thing to take note of for people who want to reproduce this: As soon as you share the connection of your NIC in the public network to the one in the private network, the NIC in the private network is assigned a static IP address by windows which doesn't neccessarily match your private network's configuration. Just change the IP accordingly and also set your computer's IP in the private network as the preferred DNS server and you're good to go. –  Tobias Gies Jul 18 '11 at 15:01
    
Glad it worked! I edited the answer, adding that note for Windows hosts. –  haymaker Jul 19 '11 at 0:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.