How to get the MAC address of the 'local' system given the IP address?

Little Girl littlergirl at gmail.com
Sun Feb 2 14:41:48 UTC 2020


Hey there,

Tom H wrote:
>On Fri, Jan 31, 2020 at 12:26 PM Little Girl wrote:
>>
>> It's case-sensitive. A lower-case i (hostname -i) returns localhost
>> and an upper-case I (hostname -I) returns the LAN IP.  
>
>"-i" returns the addresses associated with a system's hostname.
>
>"-I" returns all the addresses associated with a system.

Thanks.

>> Here's another way to get the LAN IP by using the ip command:
>>
>> ip route | grep kernel | cut -f1 -d'/'
>>
>> I also had that command in my notes written this way, but can't
>> remember why:
>>
>> ip route | grep kernel | cut -f1 -d' ' | cut -f1 -d'/'
>>
>> Both give the same result on my computer, but maybe only one will
>> work on certain systems or networks.  
>
>"ip r | grep kernel | cut -f1 -d'/'" works because the network
>address is the first record.
>
>"ip r | grep kernel | cut -f1 -d' ' | cut -f1 -d'/'" is the "proper"
>way because it would be extensible if the network address were the
>2nd/3rd/... record (for the 2nd, you'd use "... cut -f2 -d' ' ...".

Good to know. I ended up playing around with it even further,
changing each f1 to watch what happens. Very powerful stuff.

-- 
Little Girl

There is no spoon.




More information about the ubuntu-users mailing list