Changing DNS nameservers by shell script

Non release banter
hope
Black ninja
Black ninja
Posts: 64
Joined: 04 Jul 2020, 12:07
Distribution: porteus 5.0rc1 KDE desktop

Changing DNS nameservers by shell script

Post#1 by hope » 13 Aug 2022, 21:11

I am using Porteus v5.0 in always fresh mode. Today I tried to change DNS nameservers by shell script. I did this :

Code: Select all

sudo -s<<NW
echo "nameserver 208.67.222.222" >>/etc/resolv.conf
echo nameserver 208.67.220.220" >>/etc/resolv.conf
nmcli networking off
nmcli networking on
NW
I checked whether DSN nameserver changed or not by :

Code: Select all

sudo nmcli
command as @Blaze's suggested.
The thing I noticed that, when I restart the networking service, DNS nameserver file resetted, in other words changes deleted.
But, when I did @Blaze's suggested ( in the link https://askubuntu.com/questions/2321/wh ... the-dns-ip by using GUI of network manager and changed DNS name servers) then, after "off & on" of "networking" service worked and changed DNS settings.

Therefore, I could not find a pure shell script solution to change DNS nameservers yet :unknown: . If anybody know, please share with us :sos:
Newbie to Linux-Unix systems, try to read,learn, apply, modify and create.

itrukrakso
Black ninja
Black ninja
Posts: 62
Joined: 23 Jul 2022, 07:42
Distribution: Porteus 5.01_x86_64 Xfce

Changing DNS nameservers by shell script

Post#2 by itrukrakso » 17 Aug 2022, 22:04

Hi,
Even if the topic has already been discussed in chat, here would be my suggestion.
Why do you want to edit DNS name servers by using a shell script?
The entries of resolv.conf are generated by NetworkManager at startup.

Code: Select all

root@azer:head -n 1 /etc/resolv.conf
# Generated by NetworkManager

root@azer:nmcli conn show
NAME                UUID                                  TYPE      DEVICE
xyz              ...................................      wifi      wlan0
insert nameserver

Code: Select all

root@azer:nmcli conn modify "xyz" ipv4.dns  "208.67.222.222 208.67.220.220"
root@azer:nmcli networking off && nmcli networking on

copy the corresponding file /etc/NetworkManager/system-connections/xyz.nmconnection into the filesystem at boot time.
maybe it helps ?

hope
Black ninja
Black ninja
Posts: 64
Joined: 04 Jul 2020, 12:07
Distribution: porteus 5.0rc1 KDE desktop

Changing DNS nameservers by shell script

Post#3 by hope » 21 Aug 2022, 17:18

Thanks @itrukrakso, of course it helps. I will try it and write the solution here :)
I try to do it by script because I am using Porteus from USB in always fresh mode ;)
Newbie to Linux-Unix systems, try to read,learn, apply, modify and create.

Post Reply