source: chapter07/network.xml@ 6eb40d4

7.9-systemd
Last change on this file since 6eb40d4 was acbb08f, checked in by Krejzi <krejzi@…>, 10 years ago

Fixes to chapter07.

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

  • Property mode set to 100644
File size: 9.4 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="ch-scripts-network">
9 <?dbhtml filename="network.html"?>
10
11 <title>General Network Configuration</title>
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>
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
25 basic network configuration.</para>
26
27 <para>Configuration files for <command>systemd-networkd</command> can be
28 placed in <filename class="directory">/usr/lib/systemd/network</filename>
29 or <filename class="directory">/etc/systemd/network</filename>. Note that
30 files in <filename class="directory">/etc/systemd/network</filename> have
31 higher priority than the ones in
32 <filename class="directory">/usr/lib/systemd/network</filename>.</para>
33
34 <para>There are three types of configuration files:
35 <filename class="extension">.link</filename>,
36 <filename class="extension">.netdev</filename> and
37 <filename class="extension">.network</filename> files. For detailed
38 explanation about contents of the mentioned
39 configuration files, consult <filename>systemd-link(5)</filename>,
40 <filename>systemd-netdev(5)</filename> and
41 <filename>systemd-network(5)</filename> manual pages.</para>
42
43 <note><para>Udev may assign network card interface names based
44 on system physical characteristics such as enp2s1. If you are
45 not sure what your interface name is, you can always run
46 <command>ip link</command> after you have booted your system.
47 </para></note>
48
49 <sect3 id="systemd-networkd-static">
50 <title>Static IP Configuration</title>
51
52 <para>The command below creates a basic configuration file for
53 Static IP setup:</para>
54
55<screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-static-eth0.network &lt;&lt; "EOF"
56<literal>[Match]
57Name=eth0
58
59[Network]
60Address=192.168.0.2/24
61Gateway=192.168.0.1
62DNS=192.168.0.1</literal>
63EOF</userinput></screen>
64
65 <para>More than one DNS entry can be specified in the configuration file.</para>
66
67 </sect3>
68
69 <sect3 id="systemd-networkd-dhcp">
70 <title>DHCP Configuration</title>
71
72 <para>The command below creates a basic configuration file for
73 DHCP setup:</para>
74
75<screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-dhcp-eth0.network &lt;&lt; "EOF"
76<literal>[Match]
77Name=eth0
78
79[Network]
80DHCP=yes</literal>
81EOF</userinput></screen>
82
83 <para>Note that <command>systemd-networkd</command> can only handle
84 DHCPv4. DHCPv6 support is a work in progress.</para>
85
86 </sect3>
87
88 </sect2>
89
90 <sect2 id="resolv.conf">
91 <title>Creating the /etc/resolv.conf File</title>
92
93 <indexterm zone="resolv.conf">
94 <primary sortas="e-/etc/resolv.conf">/etc/resolv.conf</primary>
95 </indexterm>
96
97 <para>If the system is going to be connected to the Internet, it will
98 need some means of Domain Name Service (DNS) name resolution to
99 resolve Internet domain names to IP addresses, and vice versa. This is
100 best achieved by placing the IP address of the DNS server, available
101 from the ISP or network administrator, into
102 <filename>/etc/resolv.conf</filename>.</para>
103
104 <para>If static <filename>/etc/resolv.conf</filename> is desired, create
105 it by running the following command:</para>
106
107<screen role="nodump"><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
108<literal># Begin /etc/resolv.conf
109
110domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
111nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
112nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
113
114# End /etc/resolv.conf</literal>
115EOF</userinput></screen>
116
117 <para>The <varname>domain</varname> statement can be omitted
118 or replaced with a <varname>search</varname> statement. See the man page for
119 resolv.conf for more details.</para>
120
121 <para>Replace <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
122 with the IP address of the DNS most appropriate for the setup. There will
123 often be more than one entry (requirements demand secondary servers for
124 fallback capability). If you only need or want one DNS server, remove the
125 second <emphasis>nameserver</emphasis> line from the file. The IP address
126 may also be a router on the local network.</para>
127
128 <note><para>The Google Public IPv4 DNS addresses are 8.8.8.8 and 8.8.4.4.</para></note>
129
130 <para>When using <command>systemd-networkd</command> for network
131 configuration, another daemon, <command>systemd-resolved</command>,
132 is responsible for creating the <filename>/etc/resolv.conf</filename>
133 file. It is, however, placed in a non-standard location which is
134 writable since early boot, so it is necessary to create a symlink
135 to it by running the following command:</para>
136
137<screen><userinput>ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf</userinput></screen>
138
139 <para>This is required if you are specifying DNS entries in <filename
140 class="extension">.network</filename> files or using the built in
141 DHCP client to obtain DNS addresses.</para>
142
143 </sect2>
144
145 <sect2 id="ch-scripts-hostname">
146 <title>Configuring the system hostname</title>
147
148 <indexterm zone="ch-scripts-hostname">
149 <primary sortas="d-hostname">hostname</primary>
150 <secondary>configuring</secondary>
151 </indexterm>
152
153 <para>During the boot process, the file <filename>/etc/hostname</filename>
154 is used for establishing the system's hostname.</para>
155
156 <para>Create the <filename>/etc/hostname</filename> file and enter a
157 hostname by running:</para>
158
159<screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
160
161 <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
162 name given to the computer. Do not enter the Fully Qualified Domain Name
163 (FQDN) here. That information is put in the
164 <filename>/etc/hosts</filename> file.</para>
165
166 </sect2>
167
168 <sect2 id="ch-scripts-hosts">
169 <title>Customizing the /etc/hosts File</title>
170
171 <indexterm zone="ch-scripts-hosts">
172 <primary sortas="e-/etc/hosts">/etc/hosts</primary>
173 </indexterm>
174
175 <indexterm zone="ch-scripts-hosts">
176 <primary sortas="d-localnet">localnet</primary>
177 <secondary>/etc/hosts</secondary>
178 </indexterm>
179
180 <indexterm zone="ch-scripts-hosts">
181 <primary sortas="d-network">network</primary>
182 <secondary>/etc/hosts</secondary>
183 </indexterm>
184
185 <para>Decide on the IP address, fully-qualified domain name (FQDN), and
186 possible aliases for use in the <filename>/etc/hosts</filename> file. The
187 syntax is:</para>
188
189<screen><literal>IP_address myhost.example.org aliases</literal></screen>
190
191 <para>Unless the computer is to be visible to the Internet (i.e., there is
192 a registered domain and a valid block of assigned IP addresses&mdash;most
193 users do not have this), make sure that the IP address is in the private
194 network IP address range. Valid ranges are:</para>
195
196<screen><literal>Private Network Address Range Normal Prefix
19710.0.0.1 - 10.255.255.254 8
198172.x.0.1 - 172.x.255.254 16
199192.168.y.1 - 192.168.y.254 24</literal></screen>
200
201 <para>x can be any number in the range 16-31. y can be any number in the
202 range 0-255.</para>
203
204 <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
205 this IP could be lfs.example.org.</para>
206
207 <para>Even if not using a network card, a valid FQDN is still required.
208 This is necessary for certain programs to operate correctly.</para>
209
210 <para>Create the <filename>/etc/hosts</filename> file by running:</para>
211
212<screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
213<literal># Begin /etc/hosts (network card version)
214
215127.0.0.1 localhost
216::1 localhost
217<replaceable>&lt;192.168.0.2&gt;</replaceable> <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
218
219# End /etc/hosts (network card version)</literal>
220EOF</userinput></screen>
221
222 <para>The <replaceable>&lt;192.168.0.2&gt;</replaceable> and
223 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> values need to be
224 changed for specific uses or requirements (if assigned an IP address by a
225 network/system administrator and the machine will be connected to an
226 existing network). The optional alias name(s) can be omitted.</para>
227
228 <para>If a network card is not going to be configured, create the
229 <filename>/etc/hosts</filename> file by running:</para>
230
231<screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
232<literal># Begin /etc/hosts (no network card version)
233
234127.0.0.1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost
235::1 localhost
236
237# End /etc/hosts (no network card version)</literal>
238EOF</userinput></screen>
239
240 <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents the IPv6 loopback interface.</para>
241
242 </sect2>
243
244</sect1>
Note: See TracBrowser for help on using the repository browser.