Set Static IP and Fixed DNS Resolver in Debian Linux

The issue I found when using Virtualmin on "1&1 IONOS" Debian 11 VPS.

You have to configure the IP addresses as static. Automatic dhcp will never solve this issue.

Start configuring the network settings;

 

Webmin/Virtualmin DNS Resolver Lost After Reboot 

 
 
* First, collect your IP address, subnet mask and gateway information to apply it on a static file. Also note down the exact interface name (eth0, ens192, etc.)

Lookup the existing information first:

ifconfig

netstat -rn

1) Disable cloud-init's automatic network configuration


nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

Enter the following code in the new file

network: {config: disabled}

Save the file

2) Add or edit your IP addresses to become static setting

nano /etc/network/interfaces

After edit the information, the file will look like the following:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

#
source /etc/network/interfaces.d/*

# The loopback network interface
auto lo ens192
iface lo inet loopback

# The primary network interface
allow-hotplug ens192
iface ens192 inet static
    address xx.xx.xx.xx/32
    gateway
10.255.255.1
    up route add -net 10.255.255.1 netmask 255.255.255.255 dev ens192

#iface ens192 inet6 static
#    accept_ra 0
#    address xxxx:xxxx:xxxx:xxx::/64
#    gateway fe80::1

Replace your exact IPs in the entries. Save and exit the file.

3) Check if the DNS Config is installed and running

systemctl status resolvconf.service

4) Edit the DNS head file

nano /etc/resolvconf/resolv.conf.d/head

Then enter the DNS servers as following:

nameserver 8.8.8.8
nameserver 1.1.1.1
nameserver 2001:4860:4860::8888
nameserver 2606:4700:4700::1111

Save and exit the file

Update the file:

resolvconf --enable-updates

resolvconf -u


5) Edit the file /etc/systemd/resolved.conf and add public DNS name-servers

nano /etc/systemd/resolved.conf

Un-comment DNS line, and enter the DNS servers as the following:

DNS=8.8.8.8 1.1.1.1 2001:4860:4860::8888 2606:4700:4700::1111

Save and exit the file.

6) Edit the resolver file

nano /etc/resolv.conf

Then enter the DNS servers as following:

nameserver 8.8.8.8
nameserver 1.1.1.1
nameserver 2001:4860:4860::8888
nameserver 2606:4700:4700::1111

Save and exit the file

Enable the service on startup:

systemctl enable systemd-resolved.service

7) Restart the resolver service

systemctl restart systemd-resolved

That's all, reboot the server and enjoy !


 

Post a Comment