ethnet.xml 4.6 KB

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