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.
Instructions
If you're not using a pre-configured instance, it's possible to modify networking settings post-installation. Here are the steps:
- 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 commandsudo systemctl restart systemd-networkd
. - Create a static.network file: This file will be used to set up a static IP on
enp2s0
. Create thestatic.network
file and place it in the/etc/systemd/network/
directory. - Apply the configuration: Once the file is correctly placed, apply the configuration by running the command
sudo systemctl restart systemd-networkd
.
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.
ifstat
(Display state of network interfaces)set net0/ip 192.168.0.3
(Set ip adress of the first network adapter)set net0/netmask 255.255.255.0
(Set netmask of the first network adapter)set net0/gateway 192.168.0.1
(Set gateway of the first network adapter)ifopen net0
(Opens the first network adapter)- If your network enforced VLAN, you also need to create the tag
vcreate --tag XXX net 0
Note that linux does not support VLAN as a kernel command, therefore it might break while booting route
(Displays routing information to gateway)- If this says "inaccessible" at this state, something went wrong !