Parse ifconfig to get only my IP address using Bash

后端 未结 20 1240
甜味超标
甜味超标 2020-11-30 05:04

I want to edit the bashrc file to have a simple function called \"myip\" to run. As you might guess, the function myip prints only my internal IP address of my machine.

20条回答
  •  孤独总比滥情好
    2020-11-30 05:46

    There is another easy way to get the IP address apart from parsing ifconfig.

    hostname -I -I, --all-ip-addresses all addresses for the host -i, --ip-address addresses for the hostname

    Ref: http://linux.die.net/man/1/hostname

    Example:

    [ec2-user@terraform ~]$ hostname -I
    10.10.10.10

提交回复
热议问题