# Configuring an Ethernet connection with a static IP address by using nmstatectl with an interface name

<div class="center top initialized" id="bkmrk-copy-link" style="--_floating-content-translate: -22.46668243408203px -73px;"><div id="bkmrk-"><div aria-hidden="true" class=" ui " id="bkmrk--1"></div></div><div class=" dark " id="bkmrk-copy-link-1" role="status"><div class="section-link tooltip-content" slot="content"></div></div></div>
You can use the declarative Nmstate API to configure an Ethernet connection with static IP addresses, gateways, and DNS settings, and assign them to a specified interface name. Nmstate ensures that the result matches the configuration file or rolls back the changes.

**Prerequisites**

<div class="itemizedlist" id="bkmrk-a-physical-or-virtua">- A physical or virtual Ethernet Network Interface Controller (NIC) exists in the server’s configuration.
- The `nmstate` package is installed.

</div>**Procedure**

<div class="orderedlist" id="bkmrk-create-a-yaml-file%2C-">1. Create a YAML file, for example `~/create-ethernet-profile.yml`, with the following content:
    
    <div class="content-code-block-container"><div class="expandable truncated" style="column-gap: 50px;"><div tabindex="0"><div aria-hidden="true" id="bkmrk--3"></div></div></div></div>```yaml
    ---
    interfaces:
    - name: enp1s0
      type: ethernet
      state: up
      ipv4:
        enabled: true
        address:
        - ip: 192.0.2.1
          prefix-length: 24
        dhcp: false
      ipv6:
        enabled: true
        address:
        - ip: 2001:db8:1::1
          prefix-length: 64
        autoconf: false
        dhcp: false
    routes:
      config:
      - destination: 0.0.0.0/0
        next-hop-address: 192.0.2.254
        next-hop-interface: enp1s0
      - destination: ::/0
        next-hop-address: 2001:db8:1::fffe
        next-hop-interface: enp1s0
    dns-resolver:
      config:
        search:
        - example.com
        server:
        - 192.0.2.200
        - 2001:db8:1::ffbb
    ```
    
    <div class="content-code-block-container"><div class="expandable truncated" id="bkmrk--4" style="column-gap: 50px;"><div id="bkmrk--5" tabindex="0"></div><div id="bkmrk--6"></div></div><div class="content-code-block-container-actions"><div class=" center " id="bkmrk--7"><div id="bkmrk--8"></div></div></div></div>These settings define an Ethernet connection profile for the `enp1s0` device with the following settings:
    
    <div class="itemizedlist">
    - A static IPv4 address - `192.0.2.1` with the `/24` subnet mask
    - A static IPv6 address - `2001:db8:1::1` with the `/64` subnet mask
    - An IPv4 default gateway - `192.0.2.254`
    - An IPv6 default gateway - `2001:db8:1::fffe`
    - An IPv4 DNS server - `192.0.2.200`
    - An IPv6 DNS server - `2001:db8:1::ffbb`
    - A DNS search domain - `example.com`
    
    </div>
2. Optional: You can define the `identifier: mac-address` and `mac-address: <span class="emphasis"><em><mac_address></em></span>` properties in the `interfaces` property to identify the network interface card by its MAC address instead of its name, for example:
    
    <div class="content-code-block-container"><div class="expandable truncated" style="column-gap: 50px;"><div tabindex="0"><div aria-hidden="true" id="bkmrk--9"></div></div></div></div>```yaml
    ---
    interfaces:
    - name: <em><profile_name></em>
      type: ethernet
      <strong>identifier: mac-address</strong>
      <strong>mac-address: <em><mac_address></em></strong>
      ...
    ```
    
    <div class="content-code-block-container"><div class="expandable truncated" id="bkmrk--10" style="column-gap: 50px;"><div id="bkmrk--11" tabindex="0"></div><div id="bkmrk--12"></div></div><div class="content-code-block-container-actions"><div class=" center " id="bkmrk--13"><div id="bkmrk--14"></div></div></div></div>
3. Apply the settings to the system:
    
    <div class="content-code-block-container"><div class="  " style="column-gap: 50px;"><div tabindex="0"><div aria-hidden="true" id="bkmrk--15"></div></div></div></div>```plaintext
    # <strong>nmstatectl apply ~/create-ethernet-profile.yml</strong>
    ```
    
    <div class="content-code-block-container"><div class="  " id="bkmrk--16" style="column-gap: 50px;"><div id="bkmrk--17" tabindex="0"></div><div id="bkmrk--18"></div></div><div class="content-code-block-container-actions"><div class=" center " id="bkmrk--19"><div id="bkmrk--20"></div></div></div></div>

</div>**Verification**

<div class="orderedlist" id="bkmrk-display-the-current-">1. Display the current state in YAML format:
    
    <div class="content-code-block-container"><div class="  " style="column-gap: 50px;"><div tabindex="0"><div aria-hidden="true" id="bkmrk--21"></div></div></div></div>```plaintext
    # <strong>nmstatectl show enp1s0</strong>
    ```
    
    <div class="content-code-block-container"><div class="  " id="bkmrk--22" style="column-gap: 50px;"><div id="bkmrk--23" tabindex="0"></div><div id="bkmrk--24"></div></div><div class="content-code-block-container-actions"><div class=" center " id="bkmrk--25"><div id="bkmrk--26"></div></div></div></div>
2. Display the IP settings of the NIC:
    
    <div class="content-code-block-container" data-wrap-available="true"><div class="expandable truncated" style="column-gap: 50px;"><div tabindex="0"><div aria-hidden="true" id="bkmrk--27"></div></div></div></div>```plaintext
    # <strong>ip address show enp1s0</strong>
    2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
        link/ether 52:54:00:17:b8:b6 brd ff:ff:ff:ff:ff:ff
        inet 192.0.2.1/24 brd 192.0.2.255 scope global noprefixroute enp1s0
           valid_lft forever preferred_lft forever
        inet6 2001:db8:1::fffe/64 scope global noprefixroute
           valid_lft forever preferred_lft forever
    ```
    
    <div class="content-code-block-container" data-wrap-available="true"><div class="expandable truncated" id="bkmrk--28" style="column-gap: 50px;"><div id="bkmrk--29" tabindex="0"></div><div id="bkmrk--30"></div></div><div class="content-code-block-container-actions"><div class=" center " id="bkmrk--31"><div id="bkmrk--32"></div></div><div class=" center " id="bkmrk--33"><div id="bkmrk--34"></div></div></div></div>
3. Display the IPv4 default gateway:
    
    <div class="content-code-block-container"><div class="  " style="column-gap: 50px;"><div tabindex="0"><div aria-hidden="true" id="bkmrk--35"></div></div></div></div>```plaintext
    # <strong>ip route show default</strong>
    default via 192.0.2.254 dev enp1s0 proto static metric 102
    ```
    
    <div class="content-code-block-container"><div class="  " id="bkmrk--36" style="column-gap: 50px;"><div id="bkmrk--37" tabindex="0"></div><div id="bkmrk--38"></div></div><div class="content-code-block-container-actions"><div class=" center " id="bkmrk--39"><div id="bkmrk--40"></div></div></div></div>
4. Display the IPv6 default gateway:
    
    <div class="content-code-block-container"><div class="  " style="column-gap: 50px;"><div tabindex="0"><div aria-hidden="true" id="bkmrk--41"></div></div></div></div>```plaintext
    # <strong>ip -6 route show default</strong>
    default via 2001:db8:1::fffe dev enp1s0 proto static metric 102 pref medium
    ```
    
    <div class="content-code-block-container"><div class="  " id="bkmrk--42" style="column-gap: 50px;"><div id="bkmrk--43" tabindex="0"></div><div id="bkmrk--44"></div></div><div class="content-code-block-container-actions"><div class=" center " id="bkmrk--45"><div id="bkmrk--46"></div></div></div></div>
5. Display the DNS settings:
    
    <div class="content-code-block-container"><div class="expandable truncated" style="column-gap: 50px;"><div tabindex="0"><div aria-hidden="true" id="bkmrk--47"></div></div></div></div>```plaintext
    # <strong>cat /etc/resolv.conf</strong>
    search example.com
    nameserver 192.0.2.200
    nameserver 2001:db8:1::ffbb
    ```
    
    <div class="content-code-block-container"><div class="expandable truncated" id="bkmrk--48" style="column-gap: 50px;"><div id="bkmrk--49" tabindex="0"></div><div id="bkmrk--50"></div></div><div class="content-code-block-container-actions"><div class=" center " id="bkmrk--51"><div id="bkmrk--52"></div></div></div></div>If multiple connection profiles are active at the same time, the order of `nameserver` entries depend on the DNS priority values in these profiles and the connection types.
6. Use the `ping` utility to verify that this host can send packets to other hosts:
    
    <div class="content-code-block-container"><div class="  " style="column-gap: 50px;"><div tabindex="0"><div aria-hidden="true" id="bkmrk--53"></div></div></div></div>```plaintext
    # <strong>ping <em><host-name-or-IP-address></em></strong>
    ```
    
    <div class="content-code-block-container"><div class="  " id="bkmrk--54" style="column-gap: 50px;"><div id="bkmrk--55" tabindex="0"></div><div id="bkmrk--56"></div></div></div>

</div>