Creating the /etc/init.d/ethnet script
This section only applies if you are going to configure a network card.
If you're not, skip this section.
Create a new file /etc/init.d/ethnet containing the
following:
cat > /etc/init.d/ethnet << "EOF"
#!/bin/sh
# Begin /etc/init.d/ethnet
#
# Main script by Gerard Beekmans - gerard@linuxfromscratch.org
# GATEWAY check by Jean-François Le Ray - jfleray@club-internet.fr
#
#
# Include the functions declared in the /etc/init.d/functions file
# and the variables from the /etc/sysconfig/network file.
#
source /etc/init.d/functions
source /etc/sysconfig/network
case "$1" in
start)
#
# Obtain all the network card configuration files
#
for interface in $(ls /etc/sysconfig/network-scripts/ifcfg* | \
grep -v ifcfg-lo)
do
#
# Load the variables from that file
#
source $interface
#
# If the ONBOOT variable is set to yes, process this file and bring the
# interface down.
#
if [ "$ONBOOT" == yes ]
then
echo -n "Bringing up the $DEVICE interface..."
/sbin/ifconfig $DEVICE $IP broadcast $BROADCAST \
netmask $NETMASK
evaluate_retval
fi
done
#
# If the /etc/sysconfig/network file contains a GATEWAY variable, set
# the gateway.
#
if [ "$GATEWAY" != "" ]; then
echo -n "Setting up routing for eth0 interface..."
/sbin/route add default gw $GATEWAY metric 1
evaluate_retval
fi
;;
stop)
#
# Obtain all the network card configuration files
#
for interface in $(ls /etc/sysconfig/network-scripts/ifcfg* | \
grep -v ifcfg-lo)
do
#
# Load the variables from that file
#
source $interface
#
# If the ONBOOT variable is set, process the file and bring the
# interface down
#
if [ $ONBOOT == yes ]
then
echo -n "Bringing down the $DEVICE interface..."
/sbin/ifconfig $DEVICE down
evaluate_retval
fi
done
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
# End /etc/init.d/ethnet
EOF
Adding default gateway to /etc/sysconfig/network
If you require a default gateway to be setup, run the following command:
cat >> /etc/sysconfig/network << "EOF"
GATEWAY=192.168.1.2
EOF
Change GATEWAY to match your network setup.
Creating NIC configuration files
Which interfaces are brought up and down by the ethnet script depends on
the files in the /etc/sysconfig/network-scripts directory. This
directory should contain files in the form of ifcfg-x where x is an
identification number (or whatever you choose to name it).
First create the network-scripts directory by running:
mkdir /etc/sysconfig/network-scripts
Now, create new files in that directory containing the following.
The following creates a sample file ifcfg-eth0:
cat > /etc/sysconfig/network-scripts/ifcfg-eth0
<< EOF
ONBOOT=yes
DEVICE=eth0
IP=192.168.1.1
NETMASK=255.255.255.0
BROADCAST=192.168.1.255
EOF
Of course, change the values of those four variables in every file to
match the proper setup. Usually NETMASK and BROADCAST will remain the
same, just the DEVICE IP variables will change per network interface. If
the ONBOOT variable is set to yes, the ethnet script will bring it up
during boot up of the system. If set to anything else but yes it will be
ignored by the ethnet script and thus not brought up.
&c9-ethnet-symperm;