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

后端 未结 29 1274
春和景丽
春和景丽 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:27

    When looking up your external IP address on a NATed host, quite a few answers suggest using HTTP based methods like ifconfig.me eg:

    $ curl ifconfig.me/ip
    

    Over the years I have seen many of these sites come and go, I find this DNS based method more robust:

    $ dig +short myip.opendns.com @resolver1.opendns.com
    

    I have this handy alias in my ~/.bashrc:

    alias wip='dig +short myip.opendns.com @resolver1.opendns.com'
    

提交回复
热议问题