1

Things I tried:

  • scope inet gives Error: argument "inet" is wrong: invalid "scope"
  • to inet gives Error: ??? prefix is expected rather than "inet".
  • (flag) inet gives Error: either "dev" is duplicate, or "inet" is a garbage.
  • label inet gives no output
  • List item

And thats exhausted my ideas. Is there even a built in way to get interface properties without a nasty grep 🙳 grok pipeline?

How Can I Get My Interface's IP (inet) Address?

How can I get the ipv4 (inet) field alone directly from the iproute2 tools ip command?

I was trying to the effect of:

ip address show dev docker0 [magical argument here]

But I dont think I really understand the options here:

       ip address show [ dev IFNAME ] [ scope SCOPE-ID ]
                           [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]
— $ ip address show help

ThorSummoner
  • 4,422
  • As far as I know, the most "concise" output for address is returned with ip a show dev $INTERFACE – ILMostro_7 Mar 30 '17 at 18:05
  • @ILMostro_7 If I was unclear, I want just the inet value, nothing more in the output. – ThorSummoner Mar 30 '17 at 19:40
  • 1
    Use grep, awk, perl or whatever you like to extract the ip address proper from the output. Keep in mind that interfaces can have multiple ip addresses. – dirkt Mar 31 '17 at 05:42
  • @dirkt Sorry if this is unclear, this question is asking how to get the value specifically, and directly from iproute2, without using a shell pipeline to parse any output. – ThorSummoner Mar 31 '17 at 19:54
  • Then the answer is "you can't". – dirkt Apr 01 '17 at 07:33
  • 1
    The tool really needs a way to write custom format expressions so you can easily output what you need. Or dump json. Or something. – Craig Ringer May 16 '19 at 03:28

1 Answers1

3

see Is there an easy way to programmatically extract IP address?

$ ip -f inet addr show wlan0 | grep -Po 'inet \K[\d.]+'
192.168.1.20
Anonymous
  • 31
  • 2