Flatcar Container Linux ·

How to Change Networking in Flatcar

Discover how to customize your networking setup in Flatcar Linux, including connecting to machines with static IP addresses, and enabling or disabling DHCP.

How to Change Networking in Flatcar

By default, Flatcar Linux fetches the IP via DHCP from the first ethernet port it encounters. Nevertheless, there are scenarios where network configurations may need customization, such as when establishing connections with machines using static IP addresses. This guide demonstrates how to create your own networkd units for such customizations.

ℹ️
Consider using our UMH Integrated Platform for pre-configured instances to simplify your provisioning process. Contact us for further details.

Instructions

If you're not using a pre-configured instance, it's possible to modify networking settings post-installation. Here are the steps:

  1. Locate your networkd units: Networkd units are typically found in the /etc/systemd/network/ directory. If you manually place files onto the filesystem, you'll need to reload networkd using the command sudo systemctl restart systemd-networkd.
  2. Create a static.network file: This file will be used to set up a static IP on enp2s0. Create the static.network file and place it in the /etc/systemd/network/ directory.
  3. Apply the configuration: Once the file is correctly placed, apply the configuration by running the command sudo systemctl restart systemd-networkd.
💡
If you are using ignition files, and your network has no DHCP, you need to configure the linux kernel parameters as shown below.

The following YAML file provides an example configuration. This configuration fetches the IP via DHCP in the 192.168.1.0/24 range from the first port (in file 10-enp6s0.network), sets up a second network in the 172.16.42.1/24 range with a DHCP server and static leases (in file 20-enp8s0.network), and on one port, allows connection to a network consisting of a single machine at 192.168.1.150/32 (thereby creating a DMZ around that machine, file 30-enp7s0.network).

- name: 10-enp6s0.network
  contents: |
    [Match]
    Name=enp6s0

    [Network]
    Description=Port 1 / WAN
    DHCP=ipv4

    [Route]
    Destination=192.168.1.0/24
    Scope=link
    
    # for testing only
    # DHCP=ipv4

- name: 20-enp8s0.network
  contents: |
    [Match]
    Name=enp8s0

    [Network]
    Description=Port 2 / LAN. Yes it is Port 2 and not port 3. The numbering is weird in the K300.
    Address=172.16.42.1/24
    DHCPServer=true
    IPMasquerade=ipv4

    [DHCPServer]
    PoolOffset=100
    PoolSize=100
    EmitDNS=yes
    EmitNTP=yes

    # The "[DHCPServerStaticLease]" section configures a static DHCP lease to assign a fixed IPv4 address to a specific device based on its MAC address. 
    # This section can be specified multiple times.
    
    [DHCPServerStaticLease]
    MACAddress=00:30:de:40:f9:02
    Address=172.16.42.13
- name: 30-enp7s0.network
  contents: |
    [Match]
    Name=enp7s0

    [Network]
    Description=Port 3 / PLC. Yes it is Port 3 and not port 2. The numbering is weird in the K300.
    Address=192.168.1.149/30
    DHCPServer=false
    IPMasquerade=ipv4

    [Route]
    Destination=192.168.1.150/32
    Scope=link

For more detailed instructions and additional functionality of networkd, visit the official documentation. With these steps, you should be able to successfully configure your Flatcar Linux machine to use different networking. Remember to always double-check your configuration and test your connection to ensure everything is working as expected.

Static IP using Ignition & iPXE

In addition to your normal network setup, you need to change the following inside the profile sections of flatcar-0 and flatcar-1.

Inside your boot->args section add a new entry:

ip=10.0.0.10::10.0.0.1:255.255.255.0:flatcar-0:eth0:none:10.0.0.2

Where

  • 10.0.0.10 is the interface ip
  • 10.0.0.1 is the gateway ip
  • 255.255.255.0 is the netmask
  • flatcar-0 is the hostname
  • eth0 is the interface
  • none is the auto config setting (this is normally DHCP)
  • 10.0.0.2 is the primary DNS server

On boot (iPXE)

Inside the iPXE shell you need to do the following.

Read next

Share, Engage, and Contribute!

Discover how you can share your ideas, contribute to our blog, and connect with us on other platforms.