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