Ignore:
Timestamp:
04/21/2014 09:44:04 PM (10 years ago)
Author:
Bruce Dubbs <bdubbs@…>
Branches:
10.0, 10.0-rc1, 10.1, 10.1-rc1, 11.0, 11.0-rc1, 11.0-rc2, 11.0-rc3, 11.1, 11.1-rc1, 11.2, 11.2-rc1, 11.3, 11.3-rc1, 12.0, 12.0-rc1, 12.1, 12.1-rc1, 7.6, 7.7, 7.8, 7.9, 8.0, 8.1, 8.2, 8.3, 8.4, 9.0, 9.1, arm, bdubbs/gcc13, ml-11.0, multilib, renodr/libudev-from-systemd, s6-init, trunk, xry111/arm64, xry111/arm64-12.0, xry111/clfs-ng, xry111/lfs-next, xry111/loongarch, xry111/loongarch-12.0, xry111/loongarch-12.1, xry111/mips64el, xry111/pip3, xry111/rust-wip-20221008, xry111/update-glibc
Children:
5af3f9e
Parents:
c65dd23e
Message:

Rewrite and reorganize Chapter 7.
Update systemd customization.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chapter07/network.xml

    rc65dd23e rbf58c1e  
    2525  installed in <xref linkend="ch-scripts-bootscripts"/>.</para>
    2626
    27   <sect2 id='stable-net-names'>
    28     <title>Creating stable names for network interfaces</title>
    29 
    30     <para>If there is only one network interface in the system to be
    31     configured, this section is optional, although it will never be wrong to do
    32     it.  In many cases (e.g. a laptop with a wireless and a wired interface),
    33     accomplishing the configuration in this section is necessary.</para>
    34 
    35     <para>With Udev and modular network drivers, the network interface numbering
    36     is not persistent across reboots by default, because the drivers are loaded
    37     in parallel and, thus, in random order. For example, on a computer having
    38     two network cards made by Intel and Realtek, the network card manufactured
    39     by Intel may become <filename class="devicefile">eth0</filename> and the
    40     Realtek card becomes  <filename class="devicefile">eth1</filename>. In some
    41     cases, after a reboot the cards get renumbered the other way around. To
    42     avoid this, Udev comes with a script and some rules to assign stable names
    43     to network cards based on their MAC address.</para>
    44 
    45     <para>If using the traditional network interface names such as eth0 is desired,
    46     generate a custom Udev rule:</para>
    47 
    48 <screen><userinput>bash /lib/udev/init-net-rules.sh</userinput></screen>   
    49 
    50     <para> Now, inspect the
    51     <filename>/etc/udev/rules.d/70-persistent-net.rules</filename> file, to
    52     find out which name was assigned to which network device:</para>
    53 
    54 <screen role="nodump"><userinput>cat /etc/udev/rules.d/70-persistent-net.rules</userinput></screen>
    55 
    56     <note><para>In some cases such as when MAC addresess have been assigned to
    57     a network card manually or in a virtual environment such as Xen,
    58     the network rules file may not have been generated because addresses
    59     are not consistently assigned.  In these cases, just continue to
    60     the next section.</para></note>
    61 
    62     <para>The file begins with a comment block followed by two lines for each
    63     NIC. The first line for each NIC is a commented description showing its
    64     hardware IDs (e.g. its PCI vendor and device IDs, if it's a PCI card),
    65     along with its driver in parentheses, if the driver can be found. Neither
    66     the hardware ID nor the driver is used to determine which name to give an
    67     interface; this information is only for reference. The second line is the
    68     Udev rule that matches this NIC and actually assigns it a name.</para>
    69 
    70     <para>All Udev rules are made up of several keys, separated by commas and
    71     optional whitespace. This rule's keys and an explanation of each of them
    72     are as follows:</para>
    73 
    74     <itemizedlist>
    75       <listitem>
    76         <para><literal>SUBSYSTEM=="net"</literal> - This tells Udev to ignore
    77         devices that are not network cards.</para>
    78       </listitem>
    79       <listitem>
    80         <para><literal>ACTION=="add"</literal> - This tells Udev to ignore this
    81         rule for a uevent that isn't an add ("remove" and "change" uevents also
    82         happen, but don't need to rename network interfaces).</para>
    83       </listitem>
    84       <listitem>
    85         <para><literal>DRIVERS=="?*"</literal> - This exists so that Udev will
    86         ignore VLAN or bridge sub-interfaces (because these sub-interfaces do
    87         not have drivers). These sub-interfaces are skipped because the name
    88         that would be assigned would collide with their parent devices.</para>
    89       </listitem>
    90       <listitem>
    91         <para><literal>ATTR{address}</literal> - The value of this key is the
    92         NIC's MAC address.</para>
    93       </listitem>
    94       <listitem>
    95         <para><literal>ATTR{type}=="1"</literal> - This ensures the rule only
    96         matches the primary interface in the case of certain wireless drivers,
    97         which create multiple virtual interfaces. The secondary interfaces are
    98         skipped for the same reason that VLAN and bridge sub-interfaces are
    99         skipped: there would be a name collision otherwise.</para>
    100       </listitem>
    101       <listitem>
    102         <para><literal>KERNEL=="eth*"</literal> - This key was added to the
    103         Udev rule generator to handle machines that have multiple network
    104         interfaces, all with the same MAC address (the PS3 is one such
    105         machine).  If the independent interfaces have different basenames,
    106         this key will allow Udev to tell them apart.  This is generally not
    107         necessary for most Linux From Scratch users, but does not hurt.</para>
    108       </listitem>
    109       <listitem>
    110         <para><literal>NAME</literal> - The value of this key is the name that
    111         Udev will assign to this interface.</para>
    112       </listitem>
    113     </itemizedlist>
    114 
    115     <para>The value of <literal>NAME</literal> is the important part. Make sure
    116     you know which name has been assigned to each of your network cards before
    117     proceeding, and be sure to use that <literal>NAME</literal> value when
    118     creating your configuration files below.</para>
    119 
    120   </sect2>
    121 
    12227  <sect2>
    12328    <title>Creating Network Interface Configuration Files</title>
    12429
    12530    <para>Which interfaces are brought up and down by the network script
    126     depends on the files in <filename
     31    usually depends on the files in <filename
    12732    class="directory">/etc/sysconfig/</filename>.  This directory should
    12833    contain a file for each interface to be configured, such as
     
    217122    name as described on the beginning of this page.</para>
    218123
     124    <note><para>These procedures require the configuartion files as specified
     125    in the previous section.</para></note>
     126
    219127    <note><para>The network card can also be started or stopped
    220128    with the traditional <command>ifup &lt;device&gt;</command> or
    221129    <command>ifdown &lt;device&gt;</command> commands.</para></note>
     130
     131  </sect2>
     132
     133  <sect2 id="systemd2-net-enable">
     134    <title>Configuring the Network Interface Card for systemd-networkd</title>
     135
     136    <para>An alternative way to configure a NIC when booting with with
     137    systemd is to create a configuration file recognized by the
     138    systemd-networkd daemon.  To configure the device create a file similar
     139    to this:</para>
     140
     141<screen role="nodump"><userinput>cat &gt; /etc/systemd/network/10-static-eth0.network &lt;&lt; "EOF"
     142[Match]
     143Name=eth0
     144
     145[Network]
     146Address=192.168.0.2/24
     147Gateway=192.168.0.1
     148EOF</userinput></screen>
     149
     150  <para>You can use multiple .network files if desired.  You can also specify
     151  DHCP=yes instead of the Address and Gateway settings.  See the man page for
     152  systemd.network for more details,</para>
    222153
    223154  </sect2>
     
    263194  </sect2>
    264195
     196  <sect2 id="ch-scripts-hostname">
     197    <title>Configuring the system hostname</title>
     198
     199    <indexterm zone="ch-scripts-hostname">
     200      <primary sortas="d-hostname">hostname</primary>
     201      <secondary>configuring</secondary>
     202    </indexterm>
     203
     204     <para>During the boot process, both Systemd and System V use the same file
     205     for establishing the system's hostname.  This needs to be configured by
     206     creating <filename>/etc/hostname</filename>.</para>
     207
     208     <para>Create the <filename>/etc/hostname</filename> file and enter a
     209     hostname by running:</para>
     210
     211<screen><userinput>echo "<replaceable>&lt;lfs&gt;</replaceable>" &gt; /etc/hostname</userinput></screen>
     212
     213     <para><replaceable>&lt;lfs&gt;</replaceable> needs to be replaced with the
     214     name given to the computer. Do not enter the Fully Qualified Domain Name
     215     (FQDN) here. That information is put in the
     216     <filename>/etc/hosts</filename> file.</para>
     217
     218  </sect2>
     219
     220  <sect2 id="ch-scripts-hosts">
     221     <title>Customizing the /etc/hosts File</title>
     222
     223     <indexterm zone="ch-scripts-hosts">
     224       <primary sortas="e-/etc/hosts">/etc/hosts</primary>
     225     </indexterm>
     226   
     227     <indexterm zone="ch-scripts-hosts">
     228       <primary sortas="d-localnet">localnet</primary>
     229       <secondary>/etc/hosts</secondary>
     230     </indexterm>
     231   
     232     <indexterm zone="ch-scripts-hosts">
     233       <primary sortas="d-network">network</primary>
     234       <secondary>/etc/hosts</secondary>
     235     </indexterm>
     236   
     237     <para>Decide on the IP address, fully-qualified domain name (FQDN), and
     238     possible aliases for use in the <filename>/etc/hosts</filename> file. The
     239     syntax is:</para>
     240   
     241<screen><literal>IP_address myhost.example.org aliases</literal></screen>
     242
     243     <para>Unless the computer is to be visible to the Internet (i.e., there is
     244     a registered domain and a valid block of assigned IP addresses&mdash;most
     245     users do not have this), make sure that the IP address is in the private
     246     network IP address range. Valid ranges are:</para>
     247
     248<screen><literal>Private Network Address Range      Normal Prefix
     24910.0.0.1 - 10.255.255.254           8
     250172.x.0.1 - 172.x.255.254           16
     251192.168.y.1 - 192.168.y.254         24</literal></screen>
     252
     253     <para>x can be any number in the range 16-31. y can be any number in the
     254     range 0-255.</para>
     255   
     256     <para>A valid private IP address could be 192.168.1.1. A valid FQDN for
     257     this IP could be lfs.example.org.</para>
     258   
     259     <para>Even if not using a network card, a valid FQDN is still required.
     260     This is necessary for certain programs to operate correctly.</para>
     261   
     262     <para>Create the  <filename>/etc/hosts</filename> file by running:</para>
     263
     264<screen><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
     265<literal># Begin /etc/hosts (network card version)
     266
     267127.0.0.1 localhost
     268<replaceable>&lt;192.168.1.1&gt;</replaceable> <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>[alias1] [alias2 ...]</replaceable>
     269
     270# End /etc/hosts (network card version)</literal>
     271EOF</userinput></screen>
     272
     273     <para>The <replaceable>&lt;192.168.1.1&gt;</replaceable> and
     274     <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> values need to be
     275     changed for specific uses or requirements (if assigned an IP address by a
     276     network/system administrator and the machine will be connected to an
     277     existing network). The optional alias name(s) can be omitted.</para>
     278   
     279     <para>If a network card is not going to be configured, create the
     280     <filename>/etc/hosts</filename> file by running:</para>
     281
     282<screen role="nodump"><userinput>cat &gt; /etc/hosts &lt;&lt; "EOF"
     283<literal># Begin /etc/hosts (no network card version)
     284
     285127.0.0.1 <replaceable>&lt;HOSTNAME.example.org&gt;</replaceable> <replaceable>&lt;HOSTNAME&gt;</replaceable> localhost
     286
     287# End /etc/hosts (no network card version)</literal>
     288EOF</userinput></screen>
     289
     290   </sect2>
     291
    265292</sect1>
Note: See TracChangeset for help on using the changeset viewer.