123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- #!/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
|