≡ Menu
Home > Q & A > HowTo: Edit The /etc/resolv.conf File in CentOS Linux

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
{ 13 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?

  • 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

  • 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

  • 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.

  • yogita April 11, 2018, 9:01 am

    but with the help of vi /etc/resolv.conf not save perment data

  • Sushant October 12, 2019, 1:44 am

    I have centos 7 server on AWS its working fine and also sites are running well but my server not able to ping google.com or 8.8.8.8. May i know what i need to do for fix the issues.

    traceroute google.com
    traceroute to google.com (74.125.113.147), 30 hops max, 40 byte packets
    1 * * *
    2 * * *
    3 * * *
    4 * * *
    5 * * *
    6 * * *
    7 * * *
    8 * * *
    9 * * *
    10 * * *
    11 * * *
    12 * * *
    13 * * *
    14 * * *
    15 * * *
    16 * * *
    17 * * *
    18 * * *
    19 * * *
    20 * * *
    21 * * *
    22 * * *
    23 * * *
    24 * * *
    25 * * *
    26 * * *
    27 * * *
    28 * * *
    29 * * *
    30 * * *

  • kk10 December 6, 2019, 8:49 pm

    very good

Leave a Comment