Linux bash script to extract IP address

前端 未结 13 2378
我在风中等你
我在风中等你 2020-12-04 15:44

I want to make big script on my Debian 7.3 ( something like translated and much more new user friendly enviroment ). I have a problem. I want to use only some of the informa

13条回答
  •  無奈伤痛
    2020-12-04 16:10

    To just get your IP address:

    echo `ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
    

    This will give you the IP address of eth0.

    Edit: Due to name changes of interfaces in recent versions of Ubuntu, this doesn't work anymore. Instead, you could just use this:

    hostname --all-ip-addresses or hostname -I, which does the same thing (gives you ALL IP addresses of the host).

提交回复
热议问题