By default, your Clear Linux* OS system automatically gets an IP address from your network via DHCP. If you do not have a DHCP server on your network or simply want to use a static IP address, follow the steps in this guide.

Identify which program is managing the interface

New installations of Clear Linux OS use NetworkManager as the default network interface manager for all network connections.

Note

  • The cloud Clear Linux OS images continue to use systemd-networkd to manage network connections.
  • In earlier Clear Linux OS versions, systemd-network was used to manage Ethernet interfaces and NetworkManager was used for wireless interfaces.

Before defining a configuration for assigning a static IP address, you should verify which program is managing the network interface.

  1. Check the output of nmcli device to see if NetworkManager is managing the device.

    nmcli device status
    

    If the STATE column for the device shows connected or disconnected, the network configuration is being managed by NetworkManager and the instructions for using NetworkManager should be used.

    If the STATE column for the device shows unmanaged, check to see if the device is being managed by systemd-networkd

  2. Check the output of networkctl list to see if systemd-networkd is managing the device.

    networkctl list
    

    If the SETUP column for the device shows configured, the network configuration is being managed by systemd-networkd and the instructions for using systemd-networkd should be used.

Using NetworkManager

Network connections managed by NetworkManager are stored as files with the .nmconnection file extension in the /etc/NetworkManager/system-connections/ directory.

A few tools exists to aid to manipulate network connections managed by NetworkManager:

  • nmcli - a command-line tool
  • nmtui - a text user interface that provides a pseudo graphical menu in the terminal
  • nm-connection-editor - a graphical user interface

The method below uses the command line tool nmcli to modify network connection.

  1. Identify the existing connection name:

    nmcli connection show
    

    The output will look like this:

    NAME                UUID                                  TYPE            DEVICE
    Wired connection 1  00000000-0000-0000-0000-000000000000  802-3-etherneten01
    

    If a connection does not exist, it will need to be created with nmcli connection add.

  2. Modify the connection to use a static IP address. Replace the variables in brackets with the appropriate values. [CONNECTION_NAME] should be replaced with the NAME from the command above.

    sudo nmcli connection modify "[CONNECTION_NAME]" \
    ipv4.method "manual" \
    ipv4.addresses "[IP_ADDRESS]/[CIDR_NETMASK]" \
    ipv4.gateway "[GATEWAY_IP_ADDRESS]" \
    ipv4.dns "[PRIMARY_DNS_IP],[SECONDARY_DNS_IP]"
    

    See the nmcli developer page for more configuration options. For advanced configurations, the /etc/NetworkManager/system-connections/*.nmconnection. can be edited directly.

  3. Restart the NetworkManager server to reload the DNS servers:

    sudo systemctl restart NetworkManager
    
  4. Verify your static IP address details have been set:

    nmcli
    

Using systemd-networkd

Network connections managed by systemd-networkd are stored as files with the .network file extension the /etc/systemd/network/ directory.

Files to manipulate network connections managed by systemd-networkd must be created manually.

  1. Create the /etc/systemd/network directory if it doesn’t exist already:

    sudo mkdir -p /etc/systemd/network
    
  2. Create a .network file and add the following content. Replace the variables in brackets with the appropriate values. [INTERFACE_NAME] should be replaced with LINK from the output of networkctl list ran previously.

    sudo $EDITOR /etc/systemd/network/70-static.network
    
    [Match]
    Name=[INTERFACE_NAME]
    
    [Network]
    Address=[IP_ADDRESS]/[CIDR_NETMASK]
    Gateway=[GATEWAY_IP_ADDRESS]
    DNS=[PRIMARY_DNS_IP]
    DNS=[SECONDARY_DNS_IP]
    

    See the systemd-network man page for more configuration options.

  3. Restart the systemd-networkd service:

    sudo systemctl restart systemd-networkd
    
  4. Verify your static IP address details have been set:

    networkctl status