Tuesday, 24 December 2024

Ubuntu Network, set up dns

check if system is using systemd-resolved


systemctl status systemd-resolved


change global dns

sudo nano /etc/systemd/resolved.conf

[Resolve] DNS=8.8.8.8 1.1.1.1 FallbackDNS=8.8.4.4 1.0.0.1


sudo systemctl restart systemd-resolved


// check resolve status (You have to create a seperate network file if u are not using global but a specific network interface)


resolvectl status


// Two approaches for a specific network interface


ls /etc/systemd/network/

sudo nano /etc/systemd/network/<networInterfaceId>.network


[Match] Name=enp0s3<networkinterfaceId>

 [Network] 

DNS=8.8.8.8 

DNS=1.1.1.1

sudo systemctl restart systemd-networkd * Might need to reboot machine


---------onetime solution(not recommneded)

Unlink the Current /etc/resolv.conf:


bash

Copy code

sudo unlink /etc/resolv.conf

Create a New /etc/resolv.conf File: Manually create the file with your preferred DNS servers:


bash

Copy code

sudo nano /etc/resolv.conf

Example content:


plaintext

Copy code

nameserver 8.8.8.8

nameserver 1.1.1.1

Prevent systemd-resolved from Recreating the Link: Mask the service if needed:


bash

Copy code

sudo systemctl disable --now systemd-resolved

sudo systemctl mask systemd-resolved

Verify the New Configuration: Check that the changes are applied:


bash

Copy code

cat /etc/resolv.conf


 

No comments:

Post a Comment