source: chapter07/network.xml@ 82d2dbe

Last change on this file since 82d2dbe was 82d2dbe, checked in by DJ Lucas <dj@…>, 8 years ago

Update hosts file creation and explanatory text.

git-svn-id: http://svn.linuxfromscratch.org/LFS/branches/systemd@11071 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 10.4 KB
RevLine 
[673b0d8]1<?xml version="1.0" encoding="ISO-8859-1"?>
[b06ca36]2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
[673b0d8]4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
6]>
[d781ffb]7
[3be4d97]8<sect1 id="ch-scripts-network">
[d781ffb]9 <?dbhtml filename="network.html"?>
10
[0cda898]11 <title>General Network Configuration</title>
[d781ffb]12
13 <indexterm zone="ch-scripts-network">
14 <primary sortas="d-network">network</primary>
15 <secondary>configuring</secondary></indexterm>
16
17 <para>This section only applies if a network card is to be
18 configured.</para>
19
20 <sect2>
[abadfc3]21 <title>Network Interface Configuration Files</title>
22
23 <para>Starting with version 209, systemd ships a network configuration
24 daemon called <command>systemd-networkd</command> which can be used for
[131c907]25 basic network configuration. Additionally, since version 213, DNS name
26 resolution can be handled by <command>systemd-resolved</command> in place
27 of a static <filename>/etc/resolv.conf</filename> file. Both services are
28 enabled by defualt, and absolutely should not be disabled.</para>
29
30 <para>Configuration files for <command>systemd-networkd</command> (and
31 <command>systemd-resolved</command>) can be placed in
32 <filename class="directory">/usr/lib/systemd/network</filename>
33 or <filename class="directory">/etc/systemd/network</filename>. Files in
34 <filename class="directory">/etc/systemd/network</filename> have a
[abadfc3]35 higher priority than the ones in
[131c907]36 <filename class="directory">/usr/lib/systemd/network</filename>.
37 There are three types of configuration files:
[abadfc3]38 <filename class="extension">.link</filename>,
39 <filename class="extension">.netdev</filename> and
40 <filename class="extension">.network</filename> files. For detailed
[131c907]41 descriptions and example contents of these configuration files, consult
42 the <filename>systemd-link(5)</filename>,
[39507e9]43 <filename>systemd-netdev(5)</filename> and
44 <filename>systemd-network(5)</filename> manual pages.</para>
[abadfc3]45
46 <note><para>Udev may assign network card interface names based
47 on system physical characteristics such as enp2s1. If you are
48 not sure what your interface name is, you can always run
49 <command>ip link</command> after you have booted your system.
50 </para></note>
51
52 <sect3 id="systemd-networkd-static">
53 <title>Static IP Configuration</title>
54
[131c907]55 <para>The command below creates a basic configuration file for a
56 Static IP setup (using both systemd-networkd and
57 systemd-resolved):</para>
[abadfc3]58
[131c907]59<screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-eth0-static.network &lt;&lt; "EOF"
[abadfc3]60<literal>[Match]
61Name=eth0
62
63[Network]
64Address=192.168.0.2/24
65Gateway=192.168.0.1
66DNS=192.168.0.1</literal>
[f67f5cf]67EOF</userinput></screen>
[00a2bd12]68
[131c907]69 <para>Multiple DNS entries can be added if you have more than one DNS
70 server.</para>
[0cda898]71
[abadfc3]72 </sect3>
[d781ffb]73
[abadfc3]74 <sect3 id="systemd-networkd-dhcp">
75 <title>DHCP Configuration</title>
[d781ffb]76
[131c907]77 <para>The command below creates a basic configuration file for an IPv4
[abadfc3]78 DHCP setup:</para>
[d781ffb]79
[131c907]80<screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-eth0-dhcp.network &lt;&lt; "EOF"
[abadfc3]81<literal>[Match]
82Name=eth0
[970a126]83
[abadfc3]84[Network]
[131c907]85DHCP=ipv4</literal>
[abadfc3]86EOF</userinput></screen>
[94f4fb86]87
[abadfc3]88 </sect3>
[94f4fb86]89
90 </sect2>
91
[d781ffb]92 <sect2 id="resolv.conf">
93 <title>Creating the /etc/resolv.conf File</title>
94
95 <indexterm zone="resolv.conf">
96 <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
97 </indexterm>
98
99 <para>If the system is going to be connected to the Internet, it will
100 need some means of Domain Name Service (DNS) name resolution to
101 resolve Internet domain names to IP addresses, and vice versa. This is
102 best achieved by placing the IP address of the DNS server, available
103 from the ISP or network administrator, into
[abadfc3]104 <filename>/etc/resolv.conf</filename>.</para>
105
[131c907]106 <sect3 id="resolv-conf-systemd-resoloved">
107 <title>systemd-resolved Configuration</title>
108
109 <note><para>If using another means to configure your network
110 interfaces (ex: ppp, network-manager, etc.), or if using any type of
111 local resolver (ex: bind, dnsmasq, etc.), or any other software that
112 generates an <filename>/etc/resolv.conf</filename> (ex: resolvconf), the
113 <command>systemd-resolved</command> service should not be
114 used.</para></note>
115
116 <para>When using <command>systemd-resolved</command> for DNS
117 configuration, it is responsible for creating the
[26ae89a]118 <filename>/etc/resolv.conf</filename> file. Since version 226, the
119 symlink for <filename>/etc/resolv.conf</filename> is created by systemd
120 when needed, so no further configuration is necessary.</para>
[131c907]121
122 </sect3>
123
124 <sect3 id="resolv-conf-static">
125 <title>Static resolv.conf Configuration</title>
126
127 <para>If a static <filename>/etc/resolv.conf</filename> is desired,
128 create it by running the following command:</para>
[45340ae]129
[acbb08f]130<screen role="nodump"><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
[d72e04a]131<literal># Begin /etc/resolv.conf
[45340ae]132
[4b51ca76]133domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
[0090db5]134nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
135nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
[45340ae]136
[d72e04a]137# End /etc/resolv.conf</literal>
[f67f5cf]138EOF</userinput></screen>
[45340ae]139
[131c907]140 <para>The <varname>domain</varname> statement can be omitted
141 or replaced with a <varname>search</varname> statement. See the man page
142 for resolv.conf for more details.</para>
[0cda898]143
[131c907]144 <para>Replace
145 <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
146 with the IP address of the DNS most appropriate for the setup. There will
147 often be more than one entry (requirements demand secondary servers for
148 fallback capability). If you only need or want one DNS server, remove the
149 second <emphasis>nameserver</emphasis> line from the file. The IP address
150 may also be a router on the local network.</para>
[45340ae]151
[131c907]152 <note><para>The Google Public IPv4 DNS addresses are
153 <parameter>8.8.8.8</parameter> and <parameter>8.8.4.4</parameter>
154 for IPv4, and <parameter>2001:4860:4860::8888</parameter> and
155 <parameter>2001:4860:4860::8844</parameter> for IPv6.</para></note>
[0cda898]156
[131c907]157 </sect3>
[acbb08f]158
[d781ffb]159 </sect2>
[81fd230]160
[abadfc3]161 <sect2 id="ch-scripts-hostname">
162 <title>Configuring the system hostname</title>
163
164 <indexterm zone="ch-scripts-hostname">
165 <primary sortas="d-hostname">hostname</primary>
166 <secondary>configuring</secondary>
167 </indexterm>
168
169 <para>During the boot process, the file <filename>/etc/hostname</filename>
170 is used for establishing the system's hostname.</para>
171
172 <para>Create the <filename>/etc/hostname</filename> file and enter a
173 hostname by running:</para>
174
175<screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
176
177 <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
178 name given to the computer. Do not enter the Fully Qualified Domain Name
179 (FQDN) here. That information is put in the
180 <filename>/etc/hosts</filename> file.</para>
181
182 </sect2>
183
184 <sect2 id="ch-scripts-hosts">
185 <title>Customizing the /etc/hosts File</title>
186
187 <indexterm zone="ch-scripts-hosts">
188 <primary sortas="e-/etc/hosts">/etc/hosts</primary>
189 </indexterm>
190
191 <indexterm zone="ch-scripts-hosts">
192 <primary sortas="d-localnet">localnet</primary>
193 <secondary>/etc/hosts</secondary>
194 </indexterm>
195
196 <indexterm zone="ch-scripts-hosts">
197 <primary sortas="d-network">network</primary>
198 <secondary>/etc/hosts</secondary>
199 </indexterm>
[82d2dbe]200
201 <para>Decide on a fully-qualified domain name (FQDN), and possible aliases
202 for use in the <filename>/etc/hosts</filename> file. If using static
203 addresses, you'll also need to decide on an IP address. The syntax
204 for a hosts file entry is:</para>
205
[abadfc3]206<screen><literal>IP_address myhost.example.org aliases</literal></screen>
207
208 <para>Unless the computer is to be visible to the Internet (i.e., there is
209 a registered domain and a valid block of assigned IP addresses&mdash;most
210 users do not have this), make sure that the IP address is in the private
211 network IP address range. Valid ranges are:</para>
212
213<screen><literal>Private Network Address Range Normal Prefix
21410.0.0.1 - 10.255.255.254 8
215172.x.0.1 - 172.x.255.254 16
216192.168.y.1 - 192.168.y.254 24</literal></screen>
217
218 <para>x can be any number in the range 16-31. y can be any number in the
219 range 0-255.</para>
[82d2dbe]220
[abadfc3]221 <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
222 this IP could be lfs.example.org.</para>
[82d2dbe]223
[abadfc3]224 <para>Even if not using a network card, a valid FQDN is still required.
225 This is necessary for certain programs to operate correctly.</para>
[82d2dbe]226
227 <para>If using DHCP, DHCPv6, IPv6 Autoconfiguration, or if a network card
228 is not going to be configured, create the <filename>/etc/hosts</filename>
229 file by running the following command:</para>
[abadfc3]230
231<screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
[82d2dbe]232<literal># Begin /etc/hosts
[abadfc3]233
[82d2dbe]234127.0.0.1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost <replaceable>[alias1] [alias2] ...</replaceable>
235::1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost <replaceable>[alias1] [alias2] ...</replaceable>
[abadfc3]236
[82d2dbe]237# End /etc/hosts</literal>
[abadfc3]238EOF</userinput></screen>
239
[82d2dbe]240 <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents
241the IPv6 loopback interface.</para>
242
243 <para>If ussing a staic address, create the <filename>/etc/hosts</filename>
244 file by running this command instead:</para>
[abadfc3]245
246<screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
[82d2dbe]247<literal># Begin /etc/hosts
[abadfc3]248
[82d2dbe]249127.0.0.1 localhost
[abfa34b]250::1 localhost
[82d2dbe]251<replaceable>&lt;192.168.0.2&gt;</replaceable> <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
[abadfc3]252
[82d2dbe]253# End /etc/hosts</literal>
[abadfc3]254EOF</userinput></screen>
255
[82d2dbe]256 <para>The <replaceable>&lt;192.168.0.2&gt;</replaceable>,
257 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable>, and
258 <replaceable>&lt;HOSTNAME&gt;</replaceable> values need to be
259 changed for specific uses or requirements (if assigned an IP address by a
260 network/system administrator and the machine will be connected to an
261 existing network). The optional alias name(s) can be omitted.</para>
262
[abadfc3]263 </sect2>
264
[d781ffb]265</sect1>
Note: See TracBrowser for help on using the repository browser.