Which terminal command to get just IP address and nothing else?

后端 未结 29 1324
春和景丽
春和景丽 2020-12-04 06:16

I\'m trying to use just the IP address (inet) as a parameter in a script I wrote.

Is there an easy way in a unix terminal to get just the IP address, rather than loo

29条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 06:43

    In man hostname there is even more easier way which automatically excluding loopback IP and showing only space separated list of all assigned to host ip addresses:

    root@srv:~# hostname --all-ip-addresses
    11.12.13.14 192.168.15.19 
    
    root@srv:~# ip a
    1: lo:  mtu 16436 qdisc noqueue state UNKNOWN
       link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
       inet 127.0.0.1/8 scope host lo
       inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
    2: venet0:  mtu 1500 qdisc noqueue state UNKNOWN 
      link/void 
      inet 11.12.13.14/32 scope global venet0:0
      inet 192.168.15.19/32 scope global venet0:1
    

提交回复
热议问题