Linux centos7.9 打印内网IP
ip addr show | grep 'inet ' | grep -v '127.0.0.1'| grep -v '172.17.0.1' | grep -v '172.18.0.1' | awk '{print $2}' | cut -d/ -f1
将以上命令写入sh脚本
#!/bin/bash
# 获取当前服务器的内网IP地址
internal_ip=$(ip addr show | grep 'inet ' | grep -v '127.0.0.1'| grep -v '172.17.0.1' | grep -v '172.18.0.1' | awk '{print $2}' | cut -d/ -f1)
if [ "$internal_ip" = "10.10.20.132" ]; then
echo "find it success"
echo "is my target"
else
echo "find it error"
echo "not my target"
fi