/etc/dhcpcd.conf
文件中静态选项的有效值是什么(以及它们的用途) ?
我正在通过编辑文件来配置 Raspberry(运行 raspbianstretch)的网络接口/etc/dhcpcd.conf
。
尽管我能够正确设置它,但我很好奇通过该文件提供的所有配置选项,特别是静态配置。
我阅读了 dhcpcd.conf 的手册页,但没有找到静态选项接受的值的任何解释。我在谷歌上也找不到任何东西。
这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
答案1
我也有同样的疑问,但也没有找到任何明确的答案,所以我开始深入研究。
我不知道这是否是一个详尽的列表,但这里是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
正如我所说,我对最后一点有点不确定,因为我不想花大量的时间来浏览源代码。因此,任何更正都将非常受欢迎。