📄 ch43.htm
字号:
with the service you are planning to use. For example, to use SLIP (Serial Line Interface
Protocol), you generally need a modem supporting at least V.32bis speeds (14.4kbps).
<H3 ALIGN="CENTER"><A NAME="Heading5<FONT COLOR="#000077">Configuring Linux
Files</FONT></H3>
<P>Let's assume you have a typical PC and an Ethernet card, and you want to set up
your machine to run TCP/IP over the network. In most cases, the procedure described
next will work. However, because there are many versions of Linux, many potential
conflicts with other cards and software, and unique software requirements for some
systems, this should be considered only a guide.</P>
<P>If, after following these instructions, your TCP/IP network doesn't work properly,
it's time to carefully scan all the configuration files and error messages for a
clue to the problem. Also, don't forget about the Linux Usenet newsgroups, Linux
User Groups, and other sources of information about Linux from which you can get
help.</P>
<P>To configure the TCP/IP files, you must have installed the networking software
on your system. If you haven't installed the networking portions of the distribution,
you must do so before proceeding. Your kernel must also have been configured and
recompiled with network support added. This is usually done during the installation
process, although some users will have to force the kernel recompilation manually
if they installed their software in a nonstandard manner.</P>
<P>First we'll deal with the use of a network card, and then look at how to change
the basic process to handle SLIP over a serial port and modem.
<H4 ALIGN="CENTER"><A NAME="Heading6<FONT COLOR="#000077">What You Need Before
You Start</FONT></H4>
<P>Before you start modifying system files, you should take a few minutes to determine
a few basic pieces of information you'll need. It is advisable to write these down
somewhere so that they will be handy when you need them, and also so that you won't
enter two different values in two files, thereby causing major problems for the system.
IP Address First you need an IP address, a unique number for your machine. Every
machine on the network has to be identified uniquely to allow proper routing. TCP/IP-based
networks use 32-bit addresses to uniquely identify networks and all the devices that
reside within that network. These addresses are called Internet addresses or IP addresses.</P>
<P>The 32 bits of the IP address are broken into four 8-bit parts. Each 8-bit part
can then have valid numbers ranging from 0 to 255. In IP addresses, the four 8-bit
numbers are separated by a period, a notation called dotted quad. Examples of dotted
quad IP addresses are <TT>255.255.255.255</TT> and <TT>147.14.123.8</TT>.</P>
<P>For convenience, IP addresses are divided into two parts: the network number and
the device number within that network. This separation into two components allows
devices on different networks to have the same host number. However, since the network
number is different, the devices are still uniquely identified.</P>
<P>For connection to the Internet, IP addresses are assigned by the Internet Network
Information Center (NIC) based on the size of the network. Anyone who wants to connect
to the Internet must register with the NIC to avoid duplication of network addresses.
If you don't plan to connect to the Internet, you are free to create your own numbering
scheme, although future expansion and integration with Internet-using networks can
cause serious problems.</P>
<P>For maximum flexibility, IP addresses are assigned according to network size.
Networks are divided into three categories: Class A, Class B, and Class C. The three
network classes break the 32-bit IP addresses into different sizes for the network
and host identifiers.</P>
<P>A Class A address uses one byte for the network address and three bytes for the
device address, allowing more than 16 million different host addresses. Class B networks
use two bytes for the network and two bytes for the host. Since 16 bits allow more
than 65,000 hosts, only a few large companies will be limited by this type of class.
Class C addresses have three bytes for the network and one for the number of hosts.
This provides for a maximum of 254 hosts (the numbers 0 and 255 are reserved) but
many different network IDs. The majority of networks are Class B and Class C.</P>
<P>You do have a limitation as to the first value. A Class A network's first number
must be between 0 and 127, Class B addresses are between 128 and 191, and Class C
addresses are between 192 and 223. This is because of the way the first byte is broken
up, with a few of the bits at the front saved to identify the class of the network.
Also, you can't use the values 0 and 255 for any part, because they are reserved
for special purposes.</P>
<P>Messages sent using TCP/IP use the IP address to identify sending and receiving
devices, as well as any routing information put within the message headers. If you
are going to connect to an existing network, you should find out what their IP addresses
are and what numbers you can use. If you are setting up a network for your own use
but plan to connect to the Internet at some point, you should contact the Network
Information Center for an IP Address. On the other hand, if you are setting up a
network for your own use and don't plan to have more than a telephone connection
to other networks (including the Internet), you can make up your own IP addresses.</P>
<P>If you are only setting up a loopback driver, you don't even need an IP address.
The default value for a loopback driver is <TT>127.0.0.1</TT>. Network Mask Next,
you need a network mask. This is pretty easy if you have picked out an IP address.
The network mask is the network portion of the IP address set to the value 255, and
it's used to blank out the network portion to determine routing.</P>
<P>If you have a Class C IP address (three bytes for network and one for devices),
your network mask is <TT>255.255.255.0</TT>. A Class B network has a network mask
of <TT>255.255.0.0</TT>, and a Class A network mask is <TT>255.0.0.0</TT>.</P>
<P>If you are configuring only a loopback driver, your network mask is <TT>255.0.0.0</TT>
(Class A). Network Address The network address is, strictly speaking, the IP address
bitwise-<TT>AND</TT>ed to the netmask. In English, what this means is that it's the
network portion of your IP address, so if your IP address is <TT>147.120.46.7</TT>
and it's a Class B network, the network address is <TT>147.120.0.0</TT>.</P>
<P>To get your own network address, just drop the device-specific part of the IP
address and set it to zero. A Class C network with an IP address of <TT>201.12.5.23</TT>
has a network address of <TT>201.12.5.0</TT>.</P>
<P>If you're only working with a loopback address, you don't need a network mask.
Broadcast Address The broadcast address is used when a machine wants to send the
same packet to all devices on the network. To get your broadcast address, you set
the device portion of the IP address to <TT>255</TT>. Therefore, if you have the
IP address <TT>129.23.123.2</TT>, your broadcast address will be <TT>129.23.123.255</TT>.
Your network address will be <TT>129.23.123.0</TT>.</P>
<P>If you are configuring only a loopback driver, you needn't worry about the broadcast
address. Gateway Address The gateway address is the IP address of the machine that
is the network's gateway out to other networks (such as the Internet). You need a
gateway address only if you have a network that has a dedicated gateway out. If you
are configuring a small network for your own use and don't have a dedicated Internet
connection, you don't need a gateway address.</P>
<P>Normally, gateways have the same IP address as your machines, but they have the
digit <TT>1</TT> as the device number. For example, if your IP address is <TT>129.23.123.36</TT>,
chances are that the gateway address is <TT>129.23.123.1</TT>. This convention has
been used since the early days of TCP/IP.</P>
<P>Loopback drivers do not require a gateway address, so if you are configuring your
system only for loopback, ignore this address. Name Server Address Many larger networks
have a machine whose purpose is to translate IP addresses into English-like names,
and vice versa. It is a lot easier to call a machine <TT>bobs_pc</TT> instead of
<TT>123.23.124.23</TT>. This translation is done with a system called the Domain
Name System (DNS). If your network has a name server, that's the address you need.
If you want to have your own machine act as a name server (which requires some extra
configuration not mentioned here), use the loopback address <TT>127.0.0.1</TT>.</P>
<P>Loopback drivers don't need a name server since the machine only talks to itself.
Therefore, you can ignore the nameserver address if you are only configuring a loopback
driver.
<H4 ALIGN="CENTER"><A NAME="Heading7<FONT COLOR="#000077">Setting Up the Dummy
Interface</FONT></H4>
<P>What's a dummy interface? It's a bit of a trick to give your machine an IP address
to work with when it uses only SLIP and PPP interfaces. A dummy interface solves
the problem of a standalone machine (no network cards connecting it to other machines)
whose only valid IP address to send data to is the loopback driver (<TT>127.0.0.1</TT>).
While SLIP and PPP may be used for connecting your machine to the outside world,
when the interface is not active, you have no internal IP address that applications
can use.</P>
<P>The problem arises with some applications that require a valid IP address to work.
Some word processors and desktop layout tools, for example, require the TCP/IP system
to be operational with an IP address for the target machine. The dummy interface
essentially sets an IP address for your local machine that is valid as far as TCP/IP
is concerned, but doesn't really get used except to fool applications.</P>
<P>Creating a dummy interface is very simple. If your machine has an IP address already
assigned for it in the <TT>/etc/hosts</TT> file, all you need to do is set up the
interface and create a route. The two required commands are<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">ifconfig dummy machine_name
route add machine_name
</FONT></PRE>
<P>where machine_name is your local machine's name (such as <TT>darkstar</TT>). This
creates a link to your own IP address. If you do not have an IP address for your
machine in the <TT>/etc/hosts</TT> file, you should add one before you create the
dummy interface.
<H4 ALIGN="CENTER"><A NAME="Heading8<FONT COLOR="#000077">Configuration Files</FONT></H4>
<P>Configuring Linux for TCP/IP is not difficult, because only a few configuration
files need to have the information about IP address and such added to them. You can
do this with any editor, as long as it saves the files in ASCII format. It is advisable
to make copies of the configuration files before you modify them, just in case you
damage the format in some way.</P>
<P>Many of these files are similar in every version of UNIX, including most versions
of Linux, except for one or two slight naming variations. If you've ever set up a
UNIX system (or snooped around one in detail), these files and steps might seem familiar.
If you haven't done anything with Linux or UNIX before, just take it one step at
a time and follow the instructions! rc Files 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 or lines will
be commented out (have 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 lines are 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:<FONT
COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">/bin/hostname `cat /etc/HOSTNAME | cut -f1 -d .`
/bin/sh /etc/rc.d/rc.inet1
/bin/sh /etc/rc.d/rc.inet1
</FONT></PRE>
<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:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">#IPADDR="127.0.0.1"
#NETMASK=""
#NETWORK="127.0.0"
#BROADCAST=""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -