📄 ch43.htm
字号:
#GATEWAY=""
</FONT></PRE>
<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 you will also 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:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">/sbin/ifconfig lo 127.0.0.1
/sbin/route add -net 127.0.0.0
</FONT></PRE>
<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>Below the settings for your machine's IP address, there will probably be a number
of lines that are commented out, 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:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">/etc/ifconfig eth0 ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST}
</FONT></PRE>
<P>If this causes problems later during system startup, you should switch the uncommented
line to the one that reads<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">/etc/ifconfig eth0 ${IPADDR} netmask ${NETMASK}
</FONT></PRE>
<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, there will be a section
of the <TT>rc.inet1</TT> file that 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</TT> file 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:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">if [-f ${NET}/inetd
then
echo -n " inetd"
${NET}/inetd
else
echo "no INETD found. INET cancelled."
exit 1
fi
</FONT></PRE>
<P>If you read Chapter 13, "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 will probably be 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>One other daemon you might want running is <TT>syslogd</TT>. It usually is set
to execute automatically. This is the system logging daemon, which collects log messages
from other applications and stores them in log files. The log file locations, which
you can change as you desire, are given in the file <TT>/etc/syslog.conf</TT>.</P>
<P>That's enough changes to the <TT>rc</TT> files for now. After TCP/IP is installed
and tested, the rest of the daemons (<TT>routed</TT>, <TT>named</TT>, and so on)
can be started one at a time to ensure they work. The first task is to get TCP/IP
communicating with other machines properly. Then you tweak it! /etc/hosts The <TT>/etc/hosts</TT>
file is a simple list of IP addresses and the hostnames to which they correspond.
This is a good location to list all your favorite machines so that you can use the
name and have the system look up the IP address. On very small networks, you can
add all the machines in the network here and avoid the need to run the <TT>named</TT>
daemon.</P>
<P>Every <TT>/etc/hosts</TT> file will have an entry for <TT>localhost</TT> (also
called <TT>loopback</TT>, IP address <TT>127.0.0.1</TT>) and probably one for your
machine, if you named it when you installed the software. If you didn't supply a
name and there is no line other than <TT>localhost</TT>, you can add it now. Use
an editor and set your IP address and machine name. Don't bother adding too many
other machines until you're sure the network works properly! Here's a sample <TT>/etc/hosts</TT>
file:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">127.0.0.1 localhost
147.12.2.42 merlin.tpci merlin
</FONT></PRE>
<P>You will notice that the format is quite simple: an IP address in one column and
the name in another column, separated by tabs. If the machine may have more than
one name, supply them all. In the example, which uses random numbers for the IP address,
the machine <TT>147.12.2.42</TT> has the name <TT>merlin</TT>. Since it is also part
of a larger network called <TT>tpci</TT>, the machine can be addressed as <TT>merlin.tpci</TT>.
Both names on the line ensure that the system can resolve either name to the same
address.</P>
<P>You can expand the file a little if you want by adding other machines on your
local network, or those you will communicate with regularly:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">127.0.0.1 localhost
147.12.2.42 merlin.tpci merlin
147.12.2.43 wizard.tpci wizard
147.12.2.44 arthur.tpci arthur bobs_machine
147.12.2.46 lancelot.tpci lancelot
</FONT></PRE>
<P>In this example, there are several machines from the same network (the same network
address). One has three different names.</P>
<P>If you are only using the loopback driver, the only line that should be in the
file is for the IP address <TT>127.0.0.1</TT> with the name <TT>localhost</TT> and
your machine's name after it. /etc/networks The <TT>/etc/networks</TT> file lists
names and IP addresses of your own network and other networks you connect to frequently.
This file is used by the <TT>route</TT> command, started through the <TT>rc.inet1</TT>
file. One advantage of this file is that it lets you call remote networks by name,
so instead of typing <TT>149.23.24</TT>, you can type <TT>eds_net</TT>.</P>
<P>The <TT>/etc/networks</TT> file should have an entry for every network that will
be used with the <TT>route</TT> command. If there is no entry, errors will be generated,
and the network won't work properly.</P>
<P>A sample <TT>/etc/networks</TT> file using random IP addresses is shown next.
Remember that you need only the network address and not the device portion of a remote
machine's IP address, although you must fill in the rest with zeroes:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">loopback 127.0.0.0
localnet 147.13.2.0
eds_net 197.32.1.0
big_net 12.0.0.0
</FONT></PRE>
<P>At a minimum, you must have a loopback and <TT>localnet</TT> address in the file.
/etc/host.conf The system uses the <TT>host.conf</TT> file to resolve hostnames.
It usually contains two lines that look like this:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">order hosts, bind
multi on
</FONT></PRE>
<P>These tell the system to first check the <TT>/etc/hosts</TT> file, then check
the nameserver (if one exists) when trying to resolve a name. The <TT>multi</TT>
entry lets you have multiple IP addresses for a machine in the <TT>/etc/hosts</TT>
file (which happens with gateways and machines on more than one network).</P>
<P>If your <TT>/etc/host.conf</TT> file looks like these two lines, you don't need
to make any changes at all. resolv.conf The <TT>resolv.conf</TT> file is used by
the name resolver program. It gives the address of your name server (if you have
one) and your domain name (if you have one). You will have a domain name if you are
on the Internet.</P>
<P>A sample <TT>resolv.conf</TT> file for the system <TT>merlin.tpci.com</TT> has
an entry for the domain name, which is <TT>tpci.com</TT> (<TT>merlin</TT> is the
name of an individual machine):<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">domain tpci.com
</FONT></PRE>
<P>If a name server is used on your network, you should add a line that gives its
IP address:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">domain tpci.com
nameserver 182.23.12.4
</FONT></PRE>
<P>If there are multiple name servers, which is not unusual on a larger network,
each name server should be specified on its own line.</P>
<P>If you don't have a domain name for your system, you can safely ignore this file
for now. /etc/protocols UNIX systems use the <TT>/etc/protocols</TT> file to identify
all the transport protocols available on the system and their respective protocol
numbers. (Each protocol supported by TCP/IP has a special number, but that's not
really important at this point.) Usually, this file is not modified but is maintained
by the system and updated automatically as part of the installation procedure when
new software is added.</P>
<P>The <TT>/etc/protocols</TT> file contains the protocol name, its number, and any
alias that may be used for that protocol. A sample <TT>/etc/protocols</TT> file looks
like this:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF"># Internet protocols (IP)
ip 0 IP
icmp 1 ICMP
ggp 3 GGP
tcp 6 TCP
egp 8 EGP
pup 12 PUP
udp 17 UDP
hello 63 HELLO
</FONT></PRE>
<P>If your entries don't match this, don't worry. You shouldn't have to make any
changes to this file at all, but you should know what it does. /etc/services The
<TT>/etc/services</TT> file identifies the existing network services. This file is
maintained by software as it is installed or configured.</P>
<P>This file consists of the service name, a port number, and the protocol type.
The port number and protocol type are separated by a slash, following the conventions
mentioned in previous chapters. Any optional service alias names follow. Here's a
short extract from a sample <TT>/etc/services</TT> file:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF"># network services
echo 7/tcp
echo 7/udp
discard 9/tcp sink null
discard 9/udp sink null
ftp 21/tcp
telnet 23/tcp
smtp 25/tcp mail mailx
tftp 69/udp
# specific services
login 513/tcp
who 513/udp whod
</FONT></PRE>
<P>You shouldn't change this file at all, but you do need to know what it is and
why it is there to help you understand TCP/IP a little better. /etc/hostname or /etc/HOSTNAME
The file <TT>/etc/hostname</TT> or <TT>/etc/HOSTNAME</TT> is used to store the name
of the system you are on. (Slackware Linux uses the uppercase version of the name.)
This file should have your local machine's name in it:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">merlin.tpci
</FONT></PRE>
<P>That's all it needs. The host name is used by most protocols on the system and
many applications, so it is important for proper system operation. The host name
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -