In Virtual Box, how do you know which NIC is which from the linux command line?

6,070

There are several ways you can figure it out, but here are the two most reliable methods (in my opinion)...

Method #1 (most reliable)

drew@debian:~$ /sbin/ifconfig -a | grep HWaddr
eth0      Link encap:Ethernet  HWaddr 08:00:27:f7:28:18  
eth1      Link encap:Ethernet  HWaddr 08:00:27:52:8b:6e  
eth2      Link encap:Ethernet  HWaddr 08:00:27:81:d7:5c  
eth3      Link encap:Ethernet  HWaddr 08:00:27:d5:22:e8 

Match up the MAC addresses with what is shown in the machine Network settings (from the Host). That is, right click on the VM go to Settings, then Network, look at MAC Address field for each Adapter.

Other commands that will list the MAC addresses include ip addr, ip link show, lshw -C network. I think the command I posted produces the cleanest output though.

Method #2

drew@debian:~$ ls -l /sys/class/net
total 0
lrwxrwxrwx 1 root root 0 May 13 21:59 eth0 -> ../../devices/pci0000:00/0000:00:03.0/net/eth0
lrwxrwxrwx 1 root root 0 May 13 21:59 eth1 -> ../../devices/pci0000:00/0000:00:08.0/net/eth1
lrwxrwxrwx 1 root root 0 May 13 21:59 eth2 -> ../../devices/pci0000:00/0000:00:09.0/net/eth2
lrwxrwxrwx 1 root root 0 May 13 21:59 eth3 -> ../../devices/pci0000:00/0000:00:0a.0/net/eth3
lrwxrwxrwx 1 root root 0 May 13 21:59 lo -> ../../devices/virtual/net/lo

the PCI bus numbers will be in order... 3, 8, 9, a (10). So that would translate to 3 = NIC 1, 8 = NIC2, etc... Note that if your NIC names look like enp0s3 or eno1 then they should also be in order (though not necessarily sequential), in your case enp0s3 would be NIC 1, enp0s8 would be NIC 2, etc...

Share:
6,070

Related videos on Youtube

Volumetricsteve
Author by

Volumetricsteve

Updated on September 18, 2022

Comments

  • Volumetricsteve
    Volumetricsteve over 1 year

    I've run into a problem a few times now where I'm installing linux in a virtual machine, and all of my interfaces look like "enp0s3" or "enp0s8" ect.

    In one test, I was running a VM with 4 virtual NICs, somehow those showed up in linux as:

    enp0s3 enp0s8 enp0s9 enp0s17

    The numbering scheme alone confuses me, but I'm mostly not sure on how to determine which one points to which NIC.

    If I do lspci, it shows me all the devices in the system but not how they connect to the list of interfaces....if I do "ip link show" it shows me all the interfaces, but not the NIC they're attached to. What do I do?

    EDIT:

    To clarify, I'm not trying to do much of anything with my physical layer of hardware. When I seek to see "which nic is which" I'm trying to figure out the best method to determine which interface (enp0sX) is pointing to which of Virtual Box's 4 virtual NICs. Obviously if you have one nic, that explains itself, but if you're using all 4 virtual NICs and they're all using the same driver, it gets hard to sort out which is which.

    • Volumetricsteve
      Volumetricsteve about 9 years
      that gets me closer, now I have a mac address and I can work my way backwards from there...but some systems are nice where you can tell which nic is which by what driver its using, but that doesn't seem present anymore..
    • Nullpointer42
      Nullpointer42 about 9 years
      Am I correct in saying you want to know which of your virtual NICs corresponds to the hardware NIC in the host? The guest is oblivious to the host hardware, it only knows the virtual. From the host, you can do someting like VBoxManage showvminfo {vmname} or VBoxManage list bridgedifs will get you other info as well . . . still need to do some cross referencing . . .
    • Volumetricsteve
      Volumetricsteve about 9 years
      oh, no sorry ernie, I'll clarify more. My Virtual Machine has two virtual nics, one based on an AMD chipset and the other is an Intel driver...I think it's commonly regarded as 'e1000'. Virtual Box is bridging the AMD nic to my wifi connection so it can talk directly to the DHCP in my house. I want to be able to set up my other virtual nic to forward packets to yet another virtual machine simply to teach myself how to do it...but I'm not that far into the problem yet. I'm still trying to figure out from within the OS I can determine which NIC is which.
    • Volumetricsteve
      Volumetricsteve about 9 years
      Right now it looks like I have to know the MAC of each NIC and then go from there.
  • Volumetricsteve
    Volumetricsteve about 9 years
    It looks like to me that ip addr and ip -a have identical outputs. There's nothing that'll show "this mac address is here on the pci bus and has interface name blah" ? The correlation of mac and interface name at once would really be tops...but it sounds like that's not readily available.
  • jcoppens
    jcoppens about 9 years
    I still have the impression you are trying to get the data from the physical computer (= the host). From inside the application you are running in the virtual machine, you can't get there directly. You could however connect to the host using eg. SSH, and then use lspci or whatever.
  • Volumetricsteve
    Volumetricsteve about 9 years
    jcoppens - I edited my original question to try to fix any confusion.
  • Khanna111
    Khanna111 over 7 years
    If it is centos then grep for "ether" in the output of ifconfig instead of "HWadd..". That is the MAC address.