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