📄 653-656.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:Networking</TITLE>
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0672313723//-->
<!--TITLE=Linux Unleashed, Third Edition//-->
<!--AUTHOR=Tim Parker//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=37//-->
<!--PAGES=653-656//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="651-653.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="656-658.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>rc Files</B></FONT></P>
<P>Linux reads the <TT>rc</TT> (run command) files when the system boots. The <TT>init</TT> program initiates the reading of these files, and they usually serve to start processes such as <TT>mail</TT>, <TT>printers</TT>, <TT>cron</TT>, and so on. They are also used to initiate TCP/IP connections. Most Linux systems have the <TT>rc</TT> command files in the directory <TT>/etc/rc.d</TT>.</P>
<P>The two files of interest to TCP/IP are <TT>rc.inet1</TT>, which sets the network parameters, and <TT>rc.inet2</TT>, which starts the daemons used by TCP/IP. On some systems, these two files are combined into one larger file called either <TT>rc.inet</TT> or <TT>rc.net</TT>.</P>
<P>To configure the <TT>rc.inet</TT> files to start up the TCP/IP network, you must first make sure that the files are actually read by the <TT>init</TT> program. This is handled by the <TT>/etc/inittab</TT> and <TT>/etc/rc.d/rc.M</TT> files, where there are one or more lines that control the reading of the <TT>rc.inet</TT> files.</P>
<P>Some Linux versions use only the <TT>/etc/inittab</TT> file to start the TCP/IP daemons. The Slackware version, though, has a line in the <TT>/etc/inittab</TT> file that tells the <TT>init</TT> program to read the file <TT>/etc/rc.d/rc.M</TT> when running multiuser mode. The TCP/IP daemons are not started when the system is in single-user mode.</P>
<P>Whichever file is involved, look for a line that refers to the <TT>rc.inet1</TT>, <TT>rc.inet</TT>, or <TT>rc.net</TT> file. In some cases, this line(s) is commented out (it has a pound sign as the first character) to prevent the system from trying to run TCP/IP when there is no requirement for it. If the line is commented out, remove the comment symbol. The Slackware release of Linux, for example, has an <TT>if</TT> loop within the <TT>rc.M</TT> file that has these lines in it:</P>
<!-- CODE SNIP //-->
<PRE>
/bin/hostname ‘cat /etc/HOSTNAME | cut -f1 -d .‘
/bin/sh /etc/rc.d/rc.inet1
/bin/sh /etc/rc.d/rc.inet1
</PRE>
<!-- END CODE SNIP //-->
<P>Make sure that these lines (as well as the <TT>if</TT> loop that the lines are part of) are not commented out. You want these lines to execute each time the <TT>if</TT> condition is true. With the Slackware version, the <TT>if</TT> condition checks for the existence of the file <TT>rc.inet1</TT>.</P>
<P>If you can’t find a reference to the <TT>rc.inet</TT> files in <TT>/etc/inittab</TT>, or a pointer to another file that has these files referenced (as with Slackware’s <TT>/etc/rc.d/rc.M</TT>), you will have to add the lines to the <TT>/etc/inittab</TT> file manually. This can be scary for newcomers to Linux, so make copies of the files so you can always recover. An emergency boot floppy is also always handy to have.</P>
<P>Usually there is a good set of comments within the startup files to help you configure the system. There is a section for TCP/IP Ethernet support that often has a number of lines commented out. It consists of lines like this:</P>
<!-- CODE SNIP //-->
<PRE>
#IPADDR=”127.0.0.1”
#NETMASK=””
#NETWORK=”127.0.0”
#BROADCAST=””
#GATEWAY=””
</PRE>
<!-- END CODE SNIP //-->
<P>Obviously, these correspond to the pieces of information you determined earlier. Therefore, uncomment the lines and type in the information about your machine. If you don’t have one of the pieces, such as a gateway address, leave that line commented out.
</P>
<P>In the <TT>rc.inet1</TT> file, please note several references to the programs <TT>ifconfig</TT> and <TT>route</TT>. These programs control TCP/IP communications. <TT>ifconfig</TT> configures network device interfaces, and <TT>route</TT> configures the routing table.</P>
<P>Near the top of the <TT>rc.inet1</TT> file (or whichever file is used in your version of Linux) are a couple of lines that call both <TT>ifconfig</TT> and <TT>route</TT> for the loopback driver. The lines probably look like this:</P>
<!-- CODE SNIP //-->
<PRE>
/sbin/ifconfig lo 127.0.0.1
/sbin/route add -net 127.0.0.0
</PRE>
<!-- END CODE SNIP //-->
<P>Neither of these lines should be commented out. They are necessary to set the loopback driver, which must exist on the system in order for TCP/IP to function properly.
</P>
<P>There will probably be a number of lines that are commented out below the settings for your machine’s IP address with instructions to uncomment one of them. The differences between the lines is whether broadcast and netmask variables are included. To begin, try uncommenting the line that looks like this:</P>
<!-- CODE SNIP //-->
<PRE>
/etc/ifconfig eth0 ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST}
</PRE>
<!-- END CODE SNIP //-->
<P>If this causes problems later during system startup, switch the uncommented line to the one that reads
</P>
<!-- CODE SNIP //-->
<PRE>
/etc/ifconfig eth0 ${IPADDR} netmask ${NETMASK}
</PRE>
<!-- END CODE SNIP //-->
<P><TT>eth0</TT> is the first device for the first Ethernet card on your system, called <TT>eth0</TT>.</P>
<P>Finally, if you have a gateway machine on your network, a section of the <TT>rc.inet1</TT> file lets you enter the IP address of the gateway. Again, these lines should be uncommented. You might want to try to get the system working properly before you set up the gateway because it is easier to debug when the number of potential problems is smaller.</P>
<P>The <TT>rc.inet2 file</TT> starts up the daemons used by TCP/IP. In most cases, you won’t have to make changes to this file because the most important daemons are usually started anyway. Look for a line that calls the <TT>inetd</TT> program, which is the most important TCP/IP daemon of all. There should be no comments on the line that starts it. It will probably look like this:</P>
<!-- CODE SNIP //-->
<PRE>
if [-f ${NET}/inetd
then
echo -n “ inetd”
${NET}/inetd
else
echo “no INETD found. INET cancelled.”
exit 1
fi
</PRE>
<!-- END CODE SNIP //-->
<P>If you read Chapter 14, “Shell Programming,” or you know a little about programming in some other language, this short section might make sense. This routine checks for the existence of the <TT>inetd</TT> file and starts it if it’s there. If it’s not there, an error message is generated on the display (remember this is during the boot process), and the <TT>rc.inet2</TT> file is exited.</P>
<P>More commented-out daemons are probably listed below <TT>inetd</TT>, such as <TT>named</TT> (the name server daemon that converts proper names to IP address), <TT>routed</TT> (used for routing), and several others. Unless you know that you want one of these daemons active, leave them commented out for now.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="651-653.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="656-658.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -