Dhcpcd
From Gentoo Wiki
Outdated translations are marked like this.
Dynamic Host Configuration Protocol Client Daemon (net-misc/dhcpcd)是一个能够处理 IPv4 和 IPv6 配置的流行 DHCP 客户端。
安装
USE 标记
USE flags for net-misc/dhcpcd A fully featured, yet light weight RFC2131 compliant DHCP client
+embedded
|
Embed the definitions of dhcp options in the dhcpcd executable |
+udev
|
Enable virtual/udev integration (device discovery, power and storage device support, etc) |
debug
|
Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces |
ipv6
|
Add support for IP version 6 |
privsep
|
Enable support for privilege separation |
verify-sig
|
Verify upstream signatures on distfiles |
Emerge
使用以下命令安装dhcpcd:
root #emerge --ask net-misc/dhcpcd配置
文件
所有 dhcpcd 配置都可以在 /etc/dhcpcd.conf 文件中设置,但如今大多数计算机都通过路由或运行 DHCP 服务的接入点连接网络,因此 dhcpcd 在大多数安装中可以开箱即用。如果需要高级配置,man 5 dhcpcd.conf[1] 将会有所帮助。
静态IP地址
文件
/etc/dhcpcd.confstatic ip_address=192.168.0.10/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
Static values for domain/search in resolv.conf
文件
/etc/dhcpcd.confstatic domain_name=mynetwork
static domain_search=mynetwork
附注
The resolv.conf(5) man page notes that "[t]he domain directive is an obsolete name for the search directive that handles one search list entry only."
The resolv.conf(5) man page notes that "[t]he domain directive is an obsolete name for the search directive that handles one search list entry only."
IPv6 Prefix Request
文件
/etc/dhcpcd.confRequest a prefix for eth0.lan and eth0.management to be routed publicly with eth0.wan.# Disable router solicitations for all interfaces, enable only for selected ones
noipv6rs
# Interface configuration for the wan vlan on the eth0 interface
interface eth0.wan
# Enable router solicitation for this interface
ipv6rs
# Request a normal address using iaid 1 for interface eth0.wan
ia_na 1
# Request a prefix using iaid 2 and assign it to the eth0.lan interface using sla_id 0 and prefix size of 64
ia_pd 2 eth0.lan/0/64
# Request a prefix using iaid 3 and assign it to the eth0.management interface using sla_id 0 and prefix size of 64
ia_pd 3 eth0.management/0/64
使用
调用
root #dhcpcd --helpusage: dhcpcd [-146ABbDdEGgHJKLMNPpqTV]
[-C, --nohook hook] [-c, --script script]
[-e, --env value] [-F, --fqdn FQDN] [-f, --config file]
[-h, --hostname hostname] [-I, --clientid clientid]
[-i, --vendorclassid vendorclassid] [-j, --logfile logfile]
[-l, --leasetime seconds] [-m, --metric metric]
[-O, --nooption option] [-o, --option option]
[-Q, --require option] [-r, --request address]
[-S, --static value]
[-s, --inform address[/cidr[/broadcast_address]]]
[--inform6] [-t, --timeout seconds] [-u, --userclass class]
[-v, --vendor code, value] [-W, --whitelist address[/cidr]] [-w]
[--waitip [4 | 6]] [-y, --reboot seconds]
[-X, --blacklist address[/cidr]] [-Z, --denyinterfaces pattern]
[-z, --allowinterfaces pattern] [--inactive] [interface] [...]
dhcpcd -n, --rebind [interface]
dhcpcd -k, --release [interface]
dhcpcd -U, --dumplease interface
dhcpcd --version
dhcpcd -x, --exit [interface]
作为一个服务运行
一次性 DHCP
dhcpd can be manually started on a specific interface, such as enp1s0 with:
root #dhcpcd eth0确保将上述命令中的 eth0 替换为适当的网络接口名称。
Renew a lease
To renew the lease on enp1s0, --rebind or -n can be used:
root #dhcpcd -n enp1s0Release a lease
To release a lease on enp1s0, --release or -k can be used:
root #dhcpcd -k enp1s0故障排除
- dhcpcd not working for IPv6 (#CONFIG_PACKET is not set)
- 如果 /etc/resolv.conf 不使用 VPN 的 DNS 更新, 请考虑安装 net-dns/openresolv.
参考
- Gentoo Handbook - Network configuration - 手册中关于处理网络接口的建议。
- Netifrc — Gentoo's default framework for configuring and managing network interfaces on systems running OpenRC.
- Network management using DHCPCD
- Complete Handbook/Configuring the system#Networking information
外部资源
参考
- ↑ 1.0 1.1 Roy Marples. DHCPCD.CONF(5), Roy Marples's personal blog, March 9th, 2015. Retrieved on May 07th, 2015.