📄 0254-0256.html
字号:
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:TCP/IP Network Management</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311739 //-->
<!-- TITLE=RED HAT LINUX 2ND EDITION //-->
<!-- AUTHOR=DAVID PITTS ET AL //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS PUBLISHING //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=13 //-->
<!-- PAGES=0243-0298 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0250-0253.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0257-0259.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-254"><P>Page 254</P></A>
<H4><A NAME="ch13_ 11">
Using ifconfig
</A></H4>
<P>ifconfig is the tool used to set up and configure your network card. If you used the Red
Hat installation package, you might already have this configured for you. You should,
however, understand this command in the event you need to configure the network by hand after a
system crash.
</P>
<P>The purpose of ifconfig is to set up and configure the network interfaces. Typically, this
is done early in the boot sequence so that any other network services that need to be started
know how to communicate with the rest of the world.
</P>
<P>The format of the ifconfig command is as follows:
</P>
<!-- CODE SNIP //-->
<PRE>
ifconfig interface IP_address options
</PRE>
<!-- END CODE SNIP //-->
<CENTER>
<TABLE BGCOLOR="#FFFF99">
<TR><TD><B>
NOTE
</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
The ifconfig command takes parameters in a slightly different way than most
commands. Each parameter should not be prefixed by a minus sign
(-) unless you are turning that function off. If you are setting a parameter, such as the netmask, simply use
netmask followed by the netmask you want to set—for example,
netmask 255.255.255.0.
</BLOCKQUOTE></TD></TR>
</TABLE></CENTER>
</P>
<P>interface is the network device that you want to set up. If you are using Ethernet, this will
be eth followed by a number designating which Ethernet card you are using. The numbering
starts from zero (the first Ethernet card in your system will be
eth0). IP_address is the address that you want to assign to your machine. Use dotted notation and remember not to assign it
the network address or broadcast address.
</P>
<P>These are the only required options for configuring a network device.
ifconfig will use the default netmask and broadcast address based on the class of your
IP_address setting. The default netmask and broadcast addresses, however, will only be correct if you are subnetting
along an 8-bit boundary.
</P>
<P>To set the netmask and broadcast address, use the parameters
netmask and broadcast, respectively, followed by the address you want to set for them.
</P>
<P>Here is a sample ifconfig:
</P>
<!-- CODE SNIP //-->
<PRE>
ifconfig eth0 192.168.42.2 netmask 255.255.255.0 broadcast 192.168.42.255
</PRE>
<!-- END CODE SNIP //-->
<P>As with most other UNIX commands, there is no output if it is successful. To see what
the currently configured cards are, simply run
ifconfig without any parameters:
</P>
<!-- CODE SNIP //-->
<PRE>
[root@vestax /root]# ifconfig
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-255"><P>Page 255</P></A>
<!-- CODE //-->
<PRE>
lo Link encap:Local Loopback
inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0
UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1
RX packets:10984 errors:0 dropped:0 overruns:0
TX packets:10984 errors:0 dropped:0 overruns:0
eth0 Link encap:10Mbps Ethernet HWaddr 00:60:97:C3:D0:C9
inet addr:192.168.42.2 Bcast:192.168.42.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1995581 errors:1 dropped:1 overruns:0
TX packets:1361726 errors:0 dropped:0 overruns:0
Interrupt:11 Base address:0x6100
</PRE>
<!-- END CODE //-->
<P>The first network card listed here is the lo device, which is the loopback device. I'm not
terribly interested in that entry, although it should be there. The second entry shows how the
eth0 network card is currently configured. The Link
encap tells you that it is configured as a 10Mbps Ethernet card. The
HWaddr tells you the hardware address of that particular Ethernet card
(also known as the MAC address). On the second line of the output is the
inet addr. This is the address you have configured the card to answer to. On the same line are the respective
broadcast and netmask addresses. The third line of the output shows which options have been
enabled on the card from the ifconfig command. You should recognize the
BROADCAST option because you explicitly set it. The others are default options that are covered shortly. The
fourth line contains information regarding the number of packets that have been received. In
this example, about 1.9 million packets have been received, 1 packet had an error, 1 packet
was dropped, and no packets were overruns. (Overruns are packets that are too long.) In the
line below it is the same information for packets transmitted. The last line provides the
configuration information for the hardware.
</P>
<H4><A NAME="ch13_ 12">
Optional Parameters to ifconfig
</A></H4>
<P>The following parameters are optional on the
ifconfig command line:</P>
<TABLE WIDTH="360">
<TR><TD>
up
</TD><TD>
This tells ifconfig to activate the network interface and begin
sending and receiving packets.
</TD></TR>
<TR><TD>
down
</TD><TD>
This option enables you to shut the interface down after it has
been activated. This is useful for shutting down an active card when
troubleshooting network-related problems.
</TD></TR>
<TR><TD>
arp
</TD><TD>
ARP (Address Resolution Protocol) enables you to map a
network card's hardware address to its IP address. Protocols such as DHCP
use this to find machines on a subnet without having to know an
IP address first. Note that the ARP will work only within your
immediate subnet and will not transfer through routers. By default, this option
is turned on. To turn it off, place a minus sign in front of it
(-arp).
</TD></TR>
<TR><TD>
mtu N
</TD><TD>
The MTU (Maximum Transfer Unit) sets the size of each
Ethernet packet to N, where N is the number of bytes in each packet.
For Ethernet, this defaults to 1500, and you shouldn't change it unless
you are sure about what you are doing.
</TD></TR>
</TABLE>
<A NAME="PAGENUM-256"><P>Page 256</P></A>
<H4><A NAME="ch13_ 13">
Using route
</A></H4>
<P>In order to communicate with machines outside your local area network, you need to use
a router. This device is the link between your network and the rest of the world. When you
need to communicate to a machine outside of your LAN, your host will send the message to
the router, which will forward it on through the outside network. The same is true for
packets coming in from the outside network. The router will receive the packet and forward it to
your host.
</P>
<P>If you used the Red Hat installation procedure for configuring your network, this has
already been configured for you. For a host connected to the Internet, you should have at the very
least three possible routes: a loopback, a route to your LAN, and a default route to your router.
By running route without any parameters, you can see your current routing table. The format
of the route command is
</P>
<!-- CODE SNIP //-->
<PRE>
route cmd type target_ip netmask gateway options
</PRE>
<!-- END CODE SNIP //-->
<P>where cmd is either add or del depending on whether you want to add or delete a route,
respectively. If you use del, you then only need the
target_ip parameter, which specifies the IP address for which you are routing.
</P>
<P>If, on the other hand, you used the add command, you need to specify
type to be either -net or -host, where -net is a network that you are routing to and
-host is a specific host you are routing to.
</P>
<P>The target_ip address specifies either the network or host IP address to which you are
routing. There is a special keyword for this option:
default. If you specify default instead of an
actual IP address, all packets that do not have a specific route listed in the route table will be sent
to this route.
</P>
<P>netmask allows you to specify the netmask to the network you are routing to. Note
that this applies only when using the -net option. The
netmask option is used like this: netmask
mask_number where mask_number is the actual netmask in dotted notation.
</P>
<P>gateway specifies which gateway to use for sending packets to
target_ip. For example, if your default route points to the Internet (a likely situation), then your gateway setting should
point to your router connecting to the Internet. For example, if the router were
192.168.42.1, this option would be specified as gw
192.168.42.1. You can use hostnames if you want to, so
long as they appear in the /etc/hosts file. (See the section "The Domain Name Service," later
in this chapter, for details.)
</P>
<P>The options available in addition to the ones already stated are as follows:</P>
<TABLE WIDTH="360">
<TR><TD>
-n
</TD><TD>
</TD><TD>
Uses numerical addresses instead of trying to resolve IP addresses
to hostnames. This is used when invoking route without either the
add or del parameter so you can see which routes are currently set.
</TD></TR>
</TABLE>
<P><CENTER>
<a href="0250-0253.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0257-0259.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -