2001-06-30 00:30:11 +01:00
|
|
|
|
<sect1 id="ch07-ethnet">
|
2001-02-15 15:26:52 +00:00
|
|
|
|
<title>Creating the /etc/init.d/ethnet script</title>
|
|
|
|
|
|
|
|
|
|
<para>
|
2001-03-18 20:39:49 +00:00
|
|
|
|
This section only applies if a user is going to configure a network card.
|
|
|
|
|
If not, this section can be skipped.
|
2001-02-15 15:26:52 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
<para>
|
2001-07-16 18:17:16 +01:00
|
|
|
|
Create the <filename>/etc/init.d/ethnet</filename> script by running the
|
|
|
|
|
following command:
|
2001-02-15 15:26:52 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
2001-07-10 16:06:31 +01:00
|
|
|
|
<para>
|
|
|
|
|
<screen>
|
2001-02-15 15:26:52 +00:00
|
|
|
|
<userinput>cat > /etc/init.d/ethnet << "EOF"</userinput>
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
# Begin /etc/init.d/ethnet
|
|
|
|
|
#
|
|
|
|
|
# Main script by Gerard Beekmans - gerard@linuxfromscratch.org
|
|
|
|
|
# GATEWAY check by Jean-Fran<61>ois Le Ray - jfleray@club-internet.fr
|
2001-04-29 20:49:07 +01:00
|
|
|
|
# "Specify which IF to use to reach default GATEWAY" by
|
|
|
|
|
# Graham Cantin - gcantin@pacbell.net
|
2001-02-15 15:26:52 +00:00
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# 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
|
|
|
|
|
#
|
|
|
|
|
|
2001-06-21 20:06:57 +01:00
|
|
|
|
for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
|
2001-02-15 15:26:52 +00:00
|
|
|
|
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
|
2001-03-13 00:34:36 +00:00
|
|
|
|
# interface up.
|
2001-02-15 15:26:52 +00:00
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
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
|
2001-04-29 20:49:07 +01:00
|
|
|
|
# the default gateway and the interface through which the default
|
|
|
|
|
# gateway can be reached.
|
2001-02-15 15:26:52 +00:00
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if [ "$GATEWAY" != "" ]; then
|
2001-05-24 20:04:03 +01:00
|
|
|
|
echo -n "Setting up routing for $GATEWAY_IF interface..."
|
2001-04-29 20:49:07 +01:00
|
|
|
|
/sbin/route add default gateway $GATEWAY \
|
|
|
|
|
metric 1 dev $GATEWAY_IF
|
2001-02-15 15:26:52 +00:00
|
|
|
|
evaluate_retval
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
stop)
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Obtain all the network card configuration files
|
|
|
|
|
#
|
|
|
|
|
|
2001-06-21 20:06:57 +01:00
|
|
|
|
for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
|
2001-02-15 15:26:52 +00:00
|
|
|
|
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
|
|
|
|
|
<userinput>EOF</userinput>
|
2001-07-10 16:06:31 +01:00
|
|
|
|
</screen>
|
|
|
|
|
</para>
|
2001-02-15 15:26:52 +00:00
|
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
|
<title>Adding default gateway to /etc/sysconfig/network</title>
|
|
|
|
|
|
|
|
|
|
<para>
|
2001-03-18 20:39:49 +00:00
|
|
|
|
If a default gateway is required to be setup, the following command does that:
|
2001-02-15 15:26:52 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
2001-07-10 16:06:31 +01:00
|
|
|
|
<para>
|
|
|
|
|
<screen>
|
2001-02-23 19:04:46 +00:00
|
|
|
|
<userinput>cat >> /etc/sysconfig/network << "EOF"</userinput>
|
2001-02-15 15:26:52 +00:00
|
|
|
|
GATEWAY=192.168.1.2
|
2001-04-29 20:49:07 +01:00
|
|
|
|
GATEWAY_IF=eth0
|
2001-02-15 15:26:52 +00:00
|
|
|
|
<userinput>EOF</userinput>
|
2001-07-10 16:06:31 +01:00
|
|
|
|
</screen>
|
|
|
|
|
</para>
|
2001-02-15 15:26:52 +00:00
|
|
|
|
|
|
|
|
|
<para>
|
2001-04-29 20:49:07 +01:00
|
|
|
|
GATEWAY and GATEWAY_IF need to be changed to match the network setup.
|
|
|
|
|
GATEWAY contains the address of the default gateway, and GATEWAY_IF
|
|
|
|
|
contains the network interface through which that default gateway can
|
|
|
|
|
be reached.
|
2001-02-15 15:26:52 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
|
<title>Creating NIC configuration files</title>
|
|
|
|
|
|
|
|
|
|
<para>
|
|
|
|
|
Which interfaces are brought up and down by the ethnet script depends on
|
2001-06-21 20:06:57 +01:00
|
|
|
|
the files in the /etc/sysconfig/nic-config directory. This
|
2001-02-15 15:26:52 +00:00
|
|
|
|
directory should contain files in the form of ifcfg-x where x is an
|
2001-03-18 20:39:49 +00:00
|
|
|
|
identification number (or whatever a user named it).
|
2001-02-15 15:26:52 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
<para>
|
2001-06-21 20:06:57 +01:00
|
|
|
|
First the nic-config directory is created by running:
|
2001-02-15 15:26:52 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
2001-07-10 16:06:31 +01:00
|
|
|
|
<para>
|
|
|
|
|
<screen>
|
|
|
|
|
<userinput>mkdir /etc/sysconfig/nic-config</userinput>
|
|
|
|
|
</screen>
|
|
|
|
|
</para>
|
2001-02-15 15:26:52 +00:00
|
|
|
|
|
|
|
|
|
<para>
|
2001-02-28 01:35:31 +00:00
|
|
|
|
|
2001-03-18 20:39:49 +00:00
|
|
|
|
Now, new files are created in that directory containing the following.
|
2001-07-16 18:17:16 +01:00
|
|
|
|
The following command creates a sample file ifcfg-eth0:
|
2001-02-15 15:26:52 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
2001-07-10 16:06:31 +01:00
|
|
|
|
<para>
|
|
|
|
|
<screen>
|
|
|
|
|
<userinput>cat > /etc/sysconfig/nic-config/ifcfg-eth0 << "EOF"</userinput>
|
2001-02-15 15:26:52 +00:00
|
|
|
|
ONBOOT=yes
|
|
|
|
|
DEVICE=eth0
|
|
|
|
|
IP=192.168.1.1
|
|
|
|
|
NETMASK=255.255.255.0
|
|
|
|
|
BROADCAST=192.168.1.255
|
2001-02-28 01:35:31 +00:00
|
|
|
|
<userinput>EOF</userinput>
|
2001-07-10 16:06:31 +01:00
|
|
|
|
</screen>
|
|
|
|
|
</para>
|
2001-02-15 15:26:52 +00:00
|
|
|
|
|
|
|
|
|
<para>
|
2001-03-18 20:39:49 +00:00
|
|
|
|
Of course, the values of those four variables have to be changed
|
|
|
|
|
in every file to
|
2001-02-15 15:26:52 +00:00
|
|
|
|
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.
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
|
|
</sect1>
|
|
|
|
|
|