Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Gentoo: User

How to find the MAC address

 

 

Gentoo user RSS feed   Index | Next | Previous | View Threaded


wonko at wonkology

Apr 19, 2012, 12:40 PM

Post #1 of 20 (212 views)
Permalink
How to find the MAC address

Hi there!

How am I supposed to find the MAC address of an ethernet interface? I used
to call ifconfig and grep for HWaddr, but this does not work any more.

I found the 'old-output' USE flag for sys-apps/net-tools, which brings
back the old behaviour in order not to break old scripts, but I'd like to
know what the new method is that scripts should use.

Here's how the output looked before and now:

Old output:
eth0 Link encap:Ethernet HWaddr bc:5f:f4:19:ad:18
inet addr:192.168.2.42 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::be5f:f4ff:fe19:ad18/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11027476 errors:0 dropped:0 overruns:0 frame:0
TX packets:8002728 errors:0 dropped:0 overruns:0 carrier:1
collisions:0 txqueuelen:1000
RX bytes:11763889583 (10.9 GiB) TX bytes:1006570663 (959.9 MiB)
Interrupt:49

New output:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.42 netmask 255.255.255.0 broadcast 192.168.2.255
inet6 fe80::be5f:f4ff:fe19:ad18 prefixlen 64 scopeid 0x20<link>
ether bc:5f:f4:19:ad:18 txqueuelen 1000 (Ethernet)
RX packets 10791981 bytes 11413935608 (10.6 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7867427 bytes 996505563 (950.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 1 collisions 0
device interrupt 49

Wonko


mikemol at gmail

Apr 19, 2012, 12:45 PM

Post #2 of 20 (203 views)
Permalink
Re: How to find the MAC address [In reply to]

On Thu, Apr 19, 2012 at 3:40 PM, Alex Schuster <wonko [at] wonkology> wrote:
> Hi there!
>
> How am I supposed to find the MAC address of an ethernet interface? I used
> to call ifconfig and grep for HWaddr, but this does not work any more.
>
> I found the 'old-output' USE flag for sys-apps/net-tools, which brings
> back the old behaviour in order not to break old scripts, but I'd like to
> know what the new method is that scripts should use.
>
> Here's how the output looked before and now:
>
> Old output:
> eth0      Link encap:Ethernet  HWaddr bc:5f:f4:19:ad:18
>          inet addr:192.168.2.42  Bcast:192.168.2.255  Mask:255.255.255.0
>          inet6 addr: fe80::be5f:f4ff:fe19:ad18/64 Scope:Link
>          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
>          RX packets:11027476 errors:0 dropped:0 overruns:0 frame:0
>          TX packets:8002728 errors:0 dropped:0 overruns:0 carrier:1
>          collisions:0 txqueuelen:1000
>          RX bytes:11763889583 (10.9 GiB)  TX bytes:1006570663 (959.9 MiB)
>          Interrupt:49
>
> New output:
> eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
>        inet 192.168.2.42  netmask 255.255.255.0  broadcast 192.168.2.255
>        inet6 fe80::be5f:f4ff:fe19:ad18  prefixlen 64  scopeid 0x20<link>

>        ether bc:5f:f4:19:ad:18  txqueuelen 1000  (Ethernet)

There it is.

>        RX packets 10791981  bytes 11413935608 (10.6 GiB)
>        RX errors 0  dropped 0  overruns 0  frame 0
>        TX packets 7867427  bytes 996505563 (950.3 MiB)
>        TX errors 0  dropped 0 overruns 0  carrier 1  collisions 0
>        device interrupt 49
>
>        Wonko
>



--
:wq


michael at orlitzky

Apr 19, 2012, 12:48 PM

Post #3 of 20 (205 views)
Permalink
Re: How to find the MAC address [In reply to]

On 04/19/12 15:40, Alex Schuster wrote:
> Hi there!
>
> How am I supposed to find the MAC address of an ethernet interface? I used
> to call ifconfig and grep for HWaddr, but this does not work any more.
>
> I found the 'old-output' USE flag for sys-apps/net-tools, which brings
> back the old behaviour in order not to break old scripts, but I'd like to
> know what the new method is that scripts should use.

`ip link`

Learning a new command for something so fundamental was annoying, but
now I'm much happier.


neil at digimed

Apr 19, 2012, 12:50 PM

Post #4 of 20 (206 views)
Permalink
Re: How to find the MAC address [In reply to]

On Thu, 19 Apr 2012 21:40:02 +0200, Alex Schuster wrote:

> How am I supposed to find the MAC address of an ethernet interface? I
> used to call ifconfig and grep for HWaddr, but this does not work any
> more.

> Here's how the output looked before and now:
>
> Old output:
> eth0 Link encap:Ethernet HWaddr bc:5f:f4:19:ad:18
~~~~~~~~~~~~~~~~~

> New output:
> eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST mtu 1500
> ether bc:5f:f4:19:ad:18 txqueuelen 1000 (Ethernet)
~~~~~~~~~~~~~~~~~

here?


--
Neil Bothwick

"I need your clothes, your boots, and your tagline!"
Attachments: signature.asc (0.19 KB)


mikemol at gmail

Apr 19, 2012, 12:56 PM

Post #5 of 20 (207 views)
Permalink
Re: How to find the MAC address [In reply to]

On Thu, Apr 19, 2012 at 3:48 PM, Michael Orlitzky <michael [at] orlitzky> wrote:
> On 04/19/12 15:40, Alex Schuster wrote:
>> Hi there!
>>
>> How am I supposed to find the MAC address of an ethernet interface? I used
>> to call ifconfig and grep for HWaddr, but this does not work any more.
>>
>> I found the 'old-output' USE flag for sys-apps/net-tools, which brings
>> back the old behaviour in order not to break old scripts, but I'd like to
>> know what the new method is that scripts should use.
>
> `ip link`
>
> Learning a new command for something so fundamental was annoying, but
> now I'm much happier.
>

I'll second this. The 'ip' command is far and away a nicer tool than
ifconfig, once you get a handle on it.

--
:wq


wonko at wonkology

Apr 19, 2012, 1:01 PM

Post #6 of 20 (204 views)
Permalink
Re: How to find the MAC address [In reply to]

Michael Mol writes:

> On Thu, Apr 19, 2012 at 3:40 PM, Alex Schuster <wonko [at] wonkology>
> wrote:

> > New output:
> > eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
> >        inet 192.168.2.42  netmask 255.255.255.0  broadcast
> > 192.168.2.255 inet6 fe80::be5f:f4ff:fe19:ad18  prefixlen 64  scopeid
> > 0x20<link>
>
> >        ether bc:5f:f4:19:ad:18  txqueuelen 1000  (Ethernet)
>
> There it is.

Wow. Now I feel really stupid. Because I am. I have no idea why I have
overlooked this.

Sorry for the noise!

Wonko


mikemol at gmail

Apr 19, 2012, 1:12 PM

Post #7 of 20 (204 views)
Permalink
Re: How to find the MAC address [In reply to]

On Thu, Apr 19, 2012 at 4:01 PM, Alex Schuster <wonko [at] wonkology> wrote:
> Michael Mol writes:
>
>> On Thu, Apr 19, 2012 at 3:40 PM, Alex Schuster <wonko [at] wonkology>
>> wrote:
>
>> > New output:
>> > eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
>> >        inet 192.168.2.42  netmask 255.255.255.0  broadcast
>> > 192.168.2.255 inet6 fe80::be5f:f4ff:fe19:ad18  prefixlen 64  scopeid
>> > 0x20<link>
>>
>> >        ether bc:5f:f4:19:ad:18  txqueuelen 1000  (Ethernet)
>>
>> There it is.
>
> Wow. Now I feel really stupid. Because I am. I have no idea why I have
> overlooked this.
>
> Sorry for the noise!

I didn't see it right away, either. I found it by noticing your MAC in
your old output, and searched for a substring of it in your new
output.

Incidentally, you can derive it from your IPv6 LL address, but that's
a bit of a roundabout way, and may not work if you've disabled IPv6.

--
:wq


wonko at wonkology

Apr 19, 2012, 1:14 PM

Post #8 of 20 (204 views)
Permalink
Re: How to find the MAC address [In reply to]

Neil Bothwick writes:

> On Thu, 19 Apr 2012 21:40:02 +0200, Alex Schuster wrote:

> > eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST mtu 1500
> > ether bc:5f:f4:19:ad:18 txqueuelen 1000 (Ethernet)
> ~~~~~~~~~~~~~~~~~
>
> here?

Aaaaaaah!

Wonko


wonko at wonkology

Apr 19, 2012, 1:40 PM

Post #9 of 20 (204 views)
Permalink
Re: How to find the MAC address [In reply to]

Michael Orlitzky writes:

> On 04/19/12 15:40, Alex Schuster wrote:
> > Hi there!
> >
> > How am I supposed to find the MAC address of an ethernet interface? I
> > used to call ifconfig and grep for HWaddr, but this does not work any
> > more.
> >
> > I found the 'old-output' USE flag for sys-apps/net-tools, which brings
> > back the old behaviour in order not to break old scripts, but I'd
> > like to know what the new method is that scripts should use.
>
> `ip link`
>
> Learning a new command for something so fundamental was annoying, but
> now I'm much happier.

Thanks, that's a nice one. But can I expect this command to be available
per default on typical Linux distributions? Some other systems I have
access to have it, but here on Gentoo it belongs to sys-apps/iproute2,
which depends on nothing I have installed, I do not even know why I
emerged it in the first place. So maybe I better use ifconfig which is
always available, although sometimes in /bin and sometimes in /sbin, and
I have to check the output to see which version it is.

Wonko


michael at orlitzky

Apr 19, 2012, 2:04 PM

Post #10 of 20 (204 views)
Permalink
Re: How to find the MAC address [In reply to]

On 04/19/12 16:40, Alex Schuster wrote:
>
> Thanks, that's a nice one. But can I expect this command to be available
> per default on typical Linux distributions? Some other systems I have
> access to have it, but here on Gentoo it belongs to sys-apps/iproute2,
> which depends on nothing I have installed, I do not even know why I
> emerged it in the first place. So maybe I better use ifconfig which is
> always available, although sometimes in /bin and sometimes in /sbin, and
> I have to check the output to see which version it is.
>

Gentoo prefers it over net-tools, and a few of the conf files mention
that, which explains how it could have wound up installed.

(Google says) iproute2 was introduced to replace net-tools around the
time of kernel-2.2, and (I says) they're needed to do anything remotely
complicated with the networking stack. So, they're probably pretty
standard these days.


peter at humphrey

Apr 19, 2012, 4:29 PM

Post #11 of 20 (190 views)
Permalink
Re: How to find the MAC address [In reply to]

On Thursday 19 April 2012 20:56:59 Michael Mol wrote:

> The 'ip' command is far and away a nicer tool than ifconfig, once you
> get a handle on it.

Which package is it in?

--
Rgds
Peter


wonko at wonkology

Apr 20, 2012, 3:11 AM

Post #12 of 20 (191 views)
Permalink
Re: How to find the MAC address [In reply to]

Peter Humphrey writes:

> On Thursday 19 April 2012 20:56:59 Michael Mol wrote:
>
> > The 'ip' command is far and away a nicer tool than ifconfig, once you
> > get a handle on it.
>
> Which package is it in?

sys-apps/iproute2

Wonko


joost at antarean

Apr 20, 2012, 3:43 AM

Post #13 of 20 (194 views)
Permalink
Re: How to find the MAC address [In reply to]

On Thursday, April 19, 2012 04:12:35 PM Michael Mol wrote:
> On Thu, Apr 19, 2012 at 4:01 PM, Alex Schuster <wonko [at] wonkology> wrote:
> > Michael Mol writes:
> >> On Thu, Apr 19, 2012 at 3:40 PM, Alex Schuster <wonko [at] wonkology>
> >>
> >> wrote:
> >> > New output:
> >> > eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
> >> > inet 192.168.2.42 netmask 255.255.255.0 broadcast
> >> > 192.168.2.255 inet6 fe80::be5f:f4ff:fe19:ad18 prefixlen 64 scopeid
> >> > 0x20<link>
> >> >
> >> > ether bc:5f:f4:19:ad:18 txqueuelen 1000 (Ethernet)
> >>
> >> There it is.
> >
> > Wow. Now I feel really stupid. Because I am. I have no idea why I have
> > overlooked this.
> >
> > Sorry for the noise!
>
> I didn't see it right away, either. I found it by noticing your MAC in
> your old output, and searched for a substring of it in your new
> output.
>
> Incidentally, you can derive it from your IPv6 LL address, but that's
> a bit of a roundabout way, and may not work if you've disabled IPv6.

How do you derive it?
I don't see the mac-address in the inet6 address.

--
Joost


grant.b.edwards at gmail

Apr 20, 2012, 7:14 AM

Post #14 of 20 (193 views)
Permalink
Re: How to find the MAC address [In reply to]

On 2012-04-20, Joost Roeleveld <joost [at] antarean> wrote:
> On Thursday, April 19, 2012 04:12:35 PM Michael Mol wrote:
>> On Thu, Apr 19, 2012 at 4:01 PM, Alex Schuster <wonko [at] wonkology> wrote:
>> > Michael Mol writes:
>> >> On Thu, Apr 19, 2012 at 3:40 PM, Alex Schuster <wonko [at] wonkology>
>> >>
>> >> wrote:
>> >> > New output:
>> >> > eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
>> >> > inet 192.168.2.42 netmask 255.255.255.0 broadcast
>> >> > 192.168.2.255 inet6 fe80::be5f:f4ff:fe19:ad18 prefixlen 64 scopeid
>> >> > 0x20<link>
>> >> >
>> >> > ether bc:5f:f4:19:ad:18 txqueuelen 1000 (Ethernet)
>> >>
>> >> There it is.
>> >
>> > Wow. Now I feel really stupid. Because I am. I have no idea why I have
>> > overlooked this.
>> >
>> > Sorry for the noise!
>>
>> I didn't see it right away, either. I found it by noticing your MAC in
>> your old output, and searched for a substring of it in your new
>> output.
>>
>> Incidentally, you can derive it from your IPv6 LL address, but that's
>> a bit of a roundabout way, and may not work if you've disabled IPv6.
>
> How do you derive it?
> I don't see the mac-address in the inet6 address.

$ ip addr show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000
link/ether 00:16:17:84:a7:b3 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.1/8 brd 10.255.255.255 scope global eth1
inet 192.168.250.1/24 brd 192.168.250.255 scope global eth1
inet 169.254.1.1/16 brd 169.254.255.255 scope global eth1
inet6 fe80::216:17ff:fe84:a7b3/64 scope link
valid_lft forever preferred_lft forever


fe80::0216:17ff:fe84:a7b3

0216 17 84 a7b3
xor 0200 00 00 0000
-------------------
0016 17 84 a7b3

00:16:17:84:a7:b3

And that's the interfaces MAC address.

See RFC2464 Sections 4 and 5

The tricky part is that you invert bit 1 of the first byte of the MAC
address.

--
Grant Edwards grant.b.edwards Yow! Someone in DAYTON,
at Ohio is selling USED
gmail.com CARPETS to a SERBO-CROATIAN


wireless at tampabay

Apr 20, 2012, 8:22 AM

Post #15 of 20 (194 views)
Permalink
Re: How to find the MAC address [In reply to]

Alex Schuster <wonko <at> wonkology.org> writes:


> How am I supposed to find the MAC address of an ethernet interface?

nmap -sP 192.168.2.0/24

might be of interest too,

ymmv,
James


peter at humphrey

Apr 20, 2012, 9:58 AM

Post #16 of 20 (191 views)
Permalink
Re: How to find the MAC address [In reply to]

On Friday 20 April 2012 11:11:08 Alex Schuster wrote:
> Peter Humphrey writes:
> > Which package is it in?
>
> sys-apps/iproute2

Of course. I should have thought of that - thanks.

--
Rgds
Peter


michaelkintzios at gmail

Apr 20, 2012, 11:43 AM

Post #17 of 20 (192 views)
Permalink
Re: Re: How to find the MAC address [In reply to]

On Friday 20 Apr 2012 16:22:10 James wrote:
> Alex Schuster <wonko <at> wonkology.org> writes:
> > How am I supposed to find the MAC address of an ethernet interface?
>
> nmap -sP 192.168.2.0/24
>
> might be of interest too,
>
> ymmv,
> James

Hmmm ... current versions use -sn instead of -sP for no port scan.

BTW, this would only work if you scan (as root) the target from another box.
It will not reveal a MAC address if you scan localhost.
--
Regards,
Mick
Attachments: signature.asc (0.19 KB)


mikemol at gmail

Apr 20, 2012, 1:39 PM

Post #18 of 20 (193 views)
Permalink
Re: Re: How to find the MAC address [In reply to]

On Fri, Apr 20, 2012 at 2:43 PM, Mick <michaelkintzios [at] gmail> wrote:
> On Friday 20 Apr 2012 16:22:10 James wrote:
>> Alex Schuster <wonko <at> wonkology.org> writes:
>> > How am I supposed to find the MAC address of an ethernet interface?
>>
>> nmap -sP 192.168.2.0/24
>>
>> might be of interest too,
>>
>> ymmv,
>> James
>
> Hmmm ... current versions use -sn instead of -sP for no port scan.
>
> BTW, this would only work if you scan (as root) the target from another box.
> It will not reveal a MAC address if you scan localhost.

'localhost' resolves to either 127.0.0.1 or ::1, which is almost
invariably assigned to the 'lo' interface.

It *might* work if you ran it against a public IP of the machine
you're on. Depends on how much optimization there is in the network
stack, I suppose.

--
:wq


waltdnes at waltdnes

Apr 22, 2012, 6:47 PM

Post #19 of 20 (188 views)
Permalink
Re: How to find the MAC address [In reply to]

On Fri, Apr 20, 2012 at 12:11:08PM +0200, Alex Schuster wrote
> Peter Humphrey writes:
>
> > On Thursday 19 April 2012 20:56:59 Michael Mol wrote:
> >
> > > The 'ip' command is far and away a nicer tool than ifconfig, once you
> > > get a handle on it.
> >
> > Which package is it in?
>
> sys-apps/iproute2

It's also a built-in for busybox, which is part of the system package.
On my machine...

waltdnes [at] d53 ~ $ busybox ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1454 qdisc pfifo_fast qlen 1000
link/ether 00:1d:09:96:6c:1c brd ff:ff:ff:ff:ff:ff

waltdnes [at] d53 ~ $ busybox ip addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1454 qdisc pfifo_fast qlen 1000
link/ether 00:1d:09:96:6c:1c brd ff:ff:ff:ff:ff:ff
inet 192.168.123.251/29 brd 192.168.123.255 scope global eth0
inet 169.254.1.4/16 brd 169.254.255.255 scope global eth0:1

--
Walter Dnes <waltdnes [at] waltdnes>


lavi.kfir at gmail

Apr 23, 2012, 5:49 AM

Post #20 of 20 (177 views)
Permalink
Re: How to find the MAC address [In reply to]

On Thu, Apr 19, 2012 at 10:40 PM, Alex Schuster <wonko [at] wonkology> wrote:

> Hi there!
>
> How am I supposed to find the MAC address of an ethernet interface? I used
> to call ifconfig and grep for HWaddr, but this does not work any more.
>
> I found the 'old-output' USE flag for sys-apps/net-tools, which brings
> back the old behaviour in order not to break old scripts, but I'd like to
> know what the new method is that scripts should use.
>
> Here's how the output looked before and now:
>
> Old output:
> eth0 Link encap:Ethernet HWaddr bc:5f:f4:19:ad:18
> inet addr:192.168.2.42 Bcast:192.168.2.255 Mask:255.255.255.0
> inet6 addr: fe80::be5f:f4ff:fe19:ad18/64 Scope:Link
> UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
> RX packets:11027476 errors:0 dropped:0 overruns:0 frame:0
> TX packets:8002728 errors:0 dropped:0 overruns:0 carrier:1
> collisions:0 txqueuelen:1000
> RX bytes:11763889583 (10.9 GiB) TX bytes:1006570663 (959.9 MiB)
> Interrupt:49
>
> New output:
> eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
> inet 192.168.2.42 netmask 255.255.255.0 broadcast 192.168.2.255
> inet6 fe80::be5f:f4ff:fe19:ad18 prefixlen 64 scopeid 0x20<link>
> ether bc:5f:f4:19:ad:18 txqueuelen 1000 (Ethernet)
> RX packets 10791981 bytes 11413935608 (10.6 GiB)
> RX errors 0 dropped 0 overruns 0 frame 0
> TX packets 7867427 bytes 996505563 (950.3 MiB)
> TX errors 0 dropped 0 overruns 0 carrier 1 collisions 0
> device interrupt 49
>
> Wonko
>
>
You can grab mac of eth0 with this command:
ip link show eth0 | grep 'link/ether' | awk '{print $2}'

Kfir

Gentoo user RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.