gpt4 book ai didi

linux - ifupdown 更改参数 dhclient

转载 作者:行者123 更新时间:2023-12-04 19:05:10 29 4
gpt4 key购买 nike

我有 Ubuntu 20.04,我将所有网络功能都交给了 ifupdown。
我的接口(interface)的 1 个通过 dhclient 获取网络参数:

#/etc/network/interfaces
allow-hotplug enp2s0
auto enp2s0
iface enp2s0 inet dhcp
Dhclient 以这样的参数开始:
#ps -Af | grep dhclient

/sbin/dhclient -1 -4 -v -i -pf /run/dhclient.enp2s0.pid -lf /var/lib/dhcp/dhclient.enp2s0.leases -I -df /var/lib/dhcp/dhclient6.enp2s0.leases enp2s0
客户端版本:
# dhclient --version
isc-dhclient-4.4.1
客户端配置:
# cat /etc/dhcp/dhclient.conf 
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;

timeout 60;
retry 60;
reboot 10;
reject 10.100.0.2;
厌倦了谷歌如何更改 dhclient 启动的参数(我想在没有 -1 和守护程序模式的情况下启动它),如下所示:
/sbin/dhclient -nw -4 -v -pf /run/dhclient.enp2s0.pid -lf /var/lib/dhcp/dhclient.enp2s0.leases -I -df /var/lib/dhcp/dhclient6.enp2s0.leases enp2s0
我该怎么做?
谢谢!

最佳答案

dhclient 运行参数在 ifupdown 中硬编码,您无法从其他地方更改它。
但我找到了解决方案:

  • 将接口(interface)设置为静态以防止通过 ifup 命令
  • 启动 dhclient
  • 通过 pre-up hook
  • 使用您想要的任何参数运行 dhclient
    allow-hotplug enp2s0
    auto enp2s0
    iface enp2s0 inet static
    address 192.168.1.1
    netmask 255.255.255.255

    pre-up /sbin/dhclient -4 -v -pf /run/dhclient.enp2s0.pid -lf /var/lib/dhcp/dhclient.enp2s0.leases -I -df /var/lib/dhcp/dhclient6.enp2s0.leases enp2s0
    pre-down /sbin/dhclient -4 -v -r -pf /run/dhclient.enp2s0.pid -lf /var/lib/dhcp/dhclient.enp2s0.leases -I -df /var/lib/dhcp/dhclient6.enp2s0.leases enp2s0

    关于linux - ifupdown 更改参数 dhclient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71905785/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com