Systemd: Setup a static IP Address

Hi,

an very often requested issue. I will show this on Debian Jessie

We assume we want to set a static IP Address for eth0

Create new file /etc/systemd/network/eth0.network. Name is not importend, just the prefix network.

[Match]
# You can also use wildcards. Maybe you want enable dhcp
# an all eth* NICs
Name=eth0
[Network]
#DHCP=v4
# static IP
# 192.168.100.2 netmask 255.255.255.0
Address=192.168.100.2/24
Gateway=192.168.100.1
DNS=192.168.100.1

Move your previously used /etc/network/interfaces to /etc/network/interfaces.save. The file is no longer needed (for eth0). If some other NICs defined there leave it and just remove all entries regarding to eth0.

root@debdeb:~# mv /etc/network/interfaces /etc/network/interfaces.save

and enable systemd-networkd unit

root@debdeb:~# systemctl enable systemd-networkd.service

Define DNS Server. You can add the DNS Server either in the Network section of the NIC adapter config (see above) or in /etc/systemd/resolved.conf
Create a symlink

root@debdeb:~# mv /etc/resolv.conf /etc/resolv.conf.save
root@debdeb:~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

and enable systemd resolver

root@debdeb:~# systemctl enable systemd-resolved.service

Michael

Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.