14

How can I create a virtual interface, that connects to the same network as the physical interface? I tried searching around but all I found is loopback. I need the other end of the wire recognizes this as two interface, so loopback won't do it. Hypervisors like VMWare have an option to do exactly this (VM and host are recognized as two devices on router's arp table), but in my situation using a VM is pretty much overkill. I just want another connection, or maybe some apps that can behave as a "virtual switch".

I'm on Windows, and it should be like this.

Expected_Virtual_Network

Seems like I'm not the only one having this problem. Someone here and here have also asked but there's no acceptable answer. My apologize, but it is extremely hard to search for this problem.

6
  • My OS is Windows 7. But I can move to windows 8.1 or 10 if needed.
    – tvc
    Commented Feb 28, 2018 at 4:32
  • That kind of defeat the point since I'll need a hypervisor anyway. Or do I?
    – tvc
    Commented Feb 28, 2018 at 4:47
  • So apparently there are no separate app that can do this and I have to move everything to windows 10 but anyway, thank you.
    – tvc
    Commented Feb 28, 2018 at 5:10
  • The problem is a full-blown VM is overkill when all I need is just a virtual interface.
    – tvc
    Commented Feb 28, 2018 at 6:00

5 Answers 5

12

Procedure:

  1. Enable Hyper-V feature in Windows from optionalfeatures.exe or with command prompt using the following command as administrator and restart PC.

    DISM.exe /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V /NoRestart
    
  2. Open Hyper-V Manager from start menu or with run dialog box, type virtmgmt.msc. Go to Virtual Switch Manager > New Virtual Network Switch > Select External type > Create Virtual Switch > OK. It is important to select External type for that virtual network switch. See the article below for further details.

Hyper-V_External_Virtual_NIC

  1. Open Network Control Panel (ncpa.cpl) > Select Virtual Network Interface (with vEthernet name) > Change it's IP and MAC address. IP can be in same subnet of real NIC and of same default gateway.

Further Reading:

2
  • Though this technically creates a virtual adapter, practically it is useless because it disables using the original physical adapter. All traffic is routed through the virtual adapter, and you are right back where you started.
    – cmenning
    Commented Dec 21, 2018 at 18:56
  • 2
    @cmenning Yes you are right. But you can create two virtual interface under that same virtual switch -- one of which can be configured as same IP config of the physical one.
    – Biswapriyo
    Commented Dec 21, 2018 at 19:13
5

Procedure for Linux:

So originally I'm asked this to be done in Windows. But since the Windows-way will cost me another 2 hours I decided to do this on a linux box. Anyway here's how I did it, thanks to this answer. Hope this will solve someone's problem in the future. In short:

  1. Create a virtual link on your existing interface. You should get a Locally Administered Address (here) to pass in so it won't potentially mess things up (and also a recommended way to do):

    ip link add link eth0 address 56:8A:C0:DD:EE:FF eth0.1 type macvlan

  2. Bring the interface up:

    ifconfig eth0.1 up

  3. And acquire an address:

    dhclient -v eth0.1

Futher reading:

If you insist on a * real virtual * interface, there's a package named vde2 for the purpose of creating virtual switches on linux. Haven't tried that out, but maybe it can helps. It's annoying a little bit that such 'small' tool doesn't exist in Windows.

(Yes, I'm creating a link, not really an interface. But it did get my job done. I'm sorry if my question is misworded, you can edit it to clarify. But in the end of the day it shows up as an interface and traffic did goes thru that interface so probably it is solved?)

3
  • What is macvlan? Does the virtual and real network interface both work simultaneously? Can I add more than one? Can disable the real one and enable only the virtual one?
    – Biswapriyo
    Commented Mar 2, 2018 at 9:23
  • 3
    macvlan type link denotes a virtual interface based on link layer address (source). I needed another MAC address, not just another IP so macvlan is the appropriate virtual interface type.
    – tvc
    Commented Mar 2, 2018 at 10:09
  • 1
    In my case, yea, it did work simultaneously. Never tried to add another one but i believe there can be several virtual interfaces inside one real interface. Because of that i also think disabling the real one will take down the rest virtual ones too.
    – tvc
    Commented Mar 2, 2018 at 10:13
0

First you'll need to create an external v-switch using Hyper-V (available on win10. I'm not sure, but I think you'll need the Pro installation).

After creating the v-switch your physical NIC will shift to Hyper-V's management and a virtual NIC (representing that v-switch) will be created (replacing the physical one).

You can add another windows v-NIC to that v-switch by using the Power-Shell command (you have to run it as administrator):

Add-VMNetworkAdapter -ManagementOS -SwitchName <Hyper-V's vSW name> -Name <vNIC name>

For more information check this link: Working with Virtual NIC’s in Windows

0

Searching for the same thing for Windows. So here just some additional info. Linux: Assuming you have only eth0 NIC, in /etc/network/interfaces (on Debian, Ubuntu) you can use dummy:

auto eth1
iface eth1 inet static
    pre-up ip link add eth1 type dummy
    address 10.0.0.4
    netmask 255.255.255.0
    post-down ip link delete eth1 type dummy
-3
netsh wlan set hostednetwork mode=allow ssid=randomwifiname key=12345678

netsh wlan start hostednetwork

Requires admin privileges, creates a virtual wireless network that has its own interface. You can enable internet sharing, DHCP automatically or static. By default its IP/subnet is completely separate from the usual 192.168.xxx.xxx local interfaces.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .