Changeset abadfc3


Ignore:
Timestamp:
06/29/2014 02:35:25 PM (10 years ago)
Author:
Krejzi <krejzi@…>
Branches:
7.6-systemd, 7.7-systemd, 7.8-systemd, 7.9-systemd
Children:
abfa34b
Parents:
c3ce17e
Message:

Rewrite network configuration to use systemd-networkd. Unify hostname and hosts file creation into network setup like in lfs trunk.

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

Location:
chapter07
Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • chapter07/chapter07.xml

    rc3ce17e rabadfc3  
    1515  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="network-scripts.xml"/>
    1616  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="network.xml"/>
    17   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="hosts.xml"/>
    1817  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="udev.xml"/>
    1918  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="symlinks.xml"/>
    20   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="hostname.xml"/>
    2119  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="clock.xml"/>
    2220  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="console.xml"/>
  • chapter07/network.xml

    rc3ce17e rabadfc3  
    1919
    2020  <sect2>
    21     <title>Creating Network Interface Configuration Files</title>
    22 
    23     <para>Which interfaces are brought up and down by the network script
    24     depends on the files in <filename
    25     class="directory">/etc/sysconfig/</filename>. This directory should
    26     contain a file for each interface to be configured, such as
    27     <filename>ifconfig.xyz</filename>, where <quote>xyz</quote> is
    28     required to be a Network Card Interface name (e.g. eth0).
    29     Inside this file are attributes to this interface, such as its IP
    30     address(es), subnet masks, and so forth.  It is necessary that
    31     the stem of the filename be <emphasis>ifconfig</emphasis>.</para>
    32 
    33     <note><para>Udev may assign random Network Card Interface names
    34     for some network cards such as enp2s1. If you are not sure what
    35     your Network Card Interface name is, you can always run
    36     <command>ip l</command> after you have booted your system. Again,
    37     it is important that <filename>ifconfig.xyz</filename> is named
    38     after correct Network Card Interface name (e.g.
    39     <filename>ifconfig.enp2s1</filename> or
    40     <filename>ifconfig.eth0</filename>) or Systemd will fail to bring
    41     up your network interface.</para></note>
    42 
    43     <para>The following command creates a sample file for the
    44     <emphasis>eth0</emphasis> device with a static IP address:</para>
    45 
    46 <screen><userinput>cd /etc/sysconfig/
    47 cat &gt; ifconfig.eth0 &lt;&lt; "EOF"
    48 <literal>IFACE=eth0
    49 SERVICE=ipv4-static
    50 IP=192.168.1.1
    51 GATEWAY=192.168.1.2
    52 PREFIX=24
    53 BROADCAST=192.168.1.255</literal>
    54 EOF</userinput></screen>
    55 
    56     <para>The values of these variables must be changed in every file to match
    57     the proper setup.</para>
    58 
    59     <para>The <envar>IFACE</envar> variable defines the interface name,
    60     for example, eth0. It is required for all network device configuration
    61     files.</para>
    62 
    63     <para>The <envar>SERVICE</envar> variable defines the method used for
    64     obtaining the IP address. The LFS-Network-Scripts package has a modular
    65     IP assignment format, and creating additional files in the <filename
    66     class="directory">/lib/services/</filename> directory allows other IP
    67     assignment methods. This is commonly used for Dynamic Host Configuration
    68     Protocol (DHCP), which is addressed in the BLFS book.</para>
    69 
    70     <para>The <envar>GATEWAY</envar> variable should contain the default
    71     gateway IP address, if one is present. If not, then comment out the
    72     variable entirely.</para>
    73 
    74     <para>The <envar>PREFIX</envar> variable contains the number of
    75     bits used in the subnet. Each octet in an IP address is 8 bits. If the
    76     subnet's netmask is 255.255.255.0, then it is using the first three octets
    77     (24 bits) to specify the network number. If the netmask is 255.255.255.240,
    78     it would be using the first 28 bits.  Prefixes longer than 24 bits are
    79     commonly used by DSL and cable-based Internet Service Providers (ISPs).
    80     In this example (PREFIX=24), the netmask is 255.255.255.0. Adjust the
    81     <envar>PREFIX</envar> variable according to your specific subnet.
    82     If omitted, the PREFIX defaults to 24.</para>
    83 
    84     <para>For more information see the <command>ifup</command> man page.</para>
    85 
    86   </sect2>
    87 
    88   <sect2>
    89     <title>Configuring the Network Interface Card at boot</title>
    90 
    91     <para>Enabling of the Network Interface Card configuration is
    92     done per interface. To enable Network Interface Card
    93     configuration at boot, run:</para>
    94 
    95 <screen><userinput>systemctl enable ifupdown@eth0</userinput></screen>
    96 
    97     <para>To disable previously enabled Network Interface
    98     Card configuration at boot, run:</para>
    99 
    100 <screen><userinput>systemctl disable ifupdown@eth0</userinput></screen>
    101 
    102     <para>To manually start the Network Interface Card configuration,
    103     run:</para>
    104 
    105 <screen><userinput>systemctl start ifupdown@eth0</userinput></screen>
    106 
    107     <para>Replace eth0 with the correct Network Interface Card
    108     name as described on the beginning of this page.</para>
     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>
    10987
    11088  </sect2>
     
    122100    best achieved by placing the IP address of the DNS server, available
    123101    from the ISP or network administrator, into
    124     <filename>/etc/resolv.conf</filename>. Create the file by running the
    125     following:</para>
     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>
    126115
    127116<screen><userinput>cat &gt; /etc/resolv.conf &lt;&lt; "EOF"
     
    150139  </sect2>
    151140
     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<replaceable>&lt;192.168.0.2&gt;</replaceable> <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>[alias1] [alias2] ...</replaceable>
     213
     214# End /etc/hosts (network card version)</literal>
     215EOF</userinput></screen>
     216
     217     <para>The <replaceable>&lt;192.168.0.2&gt;</replaceable> and
     218     <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> values need to be
     219     changed for specific uses or requirements (if assigned an IP address by a
     220     network/system administrator and the machine will be connected to an
     221     existing network). The optional alias name(s) can be omitted.</para>
     222   
     223     <para>If a network card is not going to be configured, create the
     224     <filename>/etc/hosts</filename> file by running:</para>
     225
     226<screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
     227<literal># Begin /etc/hosts (no network card version)
     228
     229127.0.0.1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost
     230
     231# End /etc/hosts (no network card version)</literal>
     232EOF</userinput></screen>
     233
     234   </sect2>
     235
    152236</sect1>
Note: See TracChangeset for help on using the changeset viewer.