[Swan-dev] extract MAC address from "ip -o link sow dev eth0" - awk
Lennart Sorensen
lsorense at csclub.uwaterloo.ca
Fri Sep 20 21:41:15 UTC 2019
On Fri, Sep 20, 2019 at 11:08:39AM +0200, Antony Antony wrote:
> There is an annoying issue when running inside docker/namespace. The proxy
> arp function in _updown.netkey would fails. It has been bugging me for
> years!
> Now I tracked it down to two lines in _updown.netkey.in
>
> Here my first attempt to replace it using "ip link " command.
>
> programs/_updown.netkey/_updown.netkey.in
> - if [ -r /sys/class/net/${iface}/address ]; then
> - macaddr=$(cat /sys/class/net/${iface}/address)
> + if ip -o link show dev ${iface}; then
> + macaddr=$(ip -o link show dev ${iface} | awk '$2 != "${iface}:" {print $(NF-4)}')
Looking at docker containers here, eth0 is in /sys/class/net/ in
the container and appears to have the correct mac address showing.
Matches what ip command shows. Not sure why yours would not have it.
--
Len Sorensen
More information about the Swan-dev
mailing list