| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 | 
							- <sect1 id="ch09-ethnet">
 
- <title>Creating the /etc/init.d/ethnet script</title>
 
- <para>
 
- This section only applies if a user is going to configure a network card.
 
- If not, this section can be skipped.
 
- </para>
 
- <para>
 
- A new file <filename>/etc/init.d/ethnet</filename> is created containing the
 
- following:
 
- </para>
 
- <literallayout>
 
- <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çois Le Ray - jfleray@club-internet.fr
 
- # "Specify which IF to use to reach default GATEWAY" by 
 
- #     Graham Cantin - gcantin@pacbell.net
 
- #
 
- #
 
- # 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 $(/bin/ls /etc/sysconfig/nic-config/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 up.
 
- #
 
-             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 default gateway and the interface through which the default
 
- # gateway can be reached.
 
- #
 
-             if [ "$GATEWAY" != "" ]; then
 
-                 echo -n "Setting up routing for $GATEWAY_IF interface..."
 
-                 /sbin/route add default gateway $GATEWAY \
 
-                         metric 1 dev $GATEWAY_IF
 
-                 evaluate_retval
 
-             fi
 
-                 ;;
 
-         stop)
 
- #
 
- # Obtain all the network card configuration files
 
- #
 
-         for interface in $(/bin/ls /etc/sysconfig/nic-config/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
 
- <userinput>EOF</userinput>
 
- </literallayout>
 
- <sect2>
 
- <title>Adding default gateway to /etc/sysconfig/network</title>
 
- <para>
 
- If a default gateway is required to be setup, the following command does that:
 
- </para>
 
- <literallayout>
 
- <userinput>cat >> /etc/sysconfig/network << "EOF"</userinput>
 
- GATEWAY=192.168.1.2
 
- GATEWAY_IF=eth0
 
- <userinput>EOF</userinput>
 
- </literallayout>
 
- <para>
 
- 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.
 
- </para>
 
- </sect2>
 
- <sect2>
 
- <title>Creating NIC configuration files</title>
 
- <para>
 
- Which interfaces are brought up and down by the ethnet script depends on
 
- the files in the /etc/sysconfig/nic-config directory. This
 
- directory should contain files in the form of ifcfg-x where x is an
 
- identification number (or whatever a user named it).
 
- </para>
 
- <para>
 
- First the nic-config directory is created by running:
 
- </para>
 
- <blockquote><literallayout>
 
- 	<userinput>mkdir /etc/sysconfig/nic-config</userinput>
 
- </literallayout></blockquote>
 
- <para>
 
- Now, new files are created in that directory containing the following.
 
- This creates a sample file ifcfg-eth0:
 
- </para>
 
- <literallayout>
 
- <userinput>cat > /etc/sysconfig/nic-config/ifcfg-eth0
 
- 	<< EOF</userinput>
 
- ONBOOT=yes
 
- DEVICE=eth0
 
- IP=192.168.1.1
 
- NETMASK=255.255.255.0
 
- BROADCAST=192.168.1.255
 
- <userinput>EOF</userinput>
 
- </literallayout>
 
- <para>
 
- Of course, the values of those four variables have to be changed 
 
- 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.
 
- </para>
 
- </sect2>
 
- &c9-ethnet-symperm;
 
- </sect1>
 
 
  |