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