How to get the MAC address of the 'local' system given the IP address?
Karl Auer
kauer at biplane.com.au
Fri Jan 31 13:51:28 UTC 2020
On Fri, 2020-01-31 at 06:23 -0500, Little Girl wrote:
> Here's another way to get the LAN IP by using the ip command:
> ip route | grep kernel | cut -f1 -d'/'
These days, any interface can have multiple IP addresses, and (possibly
more importantly in this case) you can have multiple connections to
your LAN. I routinely have both wireless and wired connections going at
the same time, and not always to the same LAN!
That grep above will get you the networks your interfaces are in, not
the IP addresses on your interfaces. This gets you addresses:
ip route | grep kernel | tr -s " " | cut -d\ -f9
- run ip route
- select the lines containing "kernel"
- compress all spaces to single spaces
- take the ninth space-delimited field
However: You can have an address on an interface even if no routing is
going on at all, so it is better to use ip addr than ip route.
Here is my routing table now (edited for brevity):
kauer at kt:~$ ip route
default via 192.168.1.1 dev eth0
default via 192.168.1.1 dev wlan0
169.254.0.0/16 dev wlan0
192.168.1.0/24 dev eth0 proto kernel src 192.168.1.119
192.168.1.0/24 dev wlan0 proto kernel src 192.168.1.142
Then I delete all the routes:
sudo route del default
sudo route del default
sudo route del -net 169.254.0.0/16 dev wlan0
sudo route del -net 192.168.1.0/24 dev eth0
sudo route del -net 192.168.1.0/24 dev wlan0
Then I have no routes:
kauer at kt:~$ ip route
kauer at kt:~$
But I still have addresses on my interfaces:
kauer at kt:~$ ifconfig | grep "inet addr" | cut -d: -f2 | cut -d\ -f1
192.168.1.119
127.0.0.1
192.168.1.142
Regards, K.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)
http://www.biplane.com.au/kauer
http://twitter.com/kauer389
GPG fingerprint: 8D08 9CAA 649A AFEF E862 062A 2E97 42D4 A2A0 616D
Old fingerprint: A0CD 28F0 10BE FC21 C57C 67C1 19A6 83A4 9B0B 1D75
More information about the ubuntu-users
mailing list