ethnet.xml 4.7 KB

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