Documentation

    networkd

    Manage systemd-networkd configuration files (.network, .link, .netdev).

    Attributes

    check_mode:
      support: full
    

    Parameters

    Parameter Required Type Values Description
    name true string   Name of the configuration file (without extension).
    type true string network
    link
    netdev
    Type of configuration: network, link, or netdev.
    state   string present
    absent
    Whether the configuration should exist or not. [default: "present"]
    interfaces   array   Interface names to match.
    addresses   array   IP addresses for the interface.
    gateway   string   Default gateway.
    dns   array   DNS servers.
    dhcp   boolean   Enable DHCP (ipv4, ipv6, true, false). [default: false]
    vlan_id   integer   VLAN ID (for netdev type vlan).
    netdev_kind   string bridge
    bond
    vlan
    macvlan
    ipvlan
    vxlan
    tun
    tap
    wireguard
    dummy
    Netdev kind (bridge, bond, vlan, etc.).
    mtu   integer   MTU for the link.
    backup   boolean   Create backup of existing config file.
    directory   string   Path to the systemd-networkd configuration directory. [default: "/etc/systemd/network"]
    restart   boolean   Restart systemd-networkd after changes. [default: true]
    sections   object   Additional systemd sections and directives (case-sensitive). A section is a mapping or a list of mappings for repeated sections. Directive values are scalars or lists for repeated assignments. Custom directives replace generated assignments with the same key in the first matching section. Additional section instances are appended. Use an empty string for an explicit reset. Empty lists are not supported. New section names and directive names are sorted for deterministic output; list order is preserved. Values must be single-line and cannot end in a continuation backslash. Ignored when raw config is provided.
    config   string   Raw INI content to use instead of generated config.

    Examples

    - name: Configure static IP on eth0
      networkd:
        name: 10-eth0
        type: network
        state: present
        interfaces:
          - eth0
        addresses:
          - 192.168.1.100/24
        gateway: 192.168.1.1
        dns:
          - 8.8.8.8
          - 8.8.4.4
    
    - name: Configure Ethernet with custom systemd directives
      networkd:
        name: 20-ethernet
        type: network
        interfaces:
          - ens123
        addresses:
          - 192.168.1.100/24
        gateway: 192.168.1.1
        sections:
          Match:
            Type: ether
          Link:
            RequiredForOnline: routable
          Route:
            - Destination: 10.10.0.0/16
              Gateway: 192.168.1.254
            - Destination: 10.20.0.0/16
              Gateway: 192.168.1.253
    
    - name: Configure DHCP on eth0
      networkd:
        name: 20-dhcp
        type: network
        state: present
        interfaces:
          - eth0
        dhcp: true
    
    - name: Create bridge netdev
      networkd:
        name: br0
        type: netdev
        state: present
        netdev_kind: bridge
    
    - name: Create bond netdev
      networkd:
        name: bond0
        type: netdev
        state: present
        netdev_kind: bond
    
    - name: Configure VLAN netdev
      networkd:
        name: vlan10
        type: netdev
        state: present
        netdev_kind: vlan
        vlan_id: 10
    
    - name: Configure link MTU
      networkd:
        name: 10-eth0
        type: link
        state: present
        interfaces:
          - eth0
        mtu: 9000
    
    - name: Remove network configuration
      networkd:
        name: 10-eth0
        type: network
        state: absent