source: chapter07/network.xml@ abfa34b

7.6-systemd 7.7-systemd 7.8-systemd 7.9-systemd
Last change on this file since abfa34b was abfa34b, checked in by Krejzi <krejzi@…>, 10 years ago

Add IPv6 loopback interface to /etc/hosts.

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

  • Property mode set to 100644
File size: 9.2 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 <command>systemd-link(5)</command>,
40 <command>systemd-netdev(5)</command> and
41 <command>systemd-network(5)</command> 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>When using <command>systemd-networkd</command> for network
105 configuration, another daemon, <command>systemd-resolved</command>,
106 is responsible for creating the <filename>/etc/resolv.conf</filename>
107 file. It is, however, placed in a non-standard location which is
108 writable since early boot, so it is necessary to create a symlink
109 to it by running the following command:</para>
110
111<screen><userinput>ln -sfv /run/systemd/resolve/resolv.conf /etc/resolv.conf</userinput></screen>
112
113 <para>If static <filename>/etc/resolv.conf</filename> is desired, create
114 it by running the following command:</para>
115
116<screen><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
117<literal># Begin /etc/resolv.conf
118
119domain <replaceable>&lt;Your Domain Name&gt;</replaceable>
120nameserver <replaceable>&lt;IP address of your primary nameserver&gt;</replaceable>
121nameserver <replaceable>&lt;IP address of your secondary nameserver&gt;</replaceable>
122
123# End /etc/resolv.conf</literal>
124EOF</userinput></screen>
125
126 <para>The <varname>domain</varname> statement can be omitted
127 or replaced with a <varname>search</varname> statement. See the man page for
128 resolv.conf for more details.</para>
129
130 <para>Replace <replaceable>&lt;IP address of the nameserver&gt;</replaceable>
131 with the IP address of the DNS most appropriate for the setup. There will
132 often be more than one entry (requirements demand secondary servers for
133 fallback capability). If you only need or want one DNS server, remove the
134 second <emphasis>nameserver</emphasis> line from the file. The IP address
135 may also be a router on the local network.</para>
136
137 <note><para>The Google Public IPv4 DNS addresses are 8.8.8.8 and 8.8.4.4.</para></note>
138
139 </sect2>
140
141 <sect2 id="ch-scripts-hostname">
142 <title>Configuring the system hostname</title>
143
144 <indexterm zone="ch-scripts-hostname">
145 <primary sortas="d-hostname">hostname</primary>
146 <secondary>configuring</secondary>
147 </indexterm>
148
149 <para>During the boot process, the file <filename>/etc/hostname</filename>
150 is used for establishing the system's hostname.</para>
151
152 <para>Create the <filename>/etc/hostname</filename> file and enter a
153 hostname by running:</para>
154
155<screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
156
157 <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
158 name given to the computer. Do not enter the Fully Qualified Domain Name
159 (FQDN) here. That information is put in the
160 <filename>/etc/hosts</filename> file.</para>
161
162 </sect2>
163
164 <sect2 id="ch-scripts-hosts">
165 <title>Customizing the /etc/hosts File</title>
166
167 <indexterm zone="ch-scripts-hosts">
168 <primary sortas="e-/etc/hosts">/etc/hosts</primary>
169 </indexterm>
170
171 <indexterm zone="ch-scripts-hosts">
172 <primary sortas="d-localnet">localnet</primary>
173 <secondary>/etc/hosts</secondary>
174 </indexterm>
175
176 <indexterm zone="ch-scripts-hosts">
177 <primary sortas="d-network">network</primary>
178 <secondary>/etc/hosts</secondary>
179 </indexterm>
180
181 <para>Decide on the IP address, fully-qualified domain name (FQDN), and
182 possible aliases for use in the <filename>/etc/hosts</filename> file. The
183 syntax is:</para>
184
185<screen><literal>IP_address myhost.example.org aliases</literal></screen>
186
187 <para>Unless the computer is to be visible to the Internet (i.e., there is
188 a registered domain and a valid block of assigned IP addresses&mdash;most
189 users do not have this), make sure that the IP address is in the private
190 network IP address range. Valid ranges are:</para>
191
192<screen><literal>Private Network Address Range Normal Prefix
19310.0.0.1 - 10.255.255.254 8
194172.x.0.1 - 172.x.255.254 16
195192.168.y.1 - 192.168.y.254 24</literal></screen>
196
197 <para>x can be any number in the range 16-31. y can be any number in the
198 range 0-255.</para>
199
200 <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
201 this IP could be lfs.example.org.</para>
202
203 <para>Even if not using a network card, a valid FQDN is still required.
204 This is necessary for certain programs to operate correctly.</para>
205
206 <para>Create the <filename>/etc/hosts</filename> file by running:</para>
207
208<screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
209<literal># Begin /etc/hosts (network card version)
210
211127.0.0.1 localhost
212::1 localhost
213<replaceable>&lt;192.168.0.2&gt;</replaceable> <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
214
215# End /etc/hosts (network card version)</literal>
216EOF</userinput></screen>
217
218 <para>The <replaceable>&lt;192.168.0.2&gt;</replaceable> and
219 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> values need to be
220 changed for specific uses or requirements (if assigned an IP address by a
221 network/system administrator and the machine will be connected to an
222 existing network). The optional alias name(s) can be omitted.</para>
223
224 <para>If a network card is not going to be configured, create the
225 <filename>/etc/hosts</filename> file by running:</para>
226
227<screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
228<literal># Begin /etc/hosts (no network card version)
229
230127.0.0.1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost
231::1 localhost
232
233# End /etc/hosts (no network card version)</literal>
234EOF</userinput></screen>
235
236 <para>The ::1 entry is the IPv6 counterpart of 127.0.0.1 and represents the IPv6 loopback interface.</para>
237
238 </sect2>
239
240</sect1>
Note: See TracBrowser for help on using the repository browser.