Sunil Gowda Sunil Gowda - 2 years ago 94
Bash Question

How to check that IP addess is attched to which eth in Linux Machine?

Well I use SUSE11 Linux machine, Is there is a single cmd which gives the eth number to which my IP is attched to ?


<1035 sne-70 [u2see] :/home/u2see/nginrun/log>**ifconfig -a | grep addr**
eth0 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:39
inet6 addr: fe80::225:9eff:fed4:7d39/64 Scope:Link
eth2 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:3A
inet addr: Bcast: Mask:
inet6 addr: fe80::225:9eff:fed4:7d3a/64 Scope:Link
eth3 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:3B
inet6 addr: fe80::225:9eff:fed4:7d3b/64 Scope:Link
eth4 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:3C
inet addr:**** Bcast: Mask:
inet6 addr: 2607:f0d0:1002:11::6/64 Scope:Global
inet6 addr: fe80::225:9eff:fed4:7d3c/64 Scope:Link

My IP is "" And i need to get the output as eth4 by using single cmd..
What cmd i can use ?

Answer Source

You can use GNU awk:

ifconfig -a |awk -v RS="\n\n" '/inet addr: /{print $1}'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download