Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Can more than 1 VM share a physical NIC?

  1. #1
    Join Date
    Sep 2007
    Beans
    284

    Can more than 1 VM share a physical NIC?

    Hi everyone,

    Can 2 VM's share the same NIC?

    Let's say I have VM1 running linux, and VM2 runnig Windows. Do I need separate NICs for them or can they share the same physical NIC without problems? Thanks

  2. #2
    Join Date
    Jan 2007
    Beans
    720
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Can more than 1 VM share a physical NIC?

    Your VMs can share the same NIC. In virtualbox the default is to use NAT; another option is bridged. There are other options as well, which I won't get into here. Other VM managers like VMWare work in a similar way.

    With NAT, each VMs is put behind a virtual router and it gets a private IP from that virtual router. You can set up port forwarding to access ports on the VMs from outside if you desire. Another option is NAT Network, where you give the network a name and then the virtual router is shared by multiple VMs using the same NAT network so they can see each other.

    With bridged, each VM connects directly to your NIC with its own MAC address, so it's like having a virtual switch connected to your NIC. Each VM gets an IP on your network either from your network's DHCP server, or statically assigned. In this mode it's like each VM is a separate physical machine that has an IP on your network.

    You can also create virtual networks that don't use a physical NIC at all, so VMs can see each other without having any access to the real LAN. You can also have multiple NICs per VM... one that connects to the real NIC and others that are virtual. You could even run PFSense or iptables/ufw on a VM acting as a firewall for other VMs. The sky's the limit, and it's handy for testing different network scenarios or to isolate VMs from each other or the network at large.
    Last edited by kpatz; 1 Week Ago at 02:40 PM.
    Current 'buntu systems: Server 18.04.2 LTS, Mythbuntu 16.04 LTS, Ubuntu 16.04.1 LTS / Retired: 14.04 LTS, 10.04 LTS, 8.04 LTS
    Been using ubuntu since 6.04 (13 years!)

  3. #3
    Join Date
    Sep 2007
    Beans
    284

    Re: Can more than 1 VM share a physical NIC?

    Thank you so much! This is the best answer I have ever gotten.

  4. #4
    Join Date
    Sep 2007
    Beans
    284

    Re: Can more than 1 VM share a physical NIC?

    Is there any particular reason why I would use NAT over bridged or vice versa? Is it like just preference?

  5. #5
    Join Date
    Jun 2019
    Beans
    1

    Re: Can more than 1 VM share a physical NIC?

    although i might not be able to provide you with the answer you might be seeking, i always use bridged in virtualbox because nat provides me with stupid ip address allocation. whereas bridged sticks to traditional allocation patterns which integrate better with other systems on the network.

  6. #6
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    14,026
    Distro
    Kubuntu 19.04 Disco Dingo

    Re: Can more than 1 VM share a physical NIC?

    NAT is more secure since the VM is hidden behind the host in the same way a local network is hidden behind most routers. If you plan to run servers in the VMs, you need a bridged connection so client machines can see the server.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  7. #7
    Join Date
    Mar 2007
    Location
    Denver, CO
    Beans
    7,751
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Can more than 1 VM share a physical NIC?

    Bridge uses Level 2 networking stack where as NAT uses Level 3? Perhaps I'm wrong about this. NAT is a lot more tricky to set up however probably more secure in the end -- that being said NAT to me is a PITA to me likely because I don't know what I'm doing.

  8. #8
    Join Date
    Jan 2007
    Beans
    720
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Can more than 1 VM share a physical NIC?

    Quote Originally Posted by kevdog View Post
    Bridge uses Level 2 networking stack where as NAT uses Level 3? Perhaps I'm wrong about this. NAT is a lot more tricky to set up however probably more secure in the end -- that being said NAT to me is a PITA to me likely because I don't know what I'm doing.
    Yes, essentially. Think of bridged is having a switch connected to your LAN that your VMs are plugged into, and NAT as having a router with the WAN port connected to your LAN and your VMs connected to the LAN ports so they're on their own network, getting IPs from the router.

    (I'm referring to Virtualbox's networking modes here, VMWare and other VM managers will have similar options, maybe named differently)

    Let's say your LAN has the IP range 192.168.1.0/24, your LAN's router is on 192.168.1.1 and your VM host is on 192.168.1.100. When using bridge mode, it's like plugging directly into your LAN's router (or a switch), so your VMs will have 192.168.1.x IPs and they can see everything on your LAN, everything on your LAN can see the VMs, the VMs can get to the internet through your LAN's router, just like any other computer on your network.

    So, VM 1 might have IP 192.168.1.101, VM 2 might get 192.168.1.102, etc. Your LAN router or whatever DHCP server you're using would hand out IPs to the VMs just like a physical box. It's like your NIC acts as a separate NIC for each VM, each with its own MAC address.

    So, for VMs in bridge mode:
    Host: 192.168.1.100
    VM 1: 192.168.1.101
    VM 2: 192.168.1.102
    etc.

    In default NAT mode (in Virtualbox), your VMs are each placed behind a virtual router. So, while your host will still have 192.168.1.100, the "router" will NAT to this, and your VMs behind that will have different IPs, like 10.0.2.15. The VMs can access your LAN (and the internet) through this router, but by default the LAN won't have access to the VMs, nor can each VM see other NATed VMs. You can set up port forwarding to make services on the VMs accessible from the host or the LAN in general, just like on a hardware router.

    So, for VMs in NAT mode:
    Host: 192.168.1.100
    VM 1: Virtual Router 1 -> 10.0.2.15
    VM 2: Virtual Router 2 -> 10.0.2.15
    (Each VM is behind a separate "router" so they may have the same IP, as each are on their own private network).

    There's also a "NAT Network" mode where you give the network a name, and then any VMs using that network name will share a router. Doing this, the VMs behind the router can see each other, but are still isolated from the LAN side.

    Host: 192.168.1.100
    VM 1: Virtual Router 1 -> 10.0.2.15
    VM 2: Virtual Router 1 -> 10.0.2.16
    etc.

    NAT mode is the default in Virtualbox when you create a VM, but you can change this in the network settings for each VM. For most VMs where I'm just playing with a distro, I just use NAT mode since it works. If I want to run services on a VM that are accessible from the LAN or the host (like ssh or a webserver), I'll use bridged mode.

    You're not limited to choosing just one network type either. You could have a couple VMs behind NATs, a couple more bridged, some more behind a NAT network, etc. And since each VM can have 4 virtual NICs, you can even connect one VM to more than one network. For example, you could make a VM that has 1 NIC bridged and one connected to a NAT network (or even an isolated network). Install pfSense in that VM, and then you have a firewall that other VMs on that isolated network can access.
    Last edited by kpatz; 1 Week Ago at 02:46 PM.
    Current 'buntu systems: Server 18.04.2 LTS, Mythbuntu 16.04 LTS, Ubuntu 16.04.1 LTS / Retired: 14.04 LTS, 10.04 LTS, 8.04 LTS
    Been using ubuntu since 6.04 (13 years!)

  9. #9
    Join Date
    Sep 2007
    Beans
    284

    Re: Can more than 1 VM share a physical NIC?

    Quote Originally Posted by SeijiSensei View Post
    NAT is more secure since the VM is hidden behind the host in the same way a local network is hidden behind most routers. If you plan to run servers in the VMs, you need a bridged connection so client machines can see the server.
    thanks. This is very helpful
    Last edited by webmiester; 1 Week Ago at 04:33 PM.

  10. #10
    Join Date
    Jan 2007
    Beans
    720
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Can more than 1 VM share a physical NIC?

    Quote Originally Posted by webmiester View Post
    is this advisable to use a hybrid? Like VM1 nd VM2 will use brides while VM3 and VM4 will use NAT?
    Network/NIC settings are set per VM (or more specifically, per virtual NIC of which there are 4 per VM), so you can easily do this. Is it advisable? Depends on your use case. You may have one VM that you want bridged so services running within are accessible over the LAN, and another VM you want to put behind a NAT for security, and another you want on an isolated virtual network, etc.

    It all depends on what the particular VM is being used for and how you want its network access to be, especially visibility to other machines, whether physical or VMs.

    It's no different than setting up physical machines on a network. You can plug a few into a switch and they all see each other (bridged mode) and you might put 2 more behind a NAT router for security, or on a different subnet via a router and so forth.

    As I mentioned before, when using a VM to play with a desktop distro where I'm playing in the GUI or a console I'll usually just use the default NAT, but if I want to be able to ssh into the VM from elsewhere, I'll use bridged. It's easy enough to change on an existing VM as well, in case I change my mind.
    Last edited by kpatz; 1 Week Ago at 04:43 PM.
    Current 'buntu systems: Server 18.04.2 LTS, Mythbuntu 16.04 LTS, Ubuntu 16.04.1 LTS / Retired: 14.04 LTS, 10.04 LTS, 8.04 LTS
    Been using ubuntu since 6.04 (13 years!)

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •