命令配置bmc管理口

当不知道服务器的BMC(Baseboard Management Controller)的管理IP和用户信息时,可以在服务器安装的系统上安装ipmitool工具,然后通过带内的方式来直接配置BMC的网络和IP等信息,省去重启机器去寻找BMC配置界面进行设置的步骤。

 

以下示例是通过带内方式来配置,如果要通过带外的方式来配置,在ipmitool命令后面加上“–H BMCip –U username –P password”等参数

 

1.设置BMC的网络信息

1)显示BMC的IP地址信息(可以使用其它通道号如2,3,4等来查看设备可以使用的通道的信息,通常配置通道1,以下命令中的1都是代表配置通道1)
# ipmitool lan print 1
# ipmitool channel info 1

2)设置通道1使用静态IP地址。
# ipmitool lan set 1 ipsrc static

3)设置BMC的IP地址。
# ipmitool lan set 1 ipaddr 192.168.100.142

4)设置BMC的子网掩码。
# ipmitool lan set 1 netmask 255.255.255.0

5)设置 IPMI的网关。
# ipmitool lan set 1 defgw ipaddr 192.168.100.254

6)确认BMC的IP地址信息
# ipmitool lan print 1

Set in Progress         : Set Complete
Auth Type Support       : MD5 PASSWORD 
Auth Type Enable        : Callback : MD5 PASSWORD 
                        : User     : MD5 PASSWORD 
                        : Operator : MD5 PASSWORD 
                        : Admin    : MD5 PASSWORD 
                        : OEM      : 
IP Address Source       : Static Address
IP Address              : 192.168.100.142
Subnet Mask             : 255.255.255.0
MAC Address             : 00:1e:67:54:6d:ca
SNMP Community String   : public
IP Header               : TTL=0x00 Flags=0x00 Precedence=0x00 TOS=0x00
BMC ARP Control         : ARP Responses Enabled, Gratuitous ARP Disabled
Gratituous ARP Intrvl   : 0.0 seconds
Default Gateway IP      : 192.168.100.254
Default Gateway MAC     : 00:00:00:00:00:00
Backup Gateway IP       : 0.0.0.0
Backup Gateway MAC      : 00:00:00:00:00:00
802.1q VLAN ID          : Disabled
802.1q VLAN Priority    : 0
RMCP+ Cipher Suites     : 0,1,2,3,4,6,7,8,9,11,12,13,15,16,17,18
Cipher Suite Priv Max   : caaaaaaaaaaaaaa
                        :     X=Cipher Suite Unused
                        :     c=CALLBACK
                        :     u=USER
                        :     o=OPERATOR
                        :     a=ADMIN
                        :     O=OEM
Bad Password Threshold  : Not Available

 

2.设置BMC的用户

1)列出BMC用户的信息。
# ipmitool user list 1

ID  Name             Callin  Link Auth  IPMI Msg   Channel Priv Limit
1                    false   false      true       ADMINISTRATOR
2   lenovo           false   true       true       ADMINISTRATOR
3   three            false   false      true       ADMINISTRATOR
4   test1            false   false      true       ADMINISTRATOR
5   test2            false   false      true       ADMINISTRATOR
6                    true    false      false      NO ACCESS
7                    true    false      false      NO ACCESS
8                    true    false      false      NO ACCESS
9                    true    false      false      NO ACCESS
10                   true    false      false      NO ACCESS
11                   true    false      false      NO ACCESS
12                   true    false      false      NO ACCESS
13                   true    false      false      NO ACCESS
14                   true    false      false      NO ACCESS
15                   true    false      false      NO ACCESS

2)创建新的用户(可以直接修改管理用户的密码,不创建新的用户)
# ipmitool user set name 6 test3 (6是上面命令列出的其中一个未使用的用户ID号)

3)设置用户的密码
# ipmitool user set password 6 len0vO (6是用户test3的用户ID号)

4)给新建的用户赋予权限
# ipmitool channel setaccess 1 6 callin=on ipmi=on link=on privilege=4 (6是用户test3的用户ID号)

5)检查确认用户的信息
# ipmitool user list 1

ID  Name             Callin  Link Auth  IPMI Msg   Channel Priv Limit
1                    false   false      true       ADMINISTRATOR
2   lenovo           false   true       true       ADMINISTRATOR
3   three            false   false      true       ADMINISTRATOR
4   test1            false   false      true       ADMINISTRATOR
5   test2            false   false      true       ADMINISTRATOR
6   test3            true    true       true       ADMINISTRATOR
7                    true    false      false      NO ACCESS
8                    true    false      false      NO ACCESS
9                    true    false      false      NO ACCESS
10                   true    false      false      NO ACCESS
11                   true    false      false      NO ACCESS
12                   true    false      false      NO ACCESS
13                   true    false      false      NO ACCESS
14                   true    false      false      NO ACCESS
15                   true    false      false      NO ACCESS

配置好BMC的网络和用户后,就可以通过浏览器登录服务器的管理界面,对设备进行日常的管理(通常用来做监控和故障诊断)。

 

 

service ipmi start #开启ipmi服务
ipmitool lan set 1 ipsrc static ##设置静态
ipmitool lan set 1 ipaddr 110.204.3.81 ##设置ip
ipmitool lan set 1 netmask 255.255.248.0 ##设置掩码
ipmitool lan set 1 defgw ipaddr 110.204.7.254 设置网关
ipmitool user set name 2 aaaaaa ##设置用户
ipmitool user set password 2 ‘aaaaaa’ #设置密码
ipmitool user list 1 #查看管理口用户
ipmitool lan print 1 #查看管理口配置情况

 

以下是带外安装,也就是ipmitools安装在外部pc上的操作命令:

ipmitool命令详解

原文链接:https://www.cnblogs.com/EricDing/p/8995263.html

[root@localhost ~]# yum install -y ipmitool #安装这个包

#service ipmi start
#ipmitool -I open shell

可以直接进入本地BMC sh
一、开关机,重启

查看开关机状态:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) power status

开机:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) power on

关机:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) power off

重启:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) power reset

二、用户管理

说明:[ChannelNo] 字段是可选的,ChannoNo为1或者8;BMC默认有2个用户:user id为1的匿名用户,user id为2的ADMIN用户;<>字段为必选内容;:2为user权限,3为Operator权限,4为Administrator权限;

查看用户信息:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) user list [ChannelNo]

增加用户:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) user set name

设置密码:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) user set password

设置用户权限:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) user priv [ChannelNo]

启用/禁用用户:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) user enable/disable

三、IP网络设置

说明:[ChannelNo] 字段是可选的,ChannoNo为1(Share Nic网络)或者8(BMC独立管理网络);设置网络参数,必须首先设置IP为静态,然后再进行其他设置;

查看网络信息:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) lan print [ChannelNo]

修改IP为静态还是DHCP模式:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) lan set ipsrc <static/dhcp>

修改IP地址:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) lan set ipaddr

修改子网掩码:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) lan set netmask

修改默认网关:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) lan set defgw ipaddr <默认网关>

四、SOL功能

说明:<9.6/19.2/38.4/57.6/115.2>其中115.2代表115200,即*1000是表示的波特率。

设置SOL串口波特率:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) sol set volatile-bit-rate <9.6/19.2/38.4/57.6/115.2>

打开SOL功能:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) sol activate

关闭SOL功能:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) sol deactivate

五、SEL日志查看

查看SEL日志:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) sel list

六、FRU信息查看

查看FRU信息:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) fru list

七、SDR,Sensor信息查看

查看SDR Sensor信息:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) sdr

查看Sensor信息:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) sensor list

八、mc(管理单元BMC)状态和控制

重启动BMC:
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) mc reset <warm/cold>

九、设置BMC的iptables防火墙

设置某一段IP可以访问BMC
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) raw 0x32 0x76 0x01 0x01 ip1(0xa 0xa 0xa 0xa) ip2(0xb 0xb 0xb 0xb)

ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) raw 0x32 0x76 0x09

设置某个IP可以访问BMC
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) raw 0x32 0x76 0x00 0x01 ip1(0xa 0xa 0xa 0xa)

ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) raw 0x32 0x76 0x09

取消设置
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) raw 0x32 0x76 0x08

4.获取防火墙设置

ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) raw 0x32 0x77 0x01 0x00

阻止/开启某个端口
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) raw 0x32 0x76 0x02 0x00/0x01 0x00 (portno)0x22 0x00

取消某个端口的设置(6是5的对应取消操作)
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) raw 0x32 0x76 0x06 0x00/0x01 0x00 (portno)0x22 0x00

#service ipmi start
#ipmitool -I open shell

可以直接进入本地BMC shell
#ipmitool -I lan -H -U shell

输入password,进入IPMI交互模式,当然这里也可以把shell直接换成bmc命令 , 另外ipmitool支持端口,所以是否可以先做DNAT,然后远程直接管理内网机器.
ipmitool提供的功能要比windows下ipmish提供的功能多得多,用法相对复杂一些


参考下面转摘的文章来详细了解命令
引用
Ipmitool本地监控使用命令:ipmitool –I open command,其中-I open表示使用OpenIPMI接口,command有以下项:
a) raw:发送一个原始的IPMI请求,并且打印回复信息。
b) Lan:配置网络(lan)信道(channel)
c) chassis :查看底盘的状态和设置电源
d) event:向BMC发送一个已经定义的事件(event),可用于测试配置的SNMP是否成功
e) mc: 查看MC(Management Contollor)状态和各种允许的项
f) sdr:打印传感器仓库中的所有监控项和从传感器读取到的值。
g) Sensor:打印详细的传感器信息。
h) Fru:打印内建的Field Replaceable Unit (FRU)信息
i) Sel: 打印 System Event Log (SEL)
j) Pef: 设置 Platform Event Filtering (PEF),事件过滤平台用于在监控系统发现有event时候,用PEF中的策略进行事件过滤,然后看是否需要报警。
k) Sol/isol:用于配置通过串口的Lan进行监控
l) User:设置BMC中用户的信息 。
m) Channel:设置Management Controller信道。


Ipmitool –I open sensor list命令可以获取传感器中的各种监测值和该值的监测阈值,包括(CPU温度,电压,风扇转速,电源调制模块温度,电源电压等信息)
Ipmitool –I open sensor get “CPU0Temp”可以获取ID为CPU0Temp监测值,CPU0Temp是sensor的ID,服务器不同,ID表示也不同。
Ipmitool –I open sensor thresh 设置ID值等于id的监测项的各种限制值。
Ipmitool –I open chassis status查看底盘状态,其中包括了底盘电源信息,底盘工作状态等
Ipmitool –I open chassis restart_cause查看上次系统重启的原因
Ipmitool –I open chassis policy list 查看支持的底盘电源相关策略。
Ipmitool –I open chassis power on启动底盘,用此命令可以远程开机
Ipmitool –I open chassis power off关闭底盘,用此命令可以远程开机
Ipmitool –I open chassis power reset实现硬重启,用此命令可以远程开机
Ipmi还可以设置系统启动boot的设备,具体见ipmitool帮助文档。
Ipmitool –I open mc reset 使BMC重新硬启动
Ipmitool –I open mc info 查看BMC硬件信息
Ipmitool –I open mc getenables 列出BMC所有允许的选项
Ipmitool –I open mc setenables =[on|off],设置bmc相应的允许/禁止选项。
Ipmitool-I open event 1 发送一个温度过高的消息到System Event Log中,可以发送的Event有:
1 Temperature: Upper Critical: Going High
2 Voltage Threshold: Lower Critical: Going Low
3 Memory: Correctable ECC Error Detected
Ipmitool-I open event命令可以用测试配置的IPMI中的snmp功能是否成功。
Ipmitool -I open lan print 1 打印现咱channel 1的信息 。
Ipmitool -I open lan set 1 ipaddr 10.10.113.95设置channel 1 的地址为10.10.113.95
Ipmitool -I open lan set 1 snmp public设置channel 1 上snmp的community为public。
Ipmitool -I open lan set 1 access on设置channel 1允许访问。
Ipmitool -I open pef info打印Platform Event Filtering (pef)信息
Ipmitool -I open pef status查看Platform Event Filtering (pef)状态
Ipmitool -I open pef policy查看Platform Event Filtering (pef)策略设置
Ipmitool -I open sdr list fru 读取fru信息并显示。

[root@localhost ~]# yum install -y ipmitool #安装这个包

电源相关:

#开启电源

ipmitool -I lanplus -H 10.41.1.41 -U root -P root power on

#关闭电源

ipmitool -I lanplus -H 10.41.1.41 -U root -P root power off

#重启电源

ipmitool -I lanplus -H 10.41.1.41 -U root -P root power reset

#查看电源状态

ipmitool -I lanplus -H 10.41.1.41 -U root -P root power status

启动项相关:

#设置为BIOS启动

ipmitool -I lanplus -H 10.41.1.41 -U root -P root chassis bootparam set bootflag force_bios

#设置为pxe启动

ipmitool -I lanplus -H 10.41.1.41 -U root -P root chassis bootparam set bootflag force_pxe

#设置为光盘启动

ipmitool -I lanplus -H 10.41.1.41 -U root -P root chassis bootparam set bootflag force_cdrom

#设置为硬盘启动

ipmitool -I lanplus -H 10.41.1.41 -U root -P root chassis bootparam set bootflag force_disk

#重启BMC

ipmitool -I lanplus -H 10.41.1.41 -U root -P root mc reset cold

#修改BMC密码

ipmitool -I lanplus -H 10.41.1.41 -U root -P root user set password 2 new_password #new_password 这个是新密码

#远程文本重定向 重启服务器就能看到画面

ipmitool -I lanplus-H 10.41.1.41 -U root -P root sol activate

#当有这个错误时 Info: SOL payload already active on another session

ipmitool -I lanplus-H 10.41.1.41 -U root -P root sol deactivate #这命令是踢出其他的人会话

#获取mac地址 有些机型不准 我这个是dell的服务器 华为服务器也可以使用

“”“ipmitool -I lanplus -H 10.41.1.41 -U root -P root lan print |grep “MAC Address”|awk ‘{print $NF}’”""

python 脚本

from subprocess import Popen, PIPE
cmd = “”“ipmitool -I lanplus -H 10.41.1.41 -U root -P root lan print |grep “MAC Address”|awk ‘{print $NF}’”""
text = Popen(cmd, stdout=PIPE, shell=True).stdout.read()
prefix_mac = text[:-3]
last_two = text[-2:]
plus_one = int(last_two, 16) - 2
plus_one2 = int(last_two, 16) - 1
new_last_two = hex(plus_one)[2:]
new_last_two2 = hex(plus_one2)[2:]
if len(new_last_two) == 1:
new_last_two = ‘0’ + new_last_two
if len(new_last_two2) == 1:
new_last_two2 = ‘0’ + new_last_two2
new_mac = prefix_mac.replace(’:’,’’) + new_last_two
new_mac2 = prefix_mac.replace(’:’,’’) + new_last_two2
print(new_mac,new_mac2)

获取网卡1mac地址和网卡2mac地址



posted @ 2021-11-09 11:43  DMCF  阅读(4766)  评论(0编辑  收藏  举报