天天看點

Linux下取IP位址

法一

root@test ~$eval `ifconfig | sed -rn '/^[^ \t]/{N;s/(^[^ ]*).*addr:([^ ]*).*/\1 \2/p}' | awk '$2!~/^127|^0|^$/{print $1"="$2}'|head -1`

root@test ~$

root@test ~$echo $eth0

10.240.210.131

法二

root@test ~$echo `ifconfig | sed -rn '1,2'p | awk '{print $2}' | awk -F "addr:" '{print $2}' |sed /^\s*$/d`

擷取公網IP

ifconfig|grep -oE 'inet addr:([0-9]{1,3}\.?){4}'|grep -oE '([0-9]{1,3}\.?){4}'|grep -vE '^(127|172|192|10)'

本文轉自 xoyabc 51CTO部落格,原文連結:http://blog.51cto.com/xoyabc/1662198,如需轉載請自行聯系原作者

繼續閱讀