Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794
{"id":2945,"date":"2019-12-27T07:39:11","date_gmt":"2019-12-27T07:39:11","guid":{"rendered":"https:\/\/support.aklwebhost.com\/?post_type=manual_kb&p=2945"},"modified":"2019-12-27T07:39:17","modified_gmt":"2019-12-27T07:39:17","slug":"stop-dhcp-from-changing-resolv-conf","status":"publish","type":"manual_kb","link":"https:\/\/support.aklwebhost.com\/knowledgebase\/stop-dhcp-from-changing-resolv-conf\/","title":{"rendered":"Stop DHCP From Changing resolv.conf"},"content":{"rendered":"

For DHCP users, there may be times when you need to edit\u00a0\/etc\/resolv.conf<\/code>\u00a0to use other nameservers. Then, after a period of time (or after a system reboot), you discover that your changes to\u00a0\/etc\/resolv.conf<\/code>\u00a0have been reverted.<\/p>\n

This tutorial shows three methods to stop DHCP from changing the\u00a0\/etc\/resolv.conf<\/code>\u00a0on Debian or Ubuntu.<\/p>\n

Method 1: Change interface settings to static<\/h3>\n
    \n
  • On a cloud vps, I do not suggest using this method.<\/li>\n
  • If you use this method, you may find that the reboot processing (until you can login through ssh) takes longer.<\/li>\n<\/ul>\n

    First, we need to get the\u00a0IP\/netmask\/gateway<\/strong>\u00a0of the server. Run the following command.<\/p>\n

    ifconfig | grep \"inet addr\" | head -n 1 | awk '{print $2, $4}'\r\n<\/code><\/pre>\n

    This provides the server IP and netmask. Looking at the example output…<\/p>\n

    addr:1.2.3.4 Mask:255.255.254.0\r\n<\/code><\/pre>\n

    … the server IP address is\u00a01.2.3.4<\/strong>\u00a0and mask is\u00a0255.255.254.0<\/strong>.<\/p>\n

    To get the gateway address, run the following command.<\/p>\n

     netstat -rn | grep '^0.0.0.0' | awk '{print $2}'\r\n<\/code><\/pre>\n

    In this example, I will use the gateway address\u00a01.2.3.1<\/strong>.<\/p>\n

    Now that we have the\u00a0IP\/netmask\/gateway<\/strong>, edit\u00a0\/etc\/network\/interfaces<\/code>.<\/p>\n

     vim \/etc\/network\/interfaces\r\n<\/code><\/pre>\n

    Make the following edits:<\/p>\n

    # Comment out this line\r\n# iface eth0 inet dhcp\r\n\r\n# Add these contents\r\niface eth0 inet static\r\naddress 1.2.3.4\r\nmask 255.255.254.0\r\ngateway 1.2.3.1\r\n<\/code><\/pre>\n

    Remember, you must replace these values with the appropriate\u00a0IP\/netmask\/gateway<\/strong>\u00a0of server.<\/p>\n

    Save and exit, then reboot.<\/p>\n

    Method 2: Write protect your nameservers<\/h3>\n

    Change your nameservers by editing\u00a0\/etc\/resolv.conf<\/code>. Once you have made your edits, write protect that file.<\/p>\n

    chattr +i \/etc\/resolv.conf\r\n<\/code><\/pre>\n

    The\u00a0+i<\/code>\u00a0option (attribute) write protects the\u00a0\/etc\/resolv.conf<\/code>\u00a0file on Linux so that no one can modify it – not even the root user.<\/p>\n

    If you need to remove the write protect attribute, use the following command.<\/p>\n

    chattr -i \/etc\/resolv.conf\r\n<\/code><\/pre>\n

    Method 3: Use DHCP hooks<\/h3>\n

    This is the method that I recommend using the most.<\/p>\n

    Edit\u00a0\/etc\/dhcp\/dhclient-enter-hooks.d\/nodnsupdate<\/code>.<\/p>\n

    vim \/etc\/dhcp\/dhclient-enter-hooks.d\/nodnsupdate\r\n<\/code><\/pre>\n

    Make the following edits:<\/p>\n

    #!\/bin\/sh\r\nmake_resolv_conf(){\r\n    :\r\n}\r\n<\/code><\/pre>\n

    Save and exit.<\/p>\n

    Update the permissions on the\u00a0nodnsupdate<\/code>\u00a0file.<\/p>\n

    chmod +x \/etc\/dhcp\/dhclient-enter-hooks.d\/nodnsupdate\r\n<\/code><\/pre>\n

    Reboot your server. You can now update nameservers by editing\u00a0\/etc\/resolv.conf<\/code>\u00a0without worrying about rollback.<\/p>\n

    \n
    \n

    Want to contribute ?<\/h2>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","manualknowledgebasecat":[242,244],"manual_kb_tag":[469],"_links":{"self":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2945"}],"collection":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/comments?post=2945"}],"version-history":[{"count":1,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2945\/revisions"}],"predecessor-version":[{"id":2946,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2945\/revisions\/2946"}],"wp:attachment":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/media?parent=2945"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manualknowledgebasecat?post=2945"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb_tag?post=2945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}