安装 ipmi 包:
$ apt install ipmitool
编写脚本 set_bmc.sh
内容如下:
#!/bin/bash
ipsrc=$1
ipaddr=$2
netmask=$3
gateway=$4
set_ipsrc(){
echo -e "*****************"
ipmitool lan set 1 ipsrc $ipsrc
}
set_ip(){
echo -e "*****************"
ipmitool lan set 1 ipaddr $ipaddr
}
set_netmask(){
echo -e "*****************"
ipmitool lan set 1 netmask $netmask
}
set_gateway(){
echo -e "*****************"
ipmitool lan set 1 defgw ipaddr $gateway
}
set_ipsrc
if [ $? -eq 0 ];then
echo -e "set ipsource to static===>\033[42;37m Pass \033[0m\n"
else
echo -e "\033[41;37m Error code:1 \033[0m"
exit 1
fi
sleep 10
set_ip
if [ $? -eq 0 ];then
echo -e "set static ip===>\033[42;37m Pass \033[0m\n"
else
echo -e "\033[41;37m Error code:2 \033[0m"
exit 2
fi
sleep 10
set_netmask
if [ $? -eq 0 ];then
echo -e "set static netmask===>\033[42;37m Pass \033[0m\n"
else
echo -e "\033[41;37m Error code:3 \033[0m"
exit 3
fi
sleep 10
set_gateway
if [ $? -eq 0 ];then
echo -e "set static default gateway===>\033[42;37m Pass \033[0m\n"
else
echo -e "\033[41;37m Error code:4 \033[0m"
exit 4
fi
sleep 10
使用方法:
$ ./set_bmc.sh static 192.168.1.10 255.255.255.0 192.168.1.1
评论区