[e0f737f] | 1 | <sect1 id="ch07-ethnet">
|
---|
[b08f409] | 2 | <title>Creating the /etc/init.d/ethnet script</title>
|
---|
| 3 |
|
---|
| 4 | <para>
|
---|
[137bd50] | 5 | This section only applies if a user is going to configure a network card.
|
---|
| 6 | If not, this section can be skipped.
|
---|
[b08f409] | 7 | </para>
|
---|
| 8 |
|
---|
| 9 | <para>
|
---|
[137bd50] | 10 | A new file <filename>/etc/init.d/ethnet</filename> is created containing the
|
---|
[b08f409] | 11 | following:
|
---|
| 12 | </para>
|
---|
| 13 |
|
---|
[3229c6b] | 14 | <para>
|
---|
| 15 | <screen>
|
---|
[b08f409] | 16 | <userinput>cat > /etc/init.d/ethnet << "EOF"</userinput>
|
---|
| 17 | #!/bin/sh
|
---|
| 18 | # Begin /etc/init.d/ethnet
|
---|
| 19 | #
|
---|
| 20 | # Main script by Gerard Beekmans - gerard@linuxfromscratch.org
|
---|
| 21 | # GATEWAY check by Jean-François Le Ray - jfleray@club-internet.fr
|
---|
[9b3c02c] | 22 | # "Specify which IF to use to reach default GATEWAY" by
|
---|
| 23 | # Graham Cantin - gcantin@pacbell.net
|
---|
[b08f409] | 24 | #
|
---|
| 25 |
|
---|
| 26 | #
|
---|
| 27 | # Include the functions declared in the /etc/init.d/functions file
|
---|
| 28 | # and the variables from the /etc/sysconfig/network file.
|
---|
| 29 | #
|
---|
| 30 |
|
---|
| 31 | source /etc/init.d/functions
|
---|
| 32 | source /etc/sysconfig/network
|
---|
| 33 |
|
---|
| 34 | case "$1" in
|
---|
| 35 | start)
|
---|
| 36 |
|
---|
| 37 | #
|
---|
| 38 | # Obtain all the network card configuration files
|
---|
| 39 | #
|
---|
| 40 |
|
---|
[a9bc54b7] | 41 | for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
|
---|
[b08f409] | 42 | grep -v ifcfg-lo)
|
---|
| 43 | do
|
---|
| 44 | #
|
---|
| 45 | # Load the variables from that file
|
---|
| 46 | #
|
---|
| 47 |
|
---|
| 48 | source $interface
|
---|
| 49 | #
|
---|
| 50 | # If the ONBOOT variable is set to yes, process this file and bring the
|
---|
[015eb7c] | 51 | # interface up.
|
---|
[b08f409] | 52 | #
|
---|
| 53 |
|
---|
| 54 | if [ "$ONBOOT" == yes ]
|
---|
| 55 | then
|
---|
| 56 | echo -n "Bringing up the $DEVICE interface..."
|
---|
| 57 | /sbin/ifconfig $DEVICE $IP broadcast $BROADCAST \
|
---|
| 58 | netmask $NETMASK
|
---|
| 59 | evaluate_retval
|
---|
| 60 | fi
|
---|
| 61 | done
|
---|
| 62 |
|
---|
| 63 | #
|
---|
| 64 | # If the /etc/sysconfig/network file contains a GATEWAY variable, set
|
---|
[9b3c02c] | 65 | # the default gateway and the interface through which the default
|
---|
| 66 | # gateway can be reached.
|
---|
[b08f409] | 67 | #
|
---|
| 68 |
|
---|
| 69 | if [ "$GATEWAY" != "" ]; then
|
---|
[ea7635f] | 70 | echo -n "Setting up routing for $GATEWAY_IF interface..."
|
---|
[9b3c02c] | 71 | /sbin/route add default gateway $GATEWAY \
|
---|
| 72 | metric 1 dev $GATEWAY_IF
|
---|
[b08f409] | 73 | evaluate_retval
|
---|
| 74 | fi
|
---|
| 75 | ;;
|
---|
| 76 |
|
---|
| 77 | stop)
|
---|
| 78 |
|
---|
| 79 | #
|
---|
| 80 | # Obtain all the network card configuration files
|
---|
| 81 | #
|
---|
| 82 |
|
---|
[a9bc54b7] | 83 | for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
|
---|
[b08f409] | 84 | grep -v ifcfg-lo)
|
---|
| 85 | do
|
---|
| 86 | #
|
---|
| 87 | # Load the variables from that file
|
---|
| 88 | #
|
---|
| 89 |
|
---|
| 90 | source $interface
|
---|
| 91 | #
|
---|
| 92 | # If the ONBOOT variable is set, process the file and bring the
|
---|
| 93 | # interface down
|
---|
| 94 | #
|
---|
| 95 |
|
---|
| 96 | if [ $ONBOOT == yes ]
|
---|
| 97 | then
|
---|
| 98 | echo -n "Bringing down the $DEVICE interface..."
|
---|
| 99 | /sbin/ifconfig $DEVICE down
|
---|
| 100 | evaluate_retval
|
---|
| 101 | fi
|
---|
| 102 | done
|
---|
| 103 | ;;
|
---|
| 104 |
|
---|
| 105 | restart)
|
---|
| 106 | $0 stop
|
---|
| 107 | sleep 1
|
---|
| 108 | $0 start
|
---|
| 109 | ;;
|
---|
| 110 | *)
|
---|
| 111 | echo "Usage: $0 {start|stop|restart}"
|
---|
| 112 | exit 1
|
---|
| 113 | ;;
|
---|
| 114 | esac
|
---|
| 115 |
|
---|
| 116 | # End /etc/init.d/ethnet
|
---|
| 117 | <userinput>EOF</userinput>
|
---|
[3229c6b] | 118 | </screen>
|
---|
| 119 | </para>
|
---|
[b08f409] | 120 |
|
---|
| 121 | <sect2>
|
---|
| 122 | <title>Adding default gateway to /etc/sysconfig/network</title>
|
---|
| 123 |
|
---|
| 124 | <para>
|
---|
[137bd50] | 125 | If a default gateway is required to be setup, the following command does that:
|
---|
[b08f409] | 126 | </para>
|
---|
| 127 |
|
---|
[3229c6b] | 128 | <para>
|
---|
| 129 | <screen>
|
---|
[09c2137] | 130 | <userinput>cat >> /etc/sysconfig/network << "EOF"</userinput>
|
---|
[b08f409] | 131 | GATEWAY=192.168.1.2
|
---|
[9b3c02c] | 132 | GATEWAY_IF=eth0
|
---|
[b08f409] | 133 | <userinput>EOF</userinput>
|
---|
[3229c6b] | 134 | </screen>
|
---|
| 135 | </para>
|
---|
[b08f409] | 136 |
|
---|
| 137 | <para>
|
---|
[9b3c02c] | 138 | GATEWAY and GATEWAY_IF need to be changed to match the network setup.
|
---|
| 139 | GATEWAY contains the address of the default gateway, and GATEWAY_IF
|
---|
| 140 | contains the network interface through which that default gateway can
|
---|
| 141 | be reached.
|
---|
[b08f409] | 142 | </para>
|
---|
| 143 |
|
---|
| 144 | </sect2>
|
---|
| 145 |
|
---|
| 146 | <sect2>
|
---|
| 147 | <title>Creating NIC configuration files</title>
|
---|
| 148 |
|
---|
| 149 | <para>
|
---|
| 150 | Which interfaces are brought up and down by the ethnet script depends on
|
---|
[a9bc54b7] | 151 | the files in the /etc/sysconfig/nic-config directory. This
|
---|
[b08f409] | 152 | directory should contain files in the form of ifcfg-x where x is an
|
---|
[137bd50] | 153 | identification number (or whatever a user named it).
|
---|
[b08f409] | 154 | </para>
|
---|
| 155 |
|
---|
| 156 | <para>
|
---|
[a9bc54b7] | 157 | First the nic-config directory is created by running:
|
---|
[b08f409] | 158 | </para>
|
---|
| 159 |
|
---|
[3229c6b] | 160 | <para>
|
---|
| 161 | <screen>
|
---|
| 162 | <userinput>mkdir /etc/sysconfig/nic-config</userinput>
|
---|
| 163 | </screen>
|
---|
| 164 | </para>
|
---|
[b08f409] | 165 |
|
---|
| 166 | <para>
|
---|
[a202fac2] | 167 |
|
---|
[137bd50] | 168 | Now, new files are created in that directory containing the following.
|
---|
| 169 | This creates a sample file ifcfg-eth0:
|
---|
[b08f409] | 170 | </para>
|
---|
| 171 |
|
---|
[3229c6b] | 172 | <para>
|
---|
| 173 | <screen>
|
---|
| 174 | <userinput>cat > /etc/sysconfig/nic-config/ifcfg-eth0 << "EOF"</userinput>
|
---|
[b08f409] | 175 | ONBOOT=yes
|
---|
| 176 | DEVICE=eth0
|
---|
| 177 | IP=192.168.1.1
|
---|
| 178 | NETMASK=255.255.255.0
|
---|
| 179 | BROADCAST=192.168.1.255
|
---|
[a202fac2] | 180 | <userinput>EOF</userinput>
|
---|
[3229c6b] | 181 | </screen>
|
---|
| 182 | </para>
|
---|
[b08f409] | 183 |
|
---|
| 184 | <para>
|
---|
[137bd50] | 185 | Of course, the values of those four variables have to be changed
|
---|
| 186 | in every file to
|
---|
[b08f409] | 187 | match the proper setup. Usually NETMASK and BROADCAST will remain the
|
---|
| 188 | same, just the DEVICE IP variables will change per network interface. If
|
---|
| 189 | the ONBOOT variable is set to yes, the ethnet script will bring it up
|
---|
| 190 | during boot up of the system. If set to anything else but yes it will be
|
---|
| 191 | ignored by the ethnet script and thus not brought up.
|
---|
| 192 | </para>
|
---|
| 193 |
|
---|
| 194 | </sect2>
|
---|
| 195 |
|
---|
| 196 | </sect1>
|
---|
| 197 |
|
---|