目录
查看ip
sh
ip a
查看网关
sh
ip r
只查看ens33
sh
ip a show dev ens33
过滤ip
sh
ip a | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
拿到网卡名字
sh
ip a |awk '/^[0-9]+:/{print $2}'| awk 'BEGIN{FS=":"}{print $1}'| grep -v lo
# 只要第一个网卡
ip a |awk '/^[0-9]+:/{print $2}'| awk 'BEGIN{FS=":"}{print $1}'| grep -v lo | head -1
对内容进行切片
sh
ip a show dev $(ip a |awk '/^[0-9]+:/{print $2}'|awk 'BEGIN{FS=":"}{print $1}'| grep -v lo | head -1)
## 获取ens网卡 的ip
ip a show dev ens33 | awk 'NR==3{print $2}' | awk -F'/' '{print $1}'
获取第一网卡IP (head -1 表示第一个网卡)
sh
ip a show dev $(ip a |awk '/^[0-9]+:/{print $2}'|awk 'BEGIN{FS=":"}{print $1}'| grep -v lo | head -1) | awk 'NR==3{print $2}' | awk -F'/' '{print $1}'
脚本中打印IP
sh
wangka=$(ip a |awk '/^[0-9]+:/{print $2}'| awk 'BEGIN{FS=":"}{print $1}'| grep -v lo)
for i in $wangka
do
ip a show dev $i | awk 'NR==3{print $2}' | awk -F'/' '{print $1}'
done
完结撒花
凤凰羽化之后是要腾空的, 是要翱翔九万里的。