ethnet.xml 4.6 KB

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