效果图
代码
#!/bin/bash
#功能: 查看本机IP地址
# define colors.
RED='\E[31m'
GREEN='\E[32m'
YELLOW='\E[33m'
RES='\033[0m'
nic_name='ens33'
ipaddr=`ifconfig ${nic_name}|awk 'NR==2{print $2,$3,$4}'`
defrouter=`ip route|awk 'NR==1{print $3}'`
echo -e "${RED}当前的网络信息是: ${YELLOW}IP ${ipaddr} Gateway ${defrouter} ${RES}"