#!/bin/bash ip="" ifconfig eth0 >/dev/null 2>&1 if [ $? -eq 0 ]; then ip=$(ifconfig eth0 | grep "inet addr" | awk '{print $2}' | awk -F: '{print $2}') fi if [ -z "$ip" ]; then ifconfig bond0 >/dev/null 2>&1 if [ $? -eq 0 ]; then ip=$(ifconfig bond0 | grep "inet addr" | awk '{print $2}' | awk -F: '{print $2}') fi fi if [ -z "$ip" ]; then ifconfig net0 >/dev/null 2>&1 if [ $? -eq 0 ]; then ip=$(ifconfig net0 | grep "inet addr" | awk '{print $2}' | awk -F: '{print $2}') fi fi echo "IP address: $ip

centos7网卡名称可能是eth0 可能是bond0 可能是 net0 请获取网卡IP如果eth0卡不存则去获取bond0以次类推写出shell

原文地址: http://www.cveoy.top/t/topic/cEcc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录