Novell Home

AutoYaST: Network Auto Configuration Script

Novell Cool Solutions: Feature
By Cameron Seader

Digg This - Slashdot This

Updated: 3 Oct 2007
 

Application:

If you have an environment where you want to use one single Autoinst.xml for setting up your systems, and you want them all to have different static IP addresses for one Active Ethernet interface, then the following should help you accomplish this goal.

Explanation:

There are two assumptions made before using this script.

  1. Your DNS is defined for each host that is getting setup with this script/Autoinst.xml.
  2. Your DHCP is setup so that each host that is getting setup with this script/Autoinst.xml has a static host definition defined in the dhcpd.conf.

Here is an example of a static host definition:

group test{
# Hosts List.
host test-host1 { fixed-address 172.18.0.100; hardware ethernet 00:11:22:33:44:55; }
host test-host2 { fixed-address 172.18.0.101; hardware ethernet 00:22:99:88:77:66; }
}

This script takes the dynamic address information received and makes it into a static configuration. Keeping that in mind we need to execute this script at a point during the installation that it won't interfere with the rest of the install. One such point that stands out to me is during the Init Scripts element of the AutoYaST xml. You can find reference to the syntax of this element in the following locations.

Script:

Copy the text below and paste it into the Init Scripts element of your Autoinst.xml.

#!/bin/bash
#network_setup.sh

### Disable IPV6 - comment this line out if you don't want to disable IPV6
echo 'install ipv6 /bin/true' >> /etc/modprobe.conf.local

### Variables to Calculate Network Configuration Settings for a static configuration 
ACTIVE_INTERFACE=`/sbin/ifconfig | grep eth | awk '{print $1}'`
IP_ADDRESS=`/sbin/ifconfig $ACTIVE_INTERFACE | grep 'inet addr' | awk '{print $2}' | sed 's/addr://'`
NETMASK=`/sbin/ifconfig $ACTIVE_INTERFACE | grep 'inet addr' | awk '{print $4}' | sed 's/Mask://'`
BROADCAST=`/sbin/ifconfig $ACTIVE_INTERFACE | grep Bcast: | awk '{ print $3 }' | sed 's/Bcast://'`
NETWORK=`/sbin/ip route list | grep $IP_ADDRESS | awk '{ print $1 }' | sed 's/\/[1-9][1-9]//'`
GATEWAY=`/sbin/route | grep default | awk '{print $2}'`
HOSTNAME=`/usr/bin/host $IP_ADDRESS | awk '{print $5}' | sed '$s/.$//'`

### Setup HOSTNAME
echo "$HOSTNAME" > /etc/HOSTNAME

### Setup Gateway Address
echo "default $GATEWAY - -" > /etc/sysconfig/network/routes

### Setup /etc/hosts with correct host information
HOST=`/usr/bin/host $IP_ADDRESS | awk '{print $5}' | sed '$s/.$//' | cut -d "." -f 1`
echo "$IP_ADDRESS   $HOSTNAME $HOST" >> /etc/hosts

### Network configuration file rewrite for static configuration

INT_CONF_FILE=/etc/sysconfig/network/ifcfg-eth-id-`ifconfig eth0 | grep HWaddr | awk '{ print $5 }' | perl -ne '$var=$_; print lc($var)'`

echo 'DEVICE=eth0' > $INT_CONF_FILE
echo 'BOOTPROTO=static' >> $INT_CONF_FILE
echo "IPADDR=$IP_ADDRESS" >> $INT_CONF_FILE
echo "NETMASK=$NETMASK" >> $INT_CONF_FILE
echo "BROADCAST=$BROADCAST" >> $INT_CONF_FILE
echo "NETWORK=$NETWORK" >> $INT_CONF_FILE
echo 'STARTMODE=onboot' >> $INT_CONF_FILE
echo 'TYPE=Ethernet' >> $INT_CONF_FILE

### Restart Network
/etc/init.d/network restart

Once you have it copied into the Autoinst.xml in the Init Scripts element it will look like the example below. Feel free to copy this straight out of here and put it in your Autoinst.xml if you would like.

    <scripts>
      <init-scripts config:type="list">
        <listentry>
          <filename>network_setup</filename>
          <interpreter>shell</interpreter>
          <source><![CDATA[#!/bin/bash
### Disable ipv6
echo 'install ipv6 /bin/true' >> /etc/modprobe.conf.local

### Variables to Calculate Network Configuration Settings for a static configuration ###
ACTIVE_INTERFACE=`/sbin/ifconfig | grep eth | awk '{print $1}'`
IP_ADDRESS=`/sbin/ifconfig $ACTIVE_INTERFACE | grep 'inet addr' | awk '{print $2}' | sed 's/addr://'`
NETMASK=`/sbin/ifconfig $ACTIVE_INTERFACE | grep 'inet addr' | awk '{print $4}' | sed 's/Mask://'`
BROADCAST=`/sbin/ifconfig $ACTIVE_INTERFACE | grep Bcast: | awk '{ print $3 }' | sed 's/Bcast://'`
NETWORK=`/sbin/ip route list | grep $IP_ADDRESS | awk '{ print $1 }' | sed 's/\/[1-9][1-9]//'`
GATEWAY=`/sbin/route | grep default | awk '{print $2}'`
HOSTNAME=`/usr/bin/host $IP_ADDRESS | awk '{print $5}' | sed '$s/.$//'`

### Setup HOSTNAME
echo "$HOSTNAME" > /etc/HOSTNAME

### Setup Gateway Address
echo "default $GATEWAY - -" > /etc/sysconfig/network/routes

### Setup /etc/hosts with correct host information
HOST=`/usr/bin/host $IP_ADDRESS | awk '{print $5}' | sed '$s/.$//' | cut -d "." -f 1`
echo "$IP_ADDRESS   $HOSTNAME $HOST" >> /etc/hosts

### Network configuration file rewrite for static configuration

INT_CONF_FILE=/etc/sysconfig/network/ifcfg-eth-id-`ifconfig eth0 | grep HWaddr | awk '{ print $5 }' | perl -ne '$var=$_; print lc($var)'`

echo 'DEVICE=eth0' > $INT_CONF_FILE
echo 'BOOTPROTO=static' >> $INT_CONF_FILE
echo "IPADDR=$IP_ADDRESS" >> $INT_CONF_FILE
echo "NETMASK=$NETMASK" >> $INT_CONF_FILE
echo "BROADCAST=$BROADCAST" >> $INT_CONF_FILE
echo "NETWORK=$NETWORK" >> $INT_CONF_FILE
echo 'STARTMODE=onboot' >> $INT_CONF_FILE
echo 'TYPE=Ethernet' >> $INT_CONF_FILE

### Restart Network
/etc/init.d/network restart
]]></source>
        </listentry>
      </init-scripts>
    </scripts>

Now run through an AutoYaST installation and see how it works out. If you run into trouble you can look at the installation logs at /var/adm/YaST/.

You could in fact adapt this script to auto configure multiple Ethernet Interfaces if you had the need.

10/03/2007 - Note: With SLE10 you will need to modify the lines for Disabling ipv6, you can comment out the line that I include above and add in the follwing lines.

sed -e "s/^#//" /etc/modprobe.d/ipv6 > /etc/modprobe.d/ipv6.new
cp /etc/modprobe.d/ipv6 /etc/modprobe.d/ipv6.orig
cp /etc/modprobe.d/ipv6.new /etc/modprobe.d/ipv6 

Enjoy!!


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell