≡ Menu

HowTo: Edit The /etc/resolv.conf File in CentOS Linux

How do I edit /etc/resolv.conf file in CentOS Linux?

You need to use the text editor such as vi / vim or joe make changes to /etc/resolv.conf file. You must be logged in as root user in order to change this file. The /etc/resolv.conf is resolver configuration file. You can set nameserver ip address and domain search query name in this file.

Edit File Using Vi or Joe Text Editor

Type the following command:
vi /etc/resolv.conf
OR
joe /etc/resolv.conf
Edit as follows and set name server IP address:

search dnsknowledge.com
nameserver 69.9.190.5
nameserver 69.9.162.17

Save and close the file. Test new settings either with dig or host command:

dig google.com
host google.com
dig  dnsknowledge.com
{ 10 comments… add one }
  • rav October 22, 2012, 1:00 am

    Thanks it was helpful!!

  • bunga February 22, 2013, 3:35 am

    thanx a lot!

  • Rio June 16, 2013, 12:35 am

    Thanks Bro,

  • Flynn July 20, 2013, 7:31 pm

    How do you save and close?

    • Harish March 27, 2014, 7:08 am

      Open file with vi editor
      vi /etc/resolv.conf
      Press button ‘i’ for insert mode
      Make you changes
      hit ESC button to goto ESC mode
      Press shift+; in the keyboard
      Now you can see the prompt like this
      :
      Enter ‘wq’ to save your changes
      :wq
      Press Enter

  • ronald January 31, 2014, 10:42 am

    Flynn , To save and close
    follow this

    #vi /etc/resolv.conf
    PRESS INSERT on keyboar

    To save
    Press ESC on keyboard , then type
    :wq
    PRESS ENTER

  • sam September 3, 2014, 2:33 am

    tnx so much

  • tam November 22, 2014, 12:33 am

    Thanks.

    I did it.

  • Percy June 12, 2016, 5:33 pm

    Man, that took me FOREVER. Seemed to work though. Vi is definitely something I should take some more time to learn. Seems kind of powerful. Thanks again.

  • Percy June 12, 2016, 6:14 pm

    Yeah, I’m back here again. Do you think I may be having issues because in /run/resolvconf? I have a resolv.conf.swp (binary) and a resolv.conf I’d like to understand how to fix this. I’ll never give up. Thank you in advance for the help.

Seurity: Are you a robot or human?

Leave a Comment