DHCPCD.conf IPv4/IPv6 Fallback Configuration
DHCPCD is a very popular DHCP client used in many Linux distributions. It reads its configuration from the /etc/dhcpcd.conf file. This article covers the IPv4 and IPv6 fallback configuration in the dhcpcd.conf file.
Understanding DHCPCD.conf
The /etc/dhcpcd.conf file is used to configure how the DHCP client behaves. It can be used to set static IP addresses, specify custom DNS servers, define default routes, and much more. The file uses a simple key-value pair syntax, making it easy to understand and configure.
IPv4 Fallback Configuration
In cases where a DHCP server is not available, it is useful to have a fallback configuration for the IPv4 settings. This can be done using the interface keyword followed by the name of the interface (e.g., eth0). The metric keyword can be used to set the priority of the interface, and the ipv4fallback keyword can be used to specify the fallback IPv4 settings:
interface eth0 metric 100
ipv4fallback static_ipv4_profile
The static_ipv4_profile keyword refers to a named profile that contains the static IPv4 settings. These settings can be defined using the following keywords:
static_ip_address: The static IP address of the interface, followed by the subnet mask in CIDR notationstatic_routers: The default gateway for the interfacestatic_domain_name_servers: The DNS servers for the interface
interface eth0 metric 100
ipv4fallback static_ipv4_profile
static_ipv4_profile {
static_ip_address=10.11.xxx.xxx/24
static_routers=10.11.xxx.xxx
static_domain_name_servers=8.8.8.8 1.1.1.1
}
IPv6 Fallback Configuration
Similar to IPv4, it is also possible to configure a fallback configuration for IPv6 settings in DHCPCD.conf. The following example shows how to configure a static IPv6 address and DNS servers as a fallback:
interface eth0 metric 100
ipv6fallback static_ipv6_profile
static_ipv6_profile {
static_ip_address=2602:ffe8:7::1234/64
static_domain_name_servers=2620:12a:100::1 2620:12a:100::2
}
Advanced Fallback Configuration
In some cases, it might be necessary to configure more advanced fallback settings. For example, it is possible to define multiple profiles and use them based on certain conditions. This can be done using the following syntax:
interface eth0 metric 100
ipv4fallback {
profile1 {
static_ip_address=10.11.xxx.xxx/24
static_routers=10.11.xxx.xxx
}
profile2 {
static_ip_address=192.168.xxx.xxx/24
static_routers=192.168.xxx.xxx
}
match {
rule1
rule2
}
}
In this example, the match keyword is used to define the conditions under which each profile should be used. The rule keyword can be used to define specific conditions, such as the link status, the vendor class, or the presence of a DHCP server. More information about the available rules can be found in the dhcpcd.conf manual page.
- DHCPCD is a DHCP client used in many Linux distributions
- The
/etc/dhcpcd.conffile is used to configure DHCPCD - The
ipv4fallbackkeyword can be used to specify a fallback configuration for IPv4 settings - The
ipv6fallbackkeyword can be used to specify a fallback configuration for IPv6 settings - Advanced fallback configurations can be created using multiple profiles and conditions