ethnet.xml 4.6 KB

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