[权威教程翻译]resolv.conf from debian wiki

本文来自debian wiki

Ordinarily, the resolv.conf(5) file is managed dynamically by various network service daemons. This is the default, and is intended for laptops and other highly mobile systems which may connect to different networks. It also works well for many desktop and server systems, so long as the network infrastructure is perfect.

For some systems, on some networks, the system administrator may wish to configure /etc/resolv.conf by hand. This leads to a conflict between the administrator’s changes, and the dynamic changes performed by the network service daemons.

If you edit resolv.conf by hand, and need to stop daemons from overwriting your changes, this page documents some of your options.

Configuring resolvconf

The resolvconf package may be installed. When it is, it includes various configuration files for other package (such as isc-dhcp-client). Specifically, resolvconf includes a file which modifies the make_resolv_conf shell function used by dhclient-script(8).

With resolvconf installed, you can tell it to do nothing whenever some daemon tries to modify resolv.conf, by putting resolvconf=NO in the /etc/resolvconf.conf file. (Note: this is not the /etc/resolv.conf file!)

Alternatively, you can use dns-nameserver entries in the appropriate stanza in /etc/network/interfaces:

iface eth0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameserver 192.168.1.254
dns-nameserver 8.8.8.8
dns-search foo.org bar.com

Configuring dhclient

The most common daemon which overwrites resolv.conf is dhclient(8) (from isc-dhcp-client). In many cases, simply stopping this one daemon from touching the file will suffice.

Stop dhclient from modifying /etc/resolv.conf

Another approach makes use of dhclient-script’s hook scripts. According to dhclient-script(8):

When it starts, the client script first defines a shell function, make_resolv_conf , which is later used to create the /etc/resolv.conf file. To override the default behaviour, redefine this function in the enter hook script. 

Therefore, we can stop dhclient from overwriting resolv.conf by doing the following:

echo ‘make_resolv_conf() { :; }’ > /etc/dhcp/dhclient-enter-hooks.d/leave_my_resolv_conf_alone
chmod 755 /etc/dhcp/dhclient-enter-hooks.d/leave_my_resolv_conf_alone

The execute bit is required because dhclient-script uses run-parts(8) to decide which files to read. For that same reason, the filename must not contain anything but letters, digits, underscores and hyphens.

Modifying /etc/dhcp/dhclient.conf

The /etc/dhcp/dhclient.conf file can be populated with directives that will override the options sent by the DHCP server. For example, these directives will override the domain, search, and nameserver parameters that are placed into /etc/resolv.conf:

supersede domain-name “example.com”;
supersede domain-search “example.com”;
supersede domain-name-servers 127.0.0.1;

Another option is to remove “domain-name, domain-name-servers, domain-search” from the request line. However, this only works on some networks, and not on others. If the DHCP server sends unsolicited domain-name-servers (et al.) responses, dhclient will still heed them, and will still overwrite the resolv.conf file.

Making /etc/resolv.conf immutable

This approach will render /etc/resolv.conf immutable so that it cannot be changed, regardless of what packages are installed or what tries to modify it.

rm -f /etc/resolv.conf
editor /etc/resolv.conf
chattr +i /etc/resolv.conf

Obviously, you will need to put the appropriate content into the file before setting the immutable bit. Any time you wish to change the file, you will have to remove the bit, make your change, and then restore the bit.

A consequence of making /etc/resolv.conf immutable is that if dhclient-script tries to change it and fails, it clutters /etc with temporary files. See 860928 for details. The user/admin may need to periodically clean these files out of /etc until #860928 is fixed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: resolv.conf.bak是一个备份文件,通常是在修改resolv.conf文件之前自动创建的。如果修改后的resolv.conf文件出现问题,可以使用resolv.conf.bak文件恢复原始设置。 ### 回答2: resolv.conf.bak是一个文件名的后缀,通常是在Linux系统中的网络配置文件resolv.conf备份文件的命名方式。resolv.conf是一个系统文件,用于指定DNS服务器的IP地址和域名解析的顺序。 在Linux系统中,当我们对网络配置进行更改时,往往会对resolv.conf文件进行编辑,以设置系统在进行域名解析时使用的DNS服务器。系统根据resolv.conf文件中的配置顺序依次查询DNS服务器,直到找到可以解析域名的DNS服务器为止。这个文件非常重要,因为它决定了系统在何处查找域名的IP地址。 然而,由于网络配置可能会发生变化,我们可能需要备份原始的resolv.conf文件,以便在出现问题时可以恢复到先前的配置。在这种情况下,我们可以使用.resolv.conf.bak作为resolv.conf文件的备份文件名。 一旦我们对resolv.conf文件进行编辑并保存,系统会自动生成.resolv.conf.bak作为备份文件。这样,即使我们在编辑resolv.conf时出现错误或配置失败,我们仍然可以恢复到先前的配置状态。 当我们需要恢复到先前的网络配置状态时,只需将.resolv.conf.bak文件更名为resolv.conf,并覆盖掉原始的resolv.conf文件即可。 总之,resolv.conf.bak是resolv.conf文件的备份文件名后缀,用于存储原始网络配置的备份,以便在需要时进行恢复。 ### 回答3: resolv.conf.bak是一个备份文件,通常用于存储resolv.conf文件的副本。resolv.conf文件是用于配置系统的DNS解析器的文件,其中包含了DNS服务器的信息。当我们在配置系统的网络设置时,会经常修改resolv.conf文件来指定DNS服务器的地址。而resolv.conf.bak文件则是保存了resolv.conf文件的上一个版本,以便在修改或删除resolv.conf文件后,可以通过恢复resolv.conf.bak文件来还原之前的配置。 resolv.conf.bak文件的存在可以帮助我们在修改resolv.conf文件时防止意外的错误。如果在修改resolv.conf文件时不小心犯了一个错误导致系统无法正常使用网络,我们可以通过将resolv.conf.bak文件重命名为resolv.conf来还原到之前的配置,以解决问题。 因此,resolv.conf.bak文件可以看作是一个系统配置文件的备份,旨在提供在系统配置修改出错时的回滚选项。当我们要对系统的DNS配置进行更改时,建议首先创建resolv.conf.bak文件,以便在需要时可以方便地还原到之前的配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值