• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

Stop DHCP From Changing resolv.conf

How VPS by How VPS
January 1, 2020
in Linux
0
0
SHARES
18
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Method 1: Change interface settings to static
  2. Method 2: Write protect your nameservers
  3. Method 3: Use DHCP hooks
  4. Want to contribute?


For DHCP users, there may be times when you need to edit /etc/resolv.conf to use other nameservers. Then, after a period of time (or after a system reboot), you discover that your changes to /etc/resolv.conf have been reverted.

This tutorial shows three methods to stop DHCP from changing the /etc/resolv.conf on Debian or Ubuntu.

Method 1: Change interface settings to static

  • On a cloud vps, I do not suggest using this method.
  • If you use this method, you may find that the reboot processing (until you can login through ssh) takes longer.

First, we need to get the IP/netmask/gateway of the server. Run the following command.

ifconfig | grep "inet addr" | head -n 1 | awk '{print $2, $4}'

This provides the server IP and netmask. Looking at the example output…

addr:1.2.3.4 Mask:255.255.254.0

… the server IP address is 1.2.3.4 and mask is 255.255.254.0.

To get the gateway address, run the following command.

 netstat -rn | grep '^0.0.0.0' | awk '{print $2}'

In this example, I will use the gateway address 1.2.3.1.

Now that we have the IP/netmask/gateway, edit /etc/network/interfaces.

 vim /etc/network/interfaces

Make the following edits:

# Comment out this line
# iface eth0 inet dhcp

# Add these contents
iface eth0 inet static
address 1.2.3.4
mask 255.255.254.0
gateway 1.2.3.1

Remember, you must replace these values with the appropriate IP/netmask/gateway of server.

Save and exit, then reboot.

Method 2: Write protect your nameservers

Change your nameservers by editing /etc/resolv.conf. Once you have made your edits, write protect that file.

chattr +i /etc/resolv.conf

The +i option (attribute) write protects the /etc/resolv.conf file on Linux so that no one can modify it – not even the root user.

If you need to remove the write protect attribute, use the following command.

chattr -i /etc/resolv.conf

Method 3: Use DHCP hooks

This is the method that I recommend using the most.

Edit /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate.

vim /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate

Make the following edits:

#!/bin/sh
make_resolv_conf(){
    :
}

Save and exit.

Update the permissions on the nodnsupdate file.

chmod +x /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate

Reboot your server. You can now update nameservers by editing /etc/resolv.conf without worrying about rollback.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

How to Install OpenVAS Vulnerability Scanner on Ubuntu 16.04

Next Post

Using SaltStack With Pillars on Ubuntu 17.04

Next Post

Using SaltStack With Pillars on Ubuntu 17.04

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet