| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 | 
							- <?xml version="1.0" encoding="UTF-8"?>
 
- <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
 
-   "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
 
-   <!ENTITY % general-entities SYSTEM "../general.ent">
 
-   %general-entities;
 
- ]>
 
- <sect1 id="ch-scripts-network" revision="systemd">
 
-   <?dbhtml filename="network.html"?>
 
-   <title>一般网络配置</title>
 
-   <indexterm zone="ch-scripts-network">
 
-     <primary sortas="d-network">network</primary>
 
-   <secondary>configuring</secondary></indexterm>
 
-   <para>本节只适用于需要配置网卡的情况。</para>
 
-   <sect2>
 
-     <title>网络接口配置文件</title>
 
- 	<para>从 209 版本开始,systemd 提供一个名为
 
- 		<command>systemd-networkd</command> 的网络配置守护进程,
 
- 		它能够用于基础网络配置。另外,自 213 版本起,可以用
 
- 		<command>systemd-resolved</command> 代替静态
 
- 		<filename>/etc/resolv.conf</filename> 文件处理域名解析。
 
- 		这两个服务在默认情况下都是启用的。</para>
 
-     <para><command>systemd-networkd</command> (以及
 
-     <command>systemd-resolved</command>)的配置文件可以放置在
 
-     <filename class="directory">/usr/lib/systemd/network</filename>
 
-     或 <filename class="directory">/etc/systemd/network</filename> 中。
 
-     <filename class="directory">/etc/systemd/network</filename>
 
-     中的配置文件优先级高于
 
-     <filename class="directory">/usr/lib/systemd/network</filename>
 
-     中的配置文件。有三种类型的配置文件:
 
-     <filename class="extension">.link</filename>、
 
-     <filename class="extension">.netdev</filename> 和
 
-     <filename class="extension">.network</filename> 文件。
 
-     要获得它们的详细描述和内容示例,参阅
 
-     the <filename>systemd-link(5)</filename>、
 
-     <filename>systemd-netdev(5)</filename> 和
 
-     <filename>systemd-network(5)</filename> man 手册页面。</para>
 
-     <sect3 id="systemd-network-devices">
 
-       <title>网络设备命名</title>
 
-       <!--para>
 
-         Udev normally assigns network card interface names based
 
-         on system physical characteristics such as enp2s1. If you are
 
-         not sure what your interface name is, you can always run
 
-         <command>ip link</command> after you have booted your system.
 
-       </para-->
 
- 	  <para>
 
- 		  Udev 一般根据系统物理特征为网卡分配接口名,例如 enp2s1。
 
- 		  如果您不确定接口名是什么,可以在引导您的系统后,
 
- 		  运行 <command>ip link</command> 命令。
 
- 	  </para>
 
-       <!--para>
 
-         For most systems, there is only one network interface for
 
-         each type of connection.  For example, the classic interface
 
-         name for a wired connection is eth0.  A wireless connection
 
-         will usually have the name wifi0 or wlan0. 
 
-       </para-->
 
- 	  <para>
 
- 		  对于多数系统,每种连接类型只有一个网络接口。
 
- 		  例如,有线连接的经典接口名是 eth0,而无线连接的接口名一般是
 
- 		  wifi0 或 wlan0。
 
- 	  </para>
 
-       <!--para>
 
-         If you prefer to use the classic or customized network interface names,
 
-         there are three alternative ways to do that:</para-->
 
- 	  <para>
 
- 		  如果您偏爱经典或自定义网络接口名,可以使用三种不同方式:
 
- 	  </para>
 
-       <itemizedlist>
 
-         <listitem>
 
-           <para>
 
-             覆盖 udev 提供默认策略的 .link 文件:
 
- <screen role="nodump"><userinput>ln -s /dev/null /etc/systemd/network/99-default.link</userinput></screen>
 
-           </para>
 
-         </listitem>
 
-         <listitem>
 
-           <!--para>
 
-              Create a manual naming scheme, for example by naming the
 
-              interfaces something like "internet0", "dmz0", or "lan0". 
 
-              For that, create .link
 
-              files in /etc/systemd/network/, that choose an explicit name or a
 
-              better naming scheme for one, some, or all of your interfaces. 
 
-              For example:
 
-           </para-->
 
- 		  <para>
 
- 			  手动创建命名架构,例如将网络接口命名为
 
- 			  <quote>internet0</quote>、<quote>dmz0</quote> 或
 
- 			  <quote>lan0</quote>。为此,在 /etc/systemd/network
 
- 			  中创建 .link 文件,为您的一个、
 
- 			  一些或全部网络接口直接选择名称,或选择更好的命名架构。
 
- 			  例如:
 
- 		  </para>
 
- <screen role="nodump"><userinput>cat > /etc/systemd/network/10-ether0.link << "EOF"
 
- <literal>[Match]
 
- # 将 MAC 地址替换为适用于您的网络设备的值
 
- MACAddress=12:34:45:78:90:AB
 
- [Link]
 
- Name=ether0</literal>
 
- EOF</userinput></screen>
 
-           <para>
 
-              参阅 man 页面 systemd.link(5) 获得更多信息。
 
-           </para>
 
-         </listitem>
 
-         <listitem>
 
-           <para>
 
-             在 /boot/grub/grub.cfg 的内核命令行中传递选项
 
-             net.ifnames=0。
 
-           </para>
 
-         </listitem>
 
-       </itemizedlist>
 
-     </sect3>
 
-     <sect3 id="systemd-networkd-static">
 
-       <title>静态 IP 配置</title>
 
-       <para>以下命令为静态 IP 设置创建一个基本的配置文件
 
-       (使用 systemd-networkd 和 systemd-resolved)。</para>
 
- <screen><userinput>cat > /etc/systemd/network/10-eth-static.network << "EOF"
 
- <literal>[Match]
 
- Name=<网络设备名>
 
- [Network]
 
- Address=192.168.0.2/24
 
- Gateway=192.168.0.1
 
- DNS=192.168.0.1
 
- Domains=<replaceable><您的域名></replaceable></literal>
 
- EOF</userinput></screen>
 
-       <para>如果您有多个 DNS 服务器,可以在配置文件中创建多个 DNS 项。
 
-       如果您希望使用静态 <filename>/etc/resolv.conf</filename> 文件,
 
-       则不要在配置文件中包含 DNS 和 Domains 项。</para>
 
-     </sect3>
 
-     <sect3 id="systemd-networkd-dhcp">
 
-       <title>DHCP 配置</title>
 
-       <para>以下命令为 IPv4 DHCP 配置创建基本配置文件:</para>
 
- <screen role="nodump"><userinput>cat > /etc/systemd/network/10-eth-dhcp.network << "EOF"
 
- <literal>[Match]
 
- Name=<网络设备名>
 
- [Network]
 
- DHCP=ipv4
 
- [DHCP]
 
- UseDomains=true</literal>
 
- EOF</userinput></screen>
 
-     </sect3>
 
-   </sect2>
 
-   <sect2 id="resolv.conf">
 
-     <title>创建 /etc/resolv.conf 文件</title>
 
-     <indexterm zone="resolv.conf">
 
-       <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
 
-     </indexterm>
 
-     <!--para>If the system is going to be connected to the Internet, it will
 
-     need some means of Domain Name Service (DNS) name resolution to
 
-     resolve Internet domain names to IP addresses, and vice versa. This is
 
-     best achieved by placing the IP address of the DNS server, available
 
-     from the ISP or network administrator, into
 
-     <filename>/etc/resolv.conf</filename>.</para-->
 
-     <para>如果要将系统连接到 Internet ,它需要某种域名服务(DNS)
 
-       名称解析方式,以将 Internet 域名解析为 IP 地址,
 
-       或将 IP 地址解析为域名。最好的方法是将 ISP 或网络管理员提供的
 
-       DNS 服务器 IP 地址写入 <filename>/etc/resolv.conf</filename>。</para>
 
-     <sect3 id="resolv-conf-systemd-resolved">
 
-       <title>systemd-resolved 配置</title>
 
-       <!--note><para>If using another means to configure your network
 
-       interfaces (ex: ppp, network-manager, etc.), or if using any type of
 
-       local resolver (ex: bind, dnsmasq, etc.), or any other software that
 
-       generates an <filename>/etc/resolv.conf</filename> (ex: resolvconf), the
 
-       <command>systemd-resolved</command> service should not be
 
-       used.</para></note-->
 
-       <note><para>如果使用其他方式配置网络接口(例如 ppp 或 network-manager
 
-           等),或使用了某种本地解析器(如 bind 或 dnsmasq 等),
 
-           或其他任何生成 <filename>/etc/resolv.conf</filename>
 
-           的软件(如 resolvconf),则不应使用
 
-           <command>systemd-resolved</command> 服务。</para></note>
 
-       <para>在使用 <command>systemd-resolved</command> 进行 DNS
 
-       配置时,它创建文件
 
-       <filename>/run/systemd/resolve/resolv.conf</filename>。在
 
-       <filename>/etc</filename> 中创建符号链接以使用生成的文件:</para>
 
- <screen><userinput>ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf</userinput></screen>
 
-     </sect3>
 
-     <sect3 id="resolv-conf-static">
 
-       <title>静态 resolv.conf 配置</title>
 
-       <para>如果希望使用静态的 <filename>/etc/resolv.conf</filename>
 
-       执行以下命令创建它:</para>
 
- <screen role="nodump"><userinput>cat > /etc/resolv.conf << "EOF"
 
- <literal># Begin /etc/resolv.conf
 
- domain <replaceable><您的域名></replaceable>
 
- nameserver <replaceable><您的主要域名服务器 IP 地址></replaceable>
 
- nameserver <replaceable><您的次要域名服务器 IP 地址></replaceable>
 
- # End /etc/resolv.conf</literal>
 
- EOF</userinput></screen>
 
-       <para>可以省略 <varname>domain</varname> 语句,
 
-       或使用一条 <varname>search</varname> 语句代替它。
 
-       阅读 resolv.conf 的 man 页面了解更多细节。</para>
 
-       <para>将
 
-       <replaceable><域名服务器的 IP 地址></replaceable>
 
-       替换为您的网络环境下最合适的 DNS 服务器 IP 地址。
 
- 	  这里往往会写入不止一个 DNS 服务器(需要提供后备功能的次要服务器)。
 
- 	  如果您只需要或只希望使用一个 DNS 服务器,可以删除文件中的第二个
 
-       <emphasis>nameserver</emphasis> 行。也可以写入本地路由器的 IP 地址。
 
-       </para>
 
-       <note><para>Google 公用 DNS 服务器的 IPv4 地址是
 
-       <parameter>8.8.8.8</parameter> 和 <parameter>8.8.4.4</parameter>,
 
-       IPv6 地址是 <parameter>2001:4860:4860::8888</parameter> 和
 
-       <parameter>2001:4860:4860::8844</parameter>。</para></note>
 
-     </sect3>
 
-   </sect2>
 
-   <sect2 id="ch-scripts-hostname">
 
-     <title>配置系统主机名</title>
 
-     <indexterm zone="ch-scripts-hostname">
 
-       <primary sortas="d-hostname">hostname</primary>
 
-       <secondary>configuring</secondary>
 
-     </indexterm>
 
-      <para>在引导过程中,<filename>/etc/hostname</filename>
 
-      被用于设定系统主机名。</para>
 
-      <para>执行以下命令,创建 <filename>/etc/hostname</filename>
 
-      文件,并输入一个主机名:</para>
 
- <screen><userinput>echo "<replaceable><lfs></replaceable>" > /etc/hostname</userinput></screen>
 
-      <para><replaceable><lfs></replaceable>
 
-      需要被替换为赋予该计算机的名称。
 
-      不要在这里输入全限定域名 (FQDN) ,它应该被写入
 
- 	 <filename>/etc/hosts</filename> 文件。</para>
 
-   </sect2>
 
-   <sect2 id="ch-scripts-hosts">
 
-      <title>自定义 /etc/hosts 文件</title>
 
-      <indexterm zone="ch-scripts-hosts">
 
-        <primary sortas="e-/etc/hosts">/etc/hosts</primary>
 
-      </indexterm>
 
-    
 
-      <indexterm zone="ch-scripts-hosts">
 
-        <primary sortas="d-localnet">localnet</primary>
 
-        <secondary>/etc/hosts</secondary>
 
-      </indexterm>
 
-    
 
-      <indexterm zone="ch-scripts-hosts">
 
-        <primary sortas="d-network">network</primary>
 
-        <secondary>/etc/hosts</secondary>
 
-      </indexterm>
 
-      <para>选择一个全限定域名 (FQDN),和可能的别名,以供
 
-      <filename>/etc/hosts</filename> 文件使用。如果使用静态 IP 地址,
 
-      您还需要确定要使用的 IP 地址。
 
-      hosts 文件条目的语法是:</para>
 
- <screen><literal>IP_地址 主机名.域名 别名</literal></screen>
 
-      <para>除非该计算机可以从 Internet 访问 (即拥有一个注册域名,
 
-      并分配了一个有效的 IP 地址段 —— 多数用户没有分配有效 IP),
 
- 	 确认使用的 IP 地址属于私网 IP 范围。有效的范围是:</para>
 
- <screen><literal>私网地址范围      公共前缀长度
 
- 10.0.0.1 - 10.255.255.254           8
 
- 172.x.0.1 - 172.x.255.254           16
 
- 192.168.y.1 - 192.168.y.254         24</literal></screen>
 
-      <para>x 可以是 16-31 之间的任何数字,y 可以是 0-255 之间的任何数字。
 
-      </para>
 
-      <para>有效的私网 IP 地址的一个例子是 192.168.1.1。
 
-      与之对应的 FQDN 可以是 lfs.example.org。</para>
 
-      <para>即使没有网卡,也要提供一个有效的 FQDN,
 
-      某些程序需要它才能正常工作。</para>
 
-      <para>如果使用 DHCP、DHCPv6 或 IPv6 自动配置,或者不准备配置网卡,
 
-      执行以下命令创建 <filename>/etc/hosts</filename> 文件:</para>
 
- <screen role="nodump"><userinput>cat > /etc/hosts << "EOF"
 
- <literal># Begin /etc/hosts
 
- 127.0.0.1 localhost
 
- 127.0.1.1 <replaceable><FQDN></replaceable> <replaceable><主机名></replaceable>
 
- ::1       localhost ip6-localhost ip6-loopback
 
- ff02::1   ip6-allnodes
 
- ff02::2   ip6-allrouters
 
- # End /etc/hosts</literal>
 
- EOF</userinput></screen>
 
-      <para>::1 是 127.0.0.1 在 IPv6 中的对应,即 IPv6 回环接口。 </para>
 
- 	 <para>如果使用静态地址,执行以下命令创建
 
-      <filename>/etc/hosts</filename> 文件:</para>
 
- <screen><userinput>cat > /etc/hosts << "EOF"
 
- <literal># Begin /etc/hosts
 
- 127.0.0.1 localhost
 
- 127.0.1.1 <replaceable><FQDN></replaceable> <replaceable><主机名></replaceable>
 
- <replaceable><192.168.0.2></replaceable> <replaceable><FQDN></replaceable> <replaceable><主机名></replaceable> <replaceable>[别名 1] [别名 2] ...</replaceable>
 
- ::1       localhost ip6-localhost ip6-loopback
 
- ff02::1   ip6-allnodes
 
- ff02::2   ip6-allrouters
 
- # End /etc/hosts</literal>
 
- EOF</userinput></screen>
 
-      <para>其中 <replaceable><192.168.0.2></replaceable>、
 
-      <replaceable><FQDN></replaceable> 和
 
- 	 <replaceable><HOSTNAME></replaceable>
 
- 	 值需要为特定使用环境和需求进行修改
 
- 	 (如果系统或网络管理员分配了 IP 地址,且本机将被连接到现有的网络中)。
 
-      可以跳过别名(alias),它们不是必要的。</para>
 
-    
 
-    </sect2>
 
- </sect1>
 
 
  |