1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
#!/bin/bash
#
# Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# Redistribution of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# Redistribution in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# Neither the name of Sun Microsystems, Inc. or the names of
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# This software is provided "AS IS," without a warranty of any kind.
# ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
# INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
# SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
# FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
# OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
# SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
# OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
# PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
# LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
# EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
# This script is designed for Sun Fire LX50, V60x and V65x systems.
# It may work with other setups as long as you use the correct channel
# and interface settings. It can be used on the V20z as long as you
# specify network settings on the command line.
#
# If the wrong channel is used you could lose network access to the
# box because your BMC will be sending out bad Gratuitous ARP packets
# with the wrong MAC address. You will need to use a console or
# override your local ARP cache with the correct addr.
usage ()
{
echo "
usage: $0 -c <chan> -i <interface> [options]
$0 -c <chan> [-v|w|x|y|z address] [options]
-c channel Which BMC channel to configure [-c help for more info]
-i interface Auto-configure BMC based on interface network settings
-v address Use specified IP address
-w address Use specified Netmask address
-x address Use specified MAC address
-y address Use specified Gateway IP address
-z address Use specified Gateway MAC address
-m interface Which IPMI interface to use [default linux=open solaris=lipmi]
-p password Set BMC channel password
-s string Set SNMP community string
-a interval Set Gratuitous ARP interval, off=0, default=4
-r Reset BMC channel, zero all network settings, disable
-d Debug mode, does not make any changes
"
exit 0;
}
channel_usage ()
{
echo "
Sun Fire V60x and V65x - Linux 2.4
eth0 = channel 6, top
eth1 = channel 7, bottom
Sun Fire V60x and V65x - Linux 2.6
eth0 = channel 7, bottom
eth1 = channel 6, top
Sun Fire V60x and V65x - Solaris x86
e1000g0 = channel 7, bottom
e1000g1 = channel 6, top
Sun LX50 - Linux
eth0 = channel 7, bottom
eth1 = channel 6, top
Sun LX50 - Solaris x86
le0 = channel 7, bottom
le1 = channel 6, top
Sun Fire V20z (-i option does not apply)
channel 1
"
exit 0
}
hex_to_ip ()
{
test $# -ge 1 || return;
local HEX B1 B2 B3 B4;
HEX=`echo $1 | tr '[:lower:]' '[:upper:]'`;
H1=`echo $HEX | cut -c1-2`
H2=`echo $HEX | cut -c3-4`
H3=`echo $HEX | cut -c5-6`
H4=`echo $HEX | cut -c7-8`
B1=`echo 10 o 16 i $H1 p | dc`
B2=`echo 10 o 16 i $H2 p | dc`
B3=`echo 10 o 16 i $H3 p | dc`
B4=`echo 10 o 16 i $H4 p | dc`
echo "$B1.$B2.$B3.$B4"
}
ipmitool_lan_set ()
{
[ $# -lt 1 ] && return
local PARAM=$1
local VALUE=
[ $# -ge 2 ] && VALUE=$2
if [ $DEBUG -gt 0 ]; then
echo "Setting LAN parameter $PARAM $VALUE"
echo "$IPMITOOL -I $IPMIINTF lan set $CHANNEL $PARAM $VALUE"
return
fi
$IPMITOOL -I $IPMIINTF lan set $CHANNEL $PARAM $VALUE
}
ipmitool_lan_reset ()
{
ipmitool_lan_set "ipsrc" "static"
ipmitool_lan_set "ipaddr" "0.0.0.0"
ipmitool_lan_set "netmask" "0.0.0.0"
ipmitool_lan_set "macaddr" "00:00:00:00:00:00"
ipmitool_lan_set "defgw ipaddr" "0.0.0.0"
ipmitool_lan_set "defgw macaddr" "00:00:00:00:00:00"
ipmitool_lan_set "password"
ipmitool_lan_set "snmp" "public"
ipmitool_lan_set "arp generate" "off"
ipmitool_lan_set "access" "off"
exit 0
}
DEBUG=0
LINUX=0
SOLARIS=0
CHANNEL=0
IFACE=
PASSWORD=
SNMP=
GRATARP=8
PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin
case `uname -s` in
Linux)
IPMIINTF=open
IPMITOOL=ipmitool
PING=ping
IFCONFIG=ifconfig
ARP=arp
ROUTE=route
;;
SunOS)
IPMIINTF=lipmi
IPMITOOL=ipmiadm
PING=ping
IFCONFIG=ifconfig
ARP=arp
ROUTE=route
;;
*)
echo "Invalid OS!"
exit 1
esac
while getopts "dhri:c:m:p:s:a:v:w:x:y:z:" OPTION ; do
case "$OPTION" in
i) IFACE=$OPTARG ;;
c) CHANNEL=$OPTARG ; test X$CHANNEL = Xhelp && channel_usage ;;
m) IPMIINTF=$OPTARG ;;
p) PASSWORD=$OPTARG ;;
s) SNMP=$OPTARG ;;
a) GRATARP=$OPTARG ;;
d) DEBUG=1 ;;
v) IP_ADDRESS=$OPTARG ;;
w) IP_NETMASK=$OPTARG ;;
x) MAC_ADDRESS=$OPTARG ;;
y) GATEWAY_IP=$OPTARG ;;
z) GATEWAY_MAC=$OPTARG ;;
r) ipmitool_lan_reset ;;
h) usage ;;
*) echo "Ignoring invalid option : -$OPTARG" ;;
esac
done
if [ ! -x `which $IPMITOOL` ]; then
echo "Error: unable to find $IPMITOOL"
exit 1
fi
if [ $CHANNEL -eq 0 ]; then
echo
echo "Error: you must specify a channel with -c"
echo
exit 1
fi
if [ "$IFACE" ]; then
if ! $IFCONFIG $IFACE 2>/dev/null | grep "inet " >/dev/null 2>&1 ; then
echo
echo "Error: unable to find interface $IFACE"
echo
exit 1
fi
echo "Auto-configuring $IFACE (channel $CHANNEL)"
fi
case `uname -s` in
SunOS)
if [ X$IFACE != X ]; then
if [ X$IP_ADDRESS = X ]; then
IP_ADDRESS=`$IFCONFIG $IFACE | grep inet | awk '{print $2}'`
fi
if [ X$IP_NETMASK = X ]; then
HEX_NETMASK=`$IFCONFIG $IFACE | grep netmask | awk '{print $4}'`
IP_NETMASK=`hex_to_ip $HEX_NETMASK`
fi
if [ X$MAC_ADDRESS = X ]; then
MAC_ADDRESS=`$IFCONFIG $IFACE | grep ether | awk '{print $2}'`
fi
if [ X$GATEWAY_IP = X ]; then
GATEWAY_IP=`$ROUTE -n get default | grep gateway: | awk '{print $2}'`
fi
if [ X$GATEWAY_MAC = X ]; then
$PING -i $IFACE $GATEWAY_IP 1 >/dev/null 2>&1
GATEWAY_MAC=`$ARP $GATEWAY_IP | awk '{print $4}'`
if [ X$GATEWAY_MAC = Xno ]; then
GATEWAY_MAC=
fi
fi
fi
;;
Linux)
if [ X$IFACE != X ]; then
if [ X$IP_ADDRESS = X ]; then
IP_ADDRESS=`$IFCONFIG $IFACE | grep "inet addr" | awk -F"[:[:space:]]+" '{print $4}'`
fi
if [ X$IP_NETMASK = X ]; then
IP_NETMASK=`$IFCONFIG $IFACE | grep Bcast | awk -F"[:[:space:]]+" '{print $8}'`
fi
if [ X$MAC_ADDRESS = X ]; then
MAC_ADDRESS=`$IFCONFIG $IFACE | grep HWaddr | awk '{print $5}'`
fi
if [ X$GATEWAY_IP = X ]; then
GATEWAY_IP=`$ROUTE -n | awk '/^0.0.0.0/ {print $2}'`
fi
if [ X$GATEWAY_MAC = X ]; then
$PING -q -c1 $GATEWAY_IP >/dev/null 2>&1
GATEWAY_MAC=`$ARP -an | grep "$GATEWAY_IP[^0-9]" | awk '{print $4}'`
fi
fi
;;
esac
if [ X$IP_ADDRESS != X ]; then
ipmitool_lan_set "ipsrc" "static"
ipmitool_lan_set "ipaddr" "$IP_ADDRESS"
fi
if [ X$IP_NETMASK != X ]; then
ipmitool_lan_set "netmask" "$IP_NETMASK"
fi
if [ X$MAC_ADDRESS != X ]; then
ipmitool_lan_set "macaddr" "$MAC_ADDRESS"
fi
if [ X$GATEWAY_IP != X ]; then
ipmitool_lan_set "defgw ipaddr" "$GATEWAY_IP"
fi
if [ X$GATEWAY_MAC != X ]; then
ipmitool_lan_set "defgw macaddr" "$GATEWAY_MAC"
fi
if [ X$PASSWORD != X ]; then
ipmitool_lan_set "password" "$PASSWORD"
fi
if [ X$SNMP != X ]; then
ipmitool_lan_set "snmp" "$SNMP"
fi
if [ "$GRATARP" -ne 0 ]; then
ipmitool_lan_set "arp generate" "on"
ipmitool_lan_set "arp interval" "$GRATARP"
else
ipmitool_lan_set "arp generate" "off"
fi
echo "Setting channel authentication capabilities"
ipmitool_lan_set "auth callback,user,operator,admin" "md2,md5"
echo "Enabling channel $CHANNEL"
ipmitool_lan_set "access" "on"
ipmitool_lan_set "user"
exit 0
|