388 lines
6.9 KiB
HTML
388 lines
6.9 KiB
HTML
|
<HTML
|
||
|
><HEAD
|
||
|
><TITLE
|
||
|
>Writing hosts and networks Files</TITLE
|
||
|
><META
|
||
|
NAME="GENERATOR"
|
||
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.57"><LINK
|
||
|
REL="HOME"
|
||
|
TITLE="Linux Network Administrators Guide"
|
||
|
HREF="index.html"><LINK
|
||
|
REL="UP"
|
||
|
TITLE="Configuring TCP/IP Networking"
|
||
|
HREF="x-087-2-iface.html"><LINK
|
||
|
REL="PREVIOUS"
|
||
|
TITLE="Creating Subnets"
|
||
|
HREF="x-087-2-create.subnets.html"><LINK
|
||
|
REL="NEXT"
|
||
|
TITLE="Interface Configuration for IP"
|
||
|
HREF="x-087-2-iface.interface.html"></HEAD
|
||
|
><BODY
|
||
|
CLASS="SECT1"
|
||
|
BGCOLOR="#FFFFFF"
|
||
|
TEXT="#000000"
|
||
|
LINK="#0000FF"
|
||
|
VLINK="#840084"
|
||
|
ALINK="#0000FF"
|
||
|
><DIV
|
||
|
CLASS="NAVHEADER"
|
||
|
><TABLE
|
||
|
WIDTH="100%"
|
||
|
BORDER="0"
|
||
|
CELLPADDING="0"
|
||
|
CELLSPACING="0"
|
||
|
><TR
|
||
|
><TH
|
||
|
COLSPAN="3"
|
||
|
ALIGN="center"
|
||
|
>Linux Network Administrators Guide</TH
|
||
|
></TR
|
||
|
><TR
|
||
|
><TD
|
||
|
WIDTH="10%"
|
||
|
ALIGN="left"
|
||
|
VALIGN="bottom"
|
||
|
><A
|
||
|
HREF="x-087-2-create.subnets.html"
|
||
|
>Prev</A
|
||
|
></TD
|
||
|
><TD
|
||
|
WIDTH="80%"
|
||
|
ALIGN="center"
|
||
|
VALIGN="bottom"
|
||
|
>Chapter 5. Configuring TCP/IP Networking</TD
|
||
|
><TD
|
||
|
WIDTH="10%"
|
||
|
ALIGN="right"
|
||
|
VALIGN="bottom"
|
||
|
><A
|
||
|
HREF="x-087-2-iface.interface.html"
|
||
|
>Next</A
|
||
|
></TD
|
||
|
></TR
|
||
|
></TABLE
|
||
|
><HR
|
||
|
ALIGN="LEFT"
|
||
|
WIDTH="100%"></DIV
|
||
|
><DIV
|
||
|
CLASS="SECT1"
|
||
|
><H1
|
||
|
CLASS="SECT1"
|
||
|
><A
|
||
|
NAME="X-087-2-IFACE.SIMPLE-RESOLV"
|
||
|
>5.6. Writing hosts and networks Files</A
|
||
|
></H1
|
||
|
><P
|
||
|
>After you have subnetted your network, you should prepare for some simple
|
||
|
sort of hostname resolution using the <TT
|
||
|
CLASS="FILENAME"
|
||
|
>/etc/hosts</TT
|
||
|
> file.
|
||
|
If you are not going to use DNS or NIS for address resolution, you have to put
|
||
|
all hosts in the <TT
|
||
|
CLASS="FILENAME"
|
||
|
>hosts</TT
|
||
|
> file.</P
|
||
|
><P
|
||
|
>Even if you want to run DNS or NIS during normal operation, you should
|
||
|
have some subset of all hostnames in
|
||
|
<TT
|
||
|
CLASS="FILENAME"
|
||
|
>/etc/hosts</TT
|
||
|
>. You should have some sort of name
|
||
|
resolution, even when no network interfaces are running, for example,
|
||
|
during boot time. This is not only a matter of convenience, but it
|
||
|
allows you to use symbolic hostnames in your network
|
||
|
<TT
|
||
|
CLASS="FILENAME"
|
||
|
>rc</TT
|
||
|
> scripts. Thus, when changing IP addresses, you
|
||
|
only have to copy an updated <TT
|
||
|
CLASS="FILENAME"
|
||
|
>hosts</TT
|
||
|
> file to all
|
||
|
machines and reboot, rather than edit a large number of
|
||
|
<TT
|
||
|
CLASS="FILENAME"
|
||
|
>rc</TT
|
||
|
> files separately. Usually you put all local
|
||
|
hostnames and addresses in <TT
|
||
|
CLASS="FILENAME"
|
||
|
>hosts</TT
|
||
|
>, adding those of
|
||
|
any gateways and NIS servers used.<A
|
||
|
NAME="X-087-2-FNTC03"
|
||
|
HREF="#FTN.X-087-2-FNTC03"
|
||
|
>[1]</A
|
||
|
></P
|
||
|
><P
|
||
|
>You should make sure your resolver only uses information from the
|
||
|
<TT
|
||
|
CLASS="FILENAME"
|
||
|
>hosts</TT
|
||
|
> file during initial testing. Sample files
|
||
|
that come with your DNS or NIS software may produce strange
|
||
|
results. To make all applications use <TT
|
||
|
CLASS="FILENAME"
|
||
|
>/etc/hosts</TT
|
||
|
>
|
||
|
exclusively when looking up the IP address of a host, you have to edit
|
||
|
the <TT
|
||
|
CLASS="FILENAME"
|
||
|
>/etc/host.conf</TT
|
||
|
> file. Comment out any lines
|
||
|
that begin with the keyword <SPAN
|
||
|
CLASS="SYSTEMITEM"
|
||
|
>order</SPAN
|
||
|
> by preceding them with a hash sign,
|
||
|
and insert the line:
|
||
|
|
||
|
<TABLE
|
||
|
BORDER="0"
|
||
|
BGCOLOR="#E0E0E0"
|
||
|
WIDTH="100%"
|
||
|
><TR
|
||
|
><TD
|
||
|
><PRE
|
||
|
CLASS="SCREEN"
|
||
|
>order hosts</PRE
|
||
|
></TD
|
||
|
></TR
|
||
|
></TABLE
|
||
|
></P
|
||
|
><P
|
||
|
>The configuration of the resolver library is covered in detail in
|
||
|
<A
|
||
|
HREF="x-087-2-resolv.html"
|
||
|
>Chapter 6</A
|
||
|
>.</P
|
||
|
><P
|
||
|
>The <TT
|
||
|
CLASS="FILENAME"
|
||
|
>hosts</TT
|
||
|
> file contains one entry per line, consisting
|
||
|
of an IP address, a hostname, and an optional list of aliases for the
|
||
|
hostname. The fields are separated by spaces or tabs, and the address
|
||
|
field must begin in the first column. Anything following a hash sign (#) is
|
||
|
regarded as a comment and is ignored.</P
|
||
|
><P
|
||
|
>Hostnames can be either fully qualified or relative to the local domain.
|
||
|
For <SPAN
|
||
|
CLASS="SYSTEMITEM"
|
||
|
>vale</SPAN
|
||
|
>, you would usually enter the
|
||
|
fully qualified name, <SPAN
|
||
|
CLASS="SYSTEMITEM"
|
||
|
>vale.vbrew.com</SPAN
|
||
|
>,
|
||
|
and <SPAN
|
||
|
CLASS="SYSTEMITEM"
|
||
|
>vale</SPAN
|
||
|
> by itself in the
|
||
|
<TT
|
||
|
CLASS="FILENAME"
|
||
|
>hosts</TT
|
||
|
> file, so that it is known by both its official name
|
||
|
and the shorter local name.</P
|
||
|
><P
|
||
|
>This is an example how a <TT
|
||
|
CLASS="FILENAME"
|
||
|
>hosts</TT
|
||
|
> file at the Virtual
|
||
|
Brewery might look. Two special names are included,
|
||
|
<SPAN
|
||
|
CLASS="SYSTEMITEM"
|
||
|
>vlager-if1</SPAN
|
||
|
> and
|
||
|
<SPAN
|
||
|
CLASS="SYSTEMITEM"
|
||
|
>vlager-if2</SPAN
|
||
|
>, which give the addresses
|
||
|
for both interfaces used on <SPAN
|
||
|
CLASS="SYSTEMITEM"
|
||
|
>vlager</SPAN
|
||
|
>:</P
|
||
|
><P
|
||
|
><TABLE
|
||
|
BORDER="0"
|
||
|
BGCOLOR="#E0E0E0"
|
||
|
WIDTH="100%"
|
||
|
><TR
|
||
|
><TD
|
||
|
><PRE
|
||
|
CLASS="SCREEN"
|
||
|
>#
|
||
|
# Hosts file for Virtual Brewery/Virtual Winery
|
||
|
#
|
||
|
# IP FQDN aliases
|
||
|
#
|
||
|
127.0.0.1 localhost
|
||
|
#
|
||
|
172.16.1.1 vlager.vbrew.com vlager vlager-if1
|
||
|
172.16.1.2 vstout.vbrew.com vstout
|
||
|
172.16.1.3 vale.vbrew.com vale
|
||
|
#
|
||
|
172.16.2.1 vlager-if2
|
||
|
172.16.2.2 vbeaujolais.vbrew.com vbeaujolais
|
||
|
172.16.2.3 vbardolino.vbrew.com vbardolino
|
||
|
172.16.2.4 vchianti.vbrew.com vchianti</PRE
|
||
|
></TD
|
||
|
></TR
|
||
|
></TABLE
|
||
|
></P
|
||
|
><P
|
||
|
>
|
||
|
Just as with a host's IP address, you should sometimes use a symbolic
|
||
|
name for network numbers, too. Therefore, the
|
||
|
<TT
|
||
|
CLASS="FILENAME"
|
||
|
>hosts</TT
|
||
|
> file has a companion called
|
||
|
<TT
|
||
|
CLASS="FILENAME"
|
||
|
>/etc/networks</TT
|
||
|
> that maps network names to network
|
||
|
numbers, and vice versa. At the Virtual Brewery, we might install a
|
||
|
<TT
|
||
|
CLASS="FILENAME"
|
||
|
>networks</TT
|
||
|
> file like this:<A
|
||
|
NAME="X-087-2-FNTC04"
|
||
|
HREF="#FTN.X-087-2-FNTC04"
|
||
|
>[2]</A
|
||
|
>
|
||
|
|
||
|
<TABLE
|
||
|
BORDER="0"
|
||
|
BGCOLOR="#E0E0E0"
|
||
|
WIDTH="100%"
|
||
|
><TR
|
||
|
><TD
|
||
|
><PRE
|
||
|
CLASS="SCREEN"
|
||
|
># /etc/networks for the Virtual Brewery
|
||
|
brew-net 172.16.1.0
|
||
|
wine-net 172.16.2.0</PRE
|
||
|
></TD
|
||
|
></TR
|
||
|
></TABLE
|
||
|
></P
|
||
|
></DIV
|
||
|
><H3
|
||
|
CLASS="FOOTNOTES"
|
||
|
>Notes</H3
|
||
|
><TABLE
|
||
|
BORDER="0"
|
||
|
CLASS="FOOTNOTES"
|
||
|
WIDTH="100%"
|
||
|
><TR
|
||
|
><TD
|
||
|
ALIGN="LEFT"
|
||
|
VALIGN="TOP"
|
||
|
WIDTH="5%"
|
||
|
><A
|
||
|
NAME="FTN.X-087-2-FNTC03"
|
||
|
HREF="x-087-2-iface.simple-resolv.html#X-087-2-FNTC03"
|
||
|
>[1]</A
|
||
|
></TD
|
||
|
><TD
|
||
|
ALIGN="LEFT"
|
||
|
VALIGN="TOP"
|
||
|
WIDTH="95%"
|
||
|
><P
|
||
|
>You need the address of an NIS server only if you use Peter Eriksson's
|
||
|
NYS. Other NIS implementations locate their servers only at runtime by
|
||
|
using <B
|
||
|
CLASS="COMMAND"
|
||
|
>ypbind</B
|
||
|
>.</P
|
||
|
></TD
|
||
|
></TR
|
||
|
><TR
|
||
|
><TD
|
||
|
ALIGN="LEFT"
|
||
|
VALIGN="TOP"
|
||
|
WIDTH="5%"
|
||
|
><A
|
||
|
NAME="FTN.X-087-2-FNTC04"
|
||
|
HREF="x-087-2-iface.simple-resolv.html#X-087-2-FNTC04"
|
||
|
>[2]</A
|
||
|
></TD
|
||
|
><TD
|
||
|
ALIGN="LEFT"
|
||
|
VALIGN="TOP"
|
||
|
WIDTH="95%"
|
||
|
><P
|
||
|
> Note that names in
|
||
|
<TT
|
||
|
CLASS="FILENAME"
|
||
|
>networks</TT
|
||
|
> must not collide with hostnames from the
|
||
|
<TT
|
||
|
CLASS="FILENAME"
|
||
|
>hosts</TT
|
||
|
> file, or else some programs may produce
|
||
|
strange results.</P
|
||
|
></TD
|
||
|
></TR
|
||
|
></TABLE
|
||
|
><DIV
|
||
|
CLASS="NAVFOOTER"
|
||
|
><HR
|
||
|
ALIGN="LEFT"
|
||
|
WIDTH="100%"><TABLE
|
||
|
WIDTH="100%"
|
||
|
BORDER="0"
|
||
|
CELLPADDING="0"
|
||
|
CELLSPACING="0"
|
||
|
><TR
|
||
|
><TD
|
||
|
WIDTH="33%"
|
||
|
ALIGN="left"
|
||
|
VALIGN="top"
|
||
|
><A
|
||
|
HREF="x-087-2-create.subnets.html"
|
||
|
>Prev</A
|
||
|
></TD
|
||
|
><TD
|
||
|
WIDTH="34%"
|
||
|
ALIGN="center"
|
||
|
VALIGN="top"
|
||
|
><A
|
||
|
HREF="index.html"
|
||
|
>Home</A
|
||
|
></TD
|
||
|
><TD
|
||
|
WIDTH="33%"
|
||
|
ALIGN="right"
|
||
|
VALIGN="top"
|
||
|
><A
|
||
|
HREF="x-087-2-iface.interface.html"
|
||
|
>Next</A
|
||
|
></TD
|
||
|
></TR
|
||
|
><TR
|
||
|
><TD
|
||
|
WIDTH="33%"
|
||
|
ALIGN="left"
|
||
|
VALIGN="top"
|
||
|
>Creating Subnets</TD
|
||
|
><TD
|
||
|
WIDTH="34%"
|
||
|
ALIGN="center"
|
||
|
VALIGN="top"
|
||
|
><A
|
||
|
HREF="x-087-2-iface.html"
|
||
|
>Up</A
|
||
|
></TD
|
||
|
><TD
|
||
|
WIDTH="33%"
|
||
|
ALIGN="right"
|
||
|
VALIGN="top"
|
||
|
>Interface Configuration for IP</TD
|
||
|
></TR
|
||
|
></TABLE
|
||
|
></DIV
|
||
|
></BODY
|
||
|
></HTML
|
||
|
>
|