Systemd-networkd: Successfully Requesting IP Addresses and Routing Traffic through Gateway
Systemd-networkd is a system service that manages network configurations in Linux systems. It is responsible for bringing up network interfaces, configuring addresses, routing, and other network-related settings. This article will discuss how Systemd-networkd successfully requests IP addresses for a computer and correctly resolves FQDNs (Fully Qualified Domain Names) to IP addresses.
Requesting IP Addresses with Systemd-networkd
Systemd-networkd uses network configuration files to request IP addresses for network interfaces. These configuration files are typically located in the /etc/systemd/network directory. A sample network configuration file might look like this:
[Match]
Name=eth0
[Network]
DHCP=yes
In this example, the Match section specifies that the configuration should apply to the eth0 network interface. The Network section specifies that the interface should use DHCP (Dynamic Host Configuration Protocol) to request an IP address.
Once the network configuration file is in place, Systemd-networkd can be restarted to apply the new configuration:
# systemctl restart systemd-networkd
After restarting Systemd-networkd, the eth0 interface should have a valid IP address:
# ip addr show eth0
2: eth0: mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:28:fe:1e brd ff:ff:ff:ff:ff:ff
inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic noprefixroute eth0
valid_lft 86399sec preferred_lft 86399sec
inet6 fe80::20c:29ff:fe28:fe1e/64 scope link
valid_lft forever preferred_lft forever
Resolving FQDNs with Systemd-resolved
Systemd-resolved is a system service that provides network name resolution to Linux systems. It is responsible for resolving FQDNs (Fully Qualified Domain Names) to IP addresses. This is typically done using DNS (Domain Name System) servers.
Systemd-resolved uses network configuration files to determine which DNS servers to use. These configuration files are typically located in the /etc/systemd/resolved.conf.d directory. A sample resolved configuration file might look like this:
[Resolve]
DNS=8.8.8.8 8.8.4.4
In this example, the DNS directive specifies that Systemd-resolved should use Google's public DNS servers (8.8.8.8 and 8.8.4.4) for name resolution.
Once the resolved configuration file is in place, Systemd-resolved can be restarted to apply the new configuration:
# systemctl restart systemd-resolved
After restarting Systemd-resolved, FQDNs should be correctly resolved to IP addresses:
# dig example.com
; <<>> DiG 9.16.1-Ubuntu <<>> example.com
;; global options: +cmd
;; Got answer:
;;