ethnet.xml 4.3 KB

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