AutoYaST: Network Auto Configuration Script | SUSE Communities

AutoYaST: Network Auto Configuration Script

Share
Share

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!!

Share
(Visited 1 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

No comments yet

Avatar photo
6,092 views
cseader Senior Innovative Technologist with over 15 years of experience delivering creative, customer-centric value and solutions. Broad experience in many different verticals, architectures, and data center environments. Proven leadership experience ranging from evaluating technology, collaborating across engineering teams and departments, competitive analysis, and strategic planning. Highly-motivated with a track record of success in consistent achievement of projects and goals, and driving business function and management. Skilled problem identifier and troubleshooter, continually learning and adapting, and strong analytical skills. Efficient, organized leader with success in coordinating efforts within internal-external teams to reach and surpass expectations. Expert-level skills in the implementation, analysis, optimization, troubleshooting, and documentation of mode 1 and mode 2 data center systems.