Avoid/etc/resolv. conf rewriting in FreeBSD/Linux + comparison of several solutions!

Source: Internet
Author: User

Recently, I encountered another issue where/etc/resolv. conf will be rewritten on a regular basis. This is in FreeBSD!

In the LAN via NAT or PPPoE environment on the Internet, we have to specify the DNS server in resolv. conf, And the DNS server here is
Automatically obtained through the DHCP server. If not, manually add the DNS server provided by the ISP. But sometimes some "smart" Processes
The sequence will always jump out and make some small actions, change the settings we write ourselves, and round-robin. You can change it again, and it will be changed in a few minutes.

I have encountered some problems before (the DNS server is incorrect and will be changed !) :

  1. When Ubuntu 6.10 (Edgy) is dialing through ppp, only the IP address of the DHCP server of the ADSL Modem is caught.
  2. The hateful network-manager program of Ubuntu 7.04 (Feisty) regularly captures the IP address of the ADSL Modem DHCP server.
  3. When the Guest OS in VMWare obtains an IP address from a NAT network, only the IP address of the NAT DHCP server is caught.

As a result, many people jumped out and asked a question: "How to Avoid resolv. conf being modified, rewritten, and overwritten? "

However, for a flexible system like * NIX, there are also many solutions. One by one, we can see which one is rough and which one is elegant!

Solution 1: Modify/sbin/dhclient-script and comment out the operations on resolv. conf.

Linux:

Comment out all calls to the make_resolv_conf function!

FreeBSD:

Comment out the rows where> resolv. conf is located!

Solution 2: Force modify the flag of the resolv. conf file to make it unchangeable.

Linux:

Chattr + I/etc/resolv. conf

FreeBSD:

Chflags schg/etc/resolv. conf

Solution 3: change the configuration file of the DHCP Client and append our settings at specific links.

Linux (Ubuntu Dist .):

Add the following settings to/etc/dhcp3/dhclient. conf: prepend domain-name-servers <ip1>, <ip2>;

FreeBSD:

Add the following settings to/etc/dhclient. conf: prepend domain-name-servers <ip1>, <ip2>;

In my opinion, solution 1 is rough, solution 2 is violent, and solution 3 is a good solution!

Solution 3 does not change the system framework or the original execution process. We only add prepend content in the default prepend step to let the DHCP Client
After obtaining the DNS server information, append the required configurations to the front.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.