在我的机器上,我有多个接口,通常有一个 dhcp 服务器正在运行。我现在想对各种“设置”做出不同的反应:
- 有wifi时,使用wifi
- 当有以太网时,使用以太网(我那里也有一个额外的配置文件)
- 当两者都有时,使用其中之一(或两者,或其他......只是工作)
- 当接口
usb0
或usb1
发生时,只有在有人发出问题时才启用 dhcpdhcpcd <interface>
我目前的dhcpcd.conf
样子
# See dhcpcd.conf(5) for details.
# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel
# Inform the DHCP server of our hostname for DDNS.
hostname
# Use the hardware address of the interface for the Client ID.
#clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
duid
# 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
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu
# A ServerID is required by RFC2131.
require dhcp_server_identifier
# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private
interface eth0
arping 192.168.1.77
profile 192.168.1.77
static ip_address=192.168.1.65
static routers=192.168.1.77
static domain_name_servers=192.168.1.77
interface usb0
nogateway
interface usb1
nogateway
wifi/以太网部分似乎可以工作,尽管我还没有彻底测试过。但我不知道如何将我的 USB 接口设置为仅响应 DHCP 命令。它nogateway
只是为了防止 USB 接口搞砸我的 ATM 默认路由。
我需要如何配置dhcpcd
?
编辑1:
我使用的是 Gentoo 系统,除了我的网络之外,没有更多的网络配置wpa_supplicant.conf
答案1
考虑使用allowinterfaces
和/或denyinterfaces
设置/etc/dhcpcd.conf
.从man dhcpcd.conf
allowinterfaces pattern
When discovering interfaces, the interface name must match
pattern which is a space or comma separated list of patterns
passed to fnmatch(3). If the same interface is matched in
denyinterfaces then it is still denied.
denyinterfaces pattern
When discovering interfaces, the interface name must not match
pattern which is a space or comma separated list of patterns
passed to fnmatch(3).
也有可能,尽管 IMO 在生产中不太理想,但使用 dhcpcd 的 args, [-Z, --denyinterfaces pattern]
, [-z, --allowinterfaces pattern]
。