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