LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-04-2011, 04:33 AM   #1
tank junior
Member
 
Registered: Apr 2010
Posts: 42

Rep: Reputation: 0
ifconfig physical vs virtual mac address


Hi,

I need to find out the mac address of physical ethernet card. The solution must satisfy these conditions:

1. It should always return the mac address of physical ethernet card and never the mac address of virtual ones(VirtualBox, Vmware, VPN's).

2. If no physical card is present(may be virtual ones are available), it should return nothing.

3. In case of two physical cards (wired and wireless), it should return either of one.

4. Even if media is disconnected, it should return the mac address of physical ones.

On windows system it's easier to satisfy all the conditions mentioned above by carefully parsing the result of "ipconfig /all" command.

I am new on *nix platform and after googling a lot, I am not able to find the solution. "ifconfig" command shows all the available adapters but I have no idea how to distinguish between physical ones and virtual ones.

Cheers

Prashant
 
Old 04-04-2011, 04:45 AM   #2
dudeman41465
Member
 
Registered: Jun 2005
Location: Kentucky
Distribution: Ubuntu
Posts: 794

Rep: Reputation: 56
Quote:
Originally Posted by tank junior View Post
Hi,

I need to find out the mac address of physical ethernet card. The solution must satisfy these conditions:

1. It should always return the mac address of physical ethernet card and never the mac address of virtual ones(VirtualBox, Vmware, VPN's).

2. If no physical card is present(may be virtual ones are available), it should return nothing.

3. In case of two physical cards (wired and wireless), it should return either of one.

4. Even if media is disconnected, it should return the mac address of physical ones.

On windows system it's easier to satisfy all the conditions mentioned above by carefully parsing the result of "ipconfig /all" command.

I am new on *nix platform and after googling a lot, I am not able to find the solution. "ifconfig" command shows all the available adapters but I have no idea how to distinguish between physical ones and virtual ones.

Cheers

Prashant
The virtual adapters, as far as I know, are not "created" by things like Virtualbox like they are in Windows, it behaves differently in *nix. Physical ethernet connections are almost always ethx where x is a number. Wireless ones are usually wlanx where x is a number, sometimes athx for Atheros wireless cards. You can use the grep argument with a pipe to cut out certain parts of the output of a command. For example, if you I run just ifconfig I get:
Code:
eth0      Link encap:Ethernet  HWaddr 00:1e:33:80:bb:e0  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:43 Base address:0xe000 

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:3672 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3672 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:4130319 (4.1 MB)  TX bytes:4130319 (4.1 MB)

wlan0     Link encap:Ethernet  HWaddr 00:21:63:a5:26:f4  
          inet addr:10.1.1.6  Bcast:10.1.1.255  Mask:255.255.255.0
          inet6 addr: fe80::221:63ff:fea5:26f4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:358571 errors:0 dropped:0 overruns:0 frame:0
          TX packets:356426 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:273809230 (273.8 MB)  TX bytes:66459213 (66.4 MB)
If I run:
Code:
ifconfig | grep wlan0
It cuts the output down to:
Code:
wlan0     Link encap:Ethernet  HWaddr 00:21:63:a5:26:f4
Grep only takes out that line though, I'm not quite sure how to cut out sections of a line, but hopefully this points you in the right direction. If I find anything useful with Google I'll post it here.
 
Old 04-04-2011, 04:46 AM   #3
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
i'm also not so familiar with *NIX but i'll try to put you in the right direction.

when you grepped it, use :

Code:
[root@monitor2 local]# ifconfig -a | cut -c 32-55 | grep "HW *"
HWaddr 00:25:B3:AB:3C:90
HWaddr 00:25:B3:AB:3C:92
32 is the startposition where to cut
55 is the endposition where he needs to stop cutting

if you don't want HWaddr use:
Code:
cut -c 39-55

Last edited by brownie_cookie; 04-04-2011 at 04:49 AM.
 
Old 04-04-2011, 04:57 AM   #4
dudeman41465
Member
 
Registered: Jun 2005
Location: Kentucky
Distribution: Ubuntu
Posts: 794

Rep: Reputation: 56
This command produces ONLY MAC addresses. Found this with Google and tested it myself:
Code:
ifconfig | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
It took a normal ifconfig down to this:
Code:
00:1e:33:80:bb:e0
00:21:63:a5:26:f4
Edit: Just saw the response before me. I guess both solutions work, hope this helps! :-)

Last edited by dudeman41465; 04-04-2011 at 04:58 AM.
 
Old 04-04-2011, 04:59 AM   #5
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,272

Rep: Reputation: 148Reputation: 148
1. ipconfig/all will not return virtual adapter details on windows? No, it should show all physical and virtual adapter details

2. if there no physical card, is it possible to create virtual adapter? & what use of it?

3. "ifconfig" will return all available up and running network adapter details

4. if cable disconnected & if you are not manually down the interface, i believe ifconfig will return the interface details

Personally i am not familiar with Nix but this is the standard command in Linux based system
 
Old 04-04-2011, 05:12 AM   #6
tank junior
Member
 
Registered: Apr 2010
Posts: 42

Original Poster
Rep: Reputation: 0
I can't depend on ethx and wlanx. For example when I execute 'ifconfig' on ubuntu hardy which is running as a guest using VirtualBox on windows host. I am getting eth13 and lo and both of them are virtual.
 
Old 04-04-2011, 05:19 AM   #7
dudeman41465
Member
 
Registered: Jun 2005
Location: Kentucky
Distribution: Ubuntu
Posts: 794

Rep: Reputation: 56
Quote:
Originally Posted by tank junior View Post
I can't depend on ethx and wlanx. For example when I execute 'ifconfig' on ubuntu hardy which is running as a guest using VirtualBox on windows host. I am getting eth13 and lo and both of them are virtual.
lo is usually your loopback interface, and doesn't have a MAC listed. Try one of the two commands we listed above, they should work just fine for you. I was just using ethx as an example, not as something you should try in a command.
 
Old 04-04-2011, 10:01 AM   #8
tank junior
Member
 
Registered: Apr 2010
Posts: 42

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by dudeman41465 View Post
lo is usually your loopback interface, and doesn't have a MAC listed. Try one of the two commands we listed above, they should work just fine for you. I was just using ethx as an example, not as something you should try in a command.
Command is working fine but eth13 is not the physical ethernet adapter. It's created by VirtualBox.
Another option I found is
Code:
lshw -class network
It lists all the interfaces but I don't have a system where *nix is installed on the disk as well as virtual adapters are installed. May be I can ask about this on VirtualBox forums where users are using linux as host and virtualbox is installed.
 
Old 04-04-2011, 02:23 PM   #9
tank junior
Member
 
Registered: Apr 2010
Posts: 42

Original Poster
Rep: Reputation: 0
Hey dudeman41465,

Could you please run lshw -class network on your system and post the result? There is a flag called "firmware" and it's value is "N/A", may be because it's virtual adapter. I am hoping to get something in your eth0 and wlan0 adapter because they are physical ones.

Thanks

Prashant
 
Old 04-05-2011, 12:31 AM   #10
dudeman41465
Member
 
Registered: Jun 2005
Location: Kentucky
Distribution: Ubuntu
Posts: 794

Rep: Reputation: 56
Quote:
Originally Posted by tank junior View Post
Hey dudeman41465,

Could you please run lshw -class network on your system and post the result? There is a flag called "firmware" and it's value is "N/A", may be because it's virtual adapter. I am hoping to get something in your eth0 and wlan0 adapter because they are physical ones.

Thanks

Prashant
That command gives me the following:
Code:
  *-network               
       description: Ethernet interface
       product: RTL8101E/RTL8102E PCI Express Fast Ethernet controller
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0
       bus info: pci@0000:04:00.0
       logical name: eth0
       version: 02
       serial: 00:1e:33:80:bb:e0
       width: 64 bits
       clock: 33MHz
       capabilities: bus_master cap_list ethernet physical
       configuration: broadcast=yes driver=r8169 driverversion=2.3LK-NAPI latency=0 multicast=yes
       resources: irq:43 ioport:3000(size=256) memory:f1010000-f1010fff memory:f1000000-f100ffff
  *-network
       description: Wireless interface
       product: AR928X Wireless Network Adapter (PCI-Express)
       vendor: Atheros Communications Inc.
       physical id: 0
       bus info: pci@0000:05:00.0
       logical name: wlan0
       version: 01
       serial: 00:21:63:a5:26:f4
       width: 64 bits
       clock: 33MHz
       capabilities: bus_master cap_list ethernet physical wireless
       configuration: broadcast=yes driver=ath9k driverversion=2.6.35-28-generic firmware=N/A ip=10.1.1.6 latency=0 multicast=yes wireless=IEEE 802.11bgn
       resources: irq:18 memory:f3100000-f310ffff
  *-network DISABLED
       description: Ethernet interface
       physical id: 2
       logical name: vboxnet0
       serial: 0a:00:27:00:00:00
       capabilities: ethernet physical
       configuration: broadcast=yes multicast=yes
So your Linux is inside a virtual machine, and therefore it "thinks" that eth13 is a physical adapter, but it's actually a virtual one, is that correct? That can be corrected in the VirtualBox settings for network connectivity. I believe if you set your Network to "Bridged Adapter" in Virtualbox for that virtual machine, it will have access to your physical network cards, and not the fake ones generated by Virtualbox. I believe I was misunderstanding earlier, and assumed that Linux was the host OS, and not the guest. I'll test this out real quick and will post back in a few minutes. Attached is a screenshot of the setting I'm talking about.
Attached Thumbnails
Click image for larger version

Name:	Screenshot.png
Views:	7
Size:	105.3 KB
ID:	6620  

Last edited by dudeman41465; 04-05-2011 at 12:32 AM.
 
Old 04-05-2011, 01:28 AM   #11
dudeman41465
Member
 
Registered: Jun 2005
Location: Kentucky
Distribution: Ubuntu
Posts: 794

Rep: Reputation: 56
From what I can tell, no matter what setting I change to in Virtualbox, the network adapter seen by the guest OS is always going to be a virtual one. None of the options I selected grayed out the input box for what MAC to show to the guest OS. Attached is a screenshot of what I'm talking about. The "Adapter Type" and stuff is all adjustable. I don't really have that Intel type card, that's just what Virtualbox emulates for the Guest OS. Not saying it isn't possible to see the physical interface from a guest OS, but I haven't been able to figure it out in my few minutes of messing around.
Attached Thumbnails
Click image for larger version

Name:	Screenshot.png
Views:	7
Size:	58.8 KB
ID:	6622  

Last edited by dudeman41465; 04-05-2011 at 01:29 AM.
 
Old 04-05-2011, 01:45 AM   #12
tank junior
Member
 
Registered: Apr 2010
Posts: 42

Original Poster
Rep: Reputation: 0
I think it would be impossible to differentiate mac address association with physical or virtual adapters using command lines tools available. I have also tried several c/c++ examples but none of them is flawless.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting virtual address to physical address in the kernel DBQ Programming 0 02-07-2010 07:30 PM
how to translate virtual address to physical address in linux application saurin Programming 1 11-18-2009 10:05 PM
how to find physical address of kernel virtual address kushneeraj Programming 0 10-20-2006 08:29 PM
API for mapping Physical Address to Virtual Address Lakshman_smt Linux - Software 2 10-15-2006 10:08 PM
Memory Mapping (same physical address = virtual address) skd.tech Linux - Kernel 7 07-25-2006 12:13 AM


All times are GMT -5. The time now is 10:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration