[NCLUG] RH networking scripts

Michael Dwyer mdwyer at sixthdimension.com
Mon Oct 29 10:01:39 MST 2001


> Those of you who use Red Hat for serious systems -- I mean,
> commercial and enterprise customers of RH and its derivatives,
> as distict from bottom-feeding home workstation types like me.
> Do you use the networking scripts that RH supplies? And if not,
> what procedure do you use to avoid them?

Amen, brother...  I'm still hooked on BSD-style init scripts
to start my networking.  They make SO much more sense to me...
They aren't quite so read-only as the Red Hat ones.

This is the rc.inet1 script from Slackware.  It depends on
/etc/HOSTNAME, and that's about it.  It starts up the loopback
and the ethernet interface, then sets the default route.

Mind you, this script handles nothing with regards to PPP.  But
it handles everything else quite neatly, I think.

Keep in mind that you lose the easy-configurability of sysconfig,
and may still have to maintain sysconfig for anything else that
depends on it.  But if all you want is a simple script to start
your network, this one will do it.

-=-=-=- Cut Here -=-=-=-

#! /bin/sh
#
# rc.inet1      This shell script boots up the base INET system.
#
# Version:      @(#)/etc/rc.d/rc.inet1  2.00    10/06/1999
#

HOSTNAME=`cat /etc/HOSTNAME`

# Attach the loopback device.
/sbin/ifconfig lo 127.0.0.1
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo

# IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure
the
# eth0 interface.

# Edit these values to set up a static IP address:
IPADDR="192.168.1.212"  # REPLACE with YOUR IP address!
NETMASK="255.255.255.0" # REPLACE with YOUR netmask!
NETWORK="192.168.1.0"   # REPLACE with YOUR network address!
BROADCAST="192.168.1.255"       # REPLACE with YOUR broadcast address,
if you
                        # have one. If not, leave blank and edit below.
GATEWAY="192.168.1.1"   # REPLACE with YOUR gateway address!

# To use DHCP instead of a static IP, set this value to "yes":
DHCP="no"            # Use DHCP ("yes" or "no")

# OK, time to set up the interface:
if [ "$DHCP" = "yes" ]; then # use DHCP to set everything up:
  echo "Attempting to configure eth0 by contacting a DHCP server..."
  /sbin/dhcpcd
elif [ ! "$IPADDR" = "127.0.0.1" ]; then # set up IP statically:
  # Set up the ethernet card:
  echo "Configuring eth0 as ${IPADDR}..."
  /sbin/ifconfig eth0 ${IPADDR} broadcast ${BROADCAST} netmask
${NETMASK}

  # If that didn't succeed, give the system administrator some hints:
  if [ ! $? = 0 ]; then
    cat << EOF

Big Long Message about how your network failed to start cut for brevity.

EOF
  fi

  # Older kernel versions need this to set up the eth0 routing table:
  KVERSION=`uname -r | cut -f 1,2 -d .`
  if [ "$KVERSION" = "1.0" -o "$KVERSION" = "1.1" \
   -o "$KVERSION" = "1.2" -o "$KVERSION" = "2.0" -o "$KVERSION" = "" ];
then
    /sbin/route add -net ${NETWORK} netmask ${NETMASK} eth0
  fi

  # If there is a gateway defined, then set it up:
  if [ ! "$GATEWAY" = "" ]; then
    /sbin/route add default gw ${GATEWAY} netmask 0.0.0.0 metric 1
  fi
fi

# End of rc.inet1






More information about the NCLUG mailing list