📄 hosts.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=gb2312" />
<title>
7.11. Creating the /etc/hosts File
</title>
<link rel="stylesheet" href="../stylesheets/lfs.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.68.1" />
<link rel="stylesheet" href="../stylesheets/lfs-print.css" type="text/css" media="print" />
</head>
<body id="lfs" class="6.1">
<div class="navheader">
<div class="headertitles">
<h4>
Linux From Scratch - Version 6.1
</h4>
<h3>
Chapter 7. 配置系统启动脚本(Bootscripts)
</h3>
</div>
<ul class="headerlinks">
<li class="prev">
<a accesskey="p" href="hostname.html" title="Configuring the localnet Script">后退</a>
<p>
Configuring the localnet Script
</p>
</li>
<li class="next">
<a accesskey="n" href="network.html" title="Configuring the network Script">前进</a>
<p>
Configuring the network Script
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter07.html" title="Chapter 7. 配置系统启动脚本(Bootscripts)">上一级</a>.
</li>
<li class="home">
<a accesskey="h" href="../index.html" title="Linux From Scratch - Version 6.1">回首页</a>
</li>
</ul>
</div>
<div class="sect1" lang="zh_cn" xml:lang="zh_cn">
<div class="titlepage">
<h1 class="sect1">
7.11. 创建 /etc/hosts 文件</h1>
</div>
<p>
要在 <tt class="filename">/etc/hosts</tt> 文件里配置网卡的 IP 地址、FQDN 和可能会用的别名,语法如下:</p>
<pre class="screen"><IP address> myhost.example.org aliases</pre>
<p>除非您的计算机在 Internet 上是可访问的(例如,有一个注册的域名并分配到了一个合法的 IP 地址(块)(大多数用户没有)),请确保 IP 地址在私有网络 IP 地址范围内,正确的范围是:</p>
<pre class="screen"> 类别 网络
A 10.0.0.0
B 172.16.0.0 到 172.31.0.255
C 192.168.0.0 到 192.168.255.255</pre>
<p>一个合法的 IP 地址可能是 192.168.1.1,这个 IP 的合法 FQDN 可能是 www.linuxfromscratch.org(不推荐,因为这是个已合法注册的域名,这样做可能会造成域名服务器的问题)。</p>
<p>即使您没有网卡,仍然需要一个 FQDN,某些程序需要这个才能正常工作。</p>
<p>
运行下面的命令创建 <tt class="filename">/etc/hosts</tt> 文件:</p>
<pre class="userinput"><kbd class="command">cat > /etc/hosts << "EOF"
<tt class="literal"># Begin /etc/hosts (network card version)
127.0.0.1 localhost
<em class="replaceable"><tt>[192.168.1.1]</tt></em> <em class="replaceable"><tt>[<HOSTNAME>.example.org]</tt></em> <em class="replaceable"><tt>[HOSTNAME]</tt></em>
# End /etc/hosts (network card version)</tt>
EOF</kbd></pre>
<p>
把 <em class="replaceable"><tt>[192.168.1.1]</tt></em> 和
<em class="replaceable"><tt>[<HOSTNAME>.example.org]</tt></em>
更改为特定用户或特别要求所需要的值(如果这台机器要连入一个已存在的网络,并且网络/系统管理员已经给您分配了一个 IP 地址)。</p>
<p>
如果您不配置网卡,运行下面的命令创建
<tt class="filename">/etc/hosts</tt> 文件:</p>
<pre class="userinput"><kbd class="command">cat > /etc/hosts << "EOF"
<tt class="literal"># Begin /etc/hosts (no network card version)
127.0.0.1 <em class="replaceable"><tt>[<HOSTNAME>.example.org]</tt></em> <em class="replaceable"><tt>[HOSTNAME]</tt></em> localhost
# End /etc/hosts (no network card version)</tt>
EOF</kbd></pre>
</div>
<div class="navfooter">
<ul>
<li class="prev">
<a accesskey="p" href="hostname.html" title="Configuring the localnet Script">后退</a>
<p>
Configuring the localnet Script
</p>
</li>
<li class="next">
<a accesskey="n" href="network.html" title="Configuring the network Script">前进</a>
<p>
Configuring the network Script
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter07.html" title="Chapter 7. 配置系统启动脚本(Bootscripts)">上一级</a>.
</li>
<li class="home">
<a accesskey="h" href="../index.html" title="Linux From Scratch - Version 6.1">回首页</a>.
</li>
</ul>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -