1<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-ipv4">
2 <title>IPv4 Configuration</title>
3 <para>
4 By default, NixOS uses DHCP (specifically,
5 <literal>dhcpcd</literal>) to automatically configure network
6 interfaces. However, you can configure an interface manually as
7 follows:
8 </para>
9 <programlisting language="bash">
10networking.interfaces.eth0.ipv4.addresses = [ {
11 address = "192.168.1.2";
12 prefixLength = 24;
13} ];
14</programlisting>
15 <para>
16 Typically you’ll also want to set a default gateway and set of name
17 servers:
18 </para>
19 <programlisting language="bash">
20networking.defaultGateway = "192.168.1.1";
21networking.nameservers = [ "8.8.8.8" ];
22</programlisting>
23 <note>
24 <para>
25 Statically configured interfaces are set up by the systemd service
26 <literal>interface-name-cfg.service</literal>. The default gateway
27 and name server configuration is performed by
28 <literal>network-setup.service</literal>.
29 </para>
30 </note>
31 <para>
32 The host name is set using
33 <xref linkend="opt-networking.hostName" />:
34 </para>
35 <programlisting language="bash">
36networking.hostName = "cartman";
37</programlisting>
38 <para>
39 The default host name is <literal>nixos</literal>. Set it to the
40 empty string (<literal>""</literal>) to allow the DHCP
41 server to provide the host name.
42 </para>
43</section>