(ix) Ubuntu solves resolv.conf is rewritten problem

Source: Internet
Author: User
Tags locale

Resolve Resolv.conf overridden Issues

Source: http://www.cnblogs.com/lanxuezaipiao/p/3613497.html

In the second step, you configure DNS, but each time you restart the virtual machine or restart the network/etc/ resolv.conf file will be rewritten, that is, back to the original, your previous configuration does not exist, each time to manually configure is very undesirable, so this step is necessary, first we need to figure out the reason and mechanism of resolv.conf is rewritten, which differs in different versions of Ubuntu. How do you know that? General resolv.conf file I'll tell you at the beginning.

In fact, there are two ways to solve the problem, not afraid of trouble to understand the principle of reference method one (and version related), afraid of trouble do not want to toss the consciousness to the method of two (unrelated to the version).

Method one: Related to version

A) Ubuntu 12.10

After opening/etc/resolv.conf, you can see the beginning of the sentence:

# Generated by NetworkManager

Description resolv.conf This file is generated by the NetworkManager program (corresponding to the Network-manager service), then the solution will come: We turn off the Network-manager, the command is as follows:

sudo service Network-manager stop or Sudo/etc/init.d/network-manager stop

But this method is not once and for all, because this service is started automatically after each reboot of the system, so we need to completely prohibit Network-manager boot.

To edit the network manager's configuration file/etc/init/network-manager.conf:

sudo vi/etc/init/network-manager.conf

Comment out the start on part of it:

# Network-manager-network Connection manager## The Network Manager daemon manages the system ' s network connections,# AUT Omatically switching between the best available.description     ' network Connection Manager ' #start on ( local-filesystems# and         started dbus# and         static-network-up) stop on stopping Dbusexpect forkrespawnscript        # set $LANG So, messages appearing on the GUI would be translated. See lp:875017        if [-r/etc/default/locale];                /etc/default/locale                export LANG LANGUAGE lc_messages lc_a LL        fi

b) Ubuntu 13.04

I do not know which version of Ubuntu from the beginning is not generated by the NetworkManager resolv.conf, at least in 13.04 is the case, because the beginning of resolv.conf wrote such a sentence:

# Dynamic resolv.conf (5) file for glibc resolver (3) generated by resolvconf (8) # don't     EDIT this file by HAND--YOUR Changes'll be overwritten

Said to be generated by resolvconf, NetworkManager still exists, because it is a DHCP Internet is indispensable, but at this time prohibit NetworkManager boot is no longer used, Because resolv.conf has not returned to its tube, we try to see what resolv.conf and resolvconf have to do, see:

[Email protected]:~$ ll/etc/resolv.conflrwxrwxrwx 1 root root  : 2013/etc/resolv.conf, September.  /run/resolvconf/resolv.conf

Explain/etc/resolv.conf is actually just a link, it actually point to is /run/resolvconf/resolv.conf , this also explains why each reboot will be rewritten for the reason, you changed only a link, the original file has no effect, and each time you restart the link to load the original file content, So the change to link is invalid.

The workaround is to modify the actual original file as follows:

sudo vi/etc/resolvconf/resolv.conf.d/head

Find this file is identical to the/etc/resolv.conf file, which is right, add your own nameserver inside, so that each reboot will not be rewritten.

PS: Some people on the internet also said that the modification of /etc/resolvconf/resolv.conf.d/base this file is OK, I did not personally test, interested in the use of their own testing.

Said so much, each version of the difference seems to be very troublesome, do not know the latest version or later version will not be changed, in fact, there is a more simple version-independent way to prevent the resolv.conf file is rewritten, that is method two.

Method Two: independent of version

The above mentioned fixed IP Internet access is mainly modified/etc/network/interfacesThis file, configure IP, gateway or something, in fact, there is a parameter can be configured, that is the DNS, the corresponding parameter nameddns-nameservers, the priority set here is higher than resolv.conf, that is, the network will read the DNS configuration from here, if not configured to see the resolv.conf inside the settings, so it is easier to configure DNS here.

# interfaces (5) file used by Ifup (8) and Ifdown (8) Auto loiface lo inet loopbackauto eth0iface eth0 inet staticaddress 192. 168.1.151netmask 255.255.255.0gateway 192.168.1.2dns-nameservers 202.38.64.1

= = Restart Virtual Machine Network = =

After the configuration is complete, there are several ways to restart the network:

sudo service networking restart or sudo/etc/init.d/networking restart

You can also restart the network card:

sudo ifconfig eth0 down sudo ifconfig eth0 up

Restarting the network card has no effect on other network cards, more recommended.

Hurry to ping www.baidu.com bar, should be able to surf the Internet.

PS: Of course can also be configured through the GUI network manager, but personally feel this way best, so recommend!

(ix) Ubuntu solves resolv.conf is rewritten problem

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.