Linux

在 /etc/dhcpcd.conf 中配置靜態值

  • April 23, 2021

文件中靜態選項的有效值(以及它們的用途)是/etc/dhcpcd.conf什麼?

我正在通過編輯/etc/dhcpcd.conf文件來配置 Raspberry 的網路介面(執行 raspbian 拉伸)。

儘管我能夠正確設置它,但我很好奇通過此文件提供的所有配置選項,特別是靜態配置。

我閱讀了 dhcpcd.conf 的手冊頁,並沒有找到關於靜態選項接受的值的任何解釋。我在Google上也找不到任何東西。

dhcpcd.conf的手冊頁只是這樣說:

static value
        Configures a static value.  If you set ip_address then dhcpcd
        will not attempt to obtain a lease and will just use the value
        for the address with an infinite lease time.  If you set
        ip6_address, dhcpcd will continue auto-configuation as normal.

        Here is an example which configures two static address,
        overriding the default IPv4 broadcast address, an IPv4 router,
        DNS and disables IPv6 auto-configuration.  You could also use the
        inform6 command here if you wished to obtain more information via
        DHCPv6.  For IPv4, you should use the inform ipaddress option
        instead of setting a static address.
              interface eth0
              noipv6rs
              static ip_address=192.168.0.10/24
              static broadcast_address=192.168.0.63
              static ip6_address=fd51:42f8:caae:d92e::ff/64
              static routers=192.168.0.1
              static domain_name_servers=192.168.0.1
              fd51:42f8:caae:d92e::1

        Here is an example for PPP which gives the destination a default
        route.  It uses the special destination keyword to insert the
        destination address into the value.
              interface ppp0
              static ip_address=
              destination routers

在閱讀了一些教程後,我知道的所有有效選項如下:

  • IP地址
  • 路由器
  • 域名伺服器
  • 域搜尋
  • 域名

JFYI 我的 /etc/dhcpcd.conf 配置文件如下所示:

# Inform the DHCP server of our hostname for DDNS.
hostname
# Use the hardware address of the interface for the Client ID.
clientid
# Persist interface configuration when dhcpcd exits.
persistent
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit
# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# A ServerID is required by RFC2131.
require dhcp_server_identifier
# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private
# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname

# Static IP configuration for eth0.
interface eth0
   static ip_address=192.168.12.234/24
   static routers=192.168.12.1
   static domain_name_servers=192.168.12.1
   nogateway

我想知道同樣的事情,也找不到任何明確的答案,所以我去探勘了。

static我不知道這是否是一個詳盡的列表,但這是我通過查看原始碼(可在此處獲得)收集的選項的有效值列表:

ip_address
subnet_mask
broadcast_address
routes
static_routes
classless_static_routes
ms_classless_static_routes
routers
interface_mtu
mtu
ip6_address

這些參數直接在if-options.c文件中處理。

這是我不太確定它是否詳盡的地方,並且我對正在發生的事情進行了一些推測。毫無疑問,這裡不包括domain_name_servers等。在解析配置文件並直接處理上述任何一個參數後,仍然可以有一些參數沒有被處理if-options.c。我認為這些剩餘的參數在預設的鉤子腳本中處理,特別是 20-resolv.conf 鉤子腳本(/usr/lib/dhcpcd/dhcpcd-hooks),我認為只有以下選項:

domain_name
domain_name_servers
domain_search

正如我所說,我對最後一點有點不確定,因為我不想花大量時間來瀏覽原始碼。因此,任何更正都將非常受歡迎。

引用自:https://unix.stackexchange.com/questions/528331