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