Parse ifconfig to get only my IP address using Bash

后端 未结 20 1219
甜味超标
甜味超标 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:49

    In case of eth0, the following works for me. Try to tweak it with the same logic.

    ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'  
    

提交回复
热议问题