Skip to main content
Became Hot Network Question
added 73 characters in body
Source Link

I have a program that will run a set of commands against new server installs and I need to change an entry in a file for each install. We need to change the default DNS from 127.0.0.X (which it defaults to as it installs without an internet connection) to 8.8.8.8

I was using the following command:

sudo awk '{sub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

however this doesn't appear to be working under gawk/new OS version.

sudo gawk '{gensub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

What am I doing wrong? Is there a better way to change the default DNS entry?

Current Server OS: Ubuntu 24.04.2-live-server

Previous Server OS: Ubuntu 20.04.6-live-server

EDIT:

Sample line input file:

#DNS=
#FallbackDNS=
#Domains

The command should find the first line above and replace it with DNS=8.8.8.8 however it is not. When

Desired output:

DNS=8.8.8.8
#FallbackDNS=
#Domains

When I run the awk command the file still reads:

#DNS=
#FallbackDNS=
#Domains

Additionally, it should only find and replace an exact match of #DNS=

What command and syntax will replace #DNS= with DNS=8.8.8.8?

I have a program that will run a set of commands against new server installs and I need to change an entry in a file for each install. We need to change the default DNS from 127.0.0.X (which it defaults to as it installs without an internet connection) to 8.8.8.8

I was using the following command:

sudo awk '{sub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

however this doesn't appear to be working under gawk/new OS version.

sudo gawk '{gensub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

What am I doing wrong? Is there a better way to change the default DNS entry?

Current Server OS: Ubuntu 24.04.2-live-server

Previous Server OS: Ubuntu 20.04.6-live-server

EDIT:

Sample line input file:

#DNS=
#FallbackDNS=
#Domains

The command should find the first line above and replace it with DNS=8.8.8.8 however it is not. When I run the awk command the file still reads:

#DNS=
#FallbackDNS=
#Domains

Additionally, it should only find and replace an exact match of #DNS=

What command and syntax will replace #DNS= with DNS=8.8.8.8?

I have a program that will run a set of commands against new server installs and I need to change an entry in a file for each install. We need to change the default DNS from 127.0.0.X (which it defaults to as it installs without an internet connection) to 8.8.8.8

I was using the following command:

sudo awk '{sub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

however this doesn't appear to be working under gawk/new OS version.

sudo gawk '{gensub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

What am I doing wrong? Is there a better way to change the default DNS entry?

Current Server OS: Ubuntu 24.04.2-live-server

Previous Server OS: Ubuntu 20.04.6-live-server

EDIT:

Sample line input file:

#DNS=
#FallbackDNS=
#Domains

The command should find the first line above and replace it with DNS=8.8.8.8 however it is not.

Desired output:

DNS=8.8.8.8
#FallbackDNS=
#Domains

When I run the awk command the file still reads:

#DNS=
#FallbackDNS=
#Domains

Additionally, it should only find and replace an exact match of #DNS=

What command and syntax will replace #DNS= with DNS=8.8.8.8?

formatting
Source Link
Bodo
  • 6.4k
  • 18
  • 30

I have a program that will run a set of commands against new server installs and I need to change an entry in a file for each install. We need to change the default DNS from 127.0.0.X (which it defaults to as it installs without an internet connection) to 8.8.8.8

I was using the following command:

sudo awk '{sub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

however this doesn't appear to be working under gawk/new OS version.

sudo gawk '{gensub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

What am I doing wrong? Is there a better way to change the default DNS entry?

Current Server OS: Ubuntu 24.04.2-live-server

Previous Server OS: Ubuntu 20.04.6-live-server

EDIT:

Sample line input file: #DNS= #FallbackDNS= #Domains

#DNS=
#FallbackDNS=
#Domains

The command should find the first line above and replace it with DNS=8.8.8.8DNS=8.8.8.8 however it is not. When I run the awk command the file still reads:

#DNS= #FallbackDNS= #Domains

#DNS=
#FallbackDNS=
#Domains

Additionally, it should only find and replace an exact match of #DNS=#DNS=

What command and syntax will replace #DNS=#DNS= with DNS=8.8.8.8DNS=8.8.8.8?

I have a program that will run a set of commands against new server installs and I need to change an entry in a file for each install. We need to change the default DNS from 127.0.0.X (which it defaults to as it installs without an internet connection) to 8.8.8.8

I was using the following command:

sudo awk '{sub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

however this doesn't appear to be working under gawk/new OS version.

sudo gawk '{gensub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

What am I doing wrong? Is there a better way to change the default DNS entry?

Current Server OS: Ubuntu 24.04.2-live-server

Previous Server OS: Ubuntu 20.04.6-live-server

EDIT:

Sample line input file: #DNS= #FallbackDNS= #Domains

The command should find the first line above and replace it with DNS=8.8.8.8 however it is not. When I run the awk command the file still reads:

#DNS= #FallbackDNS= #Domains

Additionally, it should only find and replace an exact match of #DNS=

What command and syntax will replace #DNS= with DNS=8.8.8.8?

I have a program that will run a set of commands against new server installs and I need to change an entry in a file for each install. We need to change the default DNS from 127.0.0.X (which it defaults to as it installs without an internet connection) to 8.8.8.8

I was using the following command:

sudo awk '{sub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

however this doesn't appear to be working under gawk/new OS version.

sudo gawk '{gensub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

What am I doing wrong? Is there a better way to change the default DNS entry?

Current Server OS: Ubuntu 24.04.2-live-server

Previous Server OS: Ubuntu 20.04.6-live-server

EDIT:

Sample line input file:

#DNS=
#FallbackDNS=
#Domains

The command should find the first line above and replace it with DNS=8.8.8.8 however it is not. When I run the awk command the file still reads:

#DNS=
#FallbackDNS=
#Domains

Additionally, it should only find and replace an exact match of #DNS=

What command and syntax will replace #DNS= with DNS=8.8.8.8?

added 1 character in body
Source Link

I have a program that will run a set of commands against new server installs and I need to change an entry in a file for each install. We need to change the default DNS from 127.0.0.X (which it defaults to as it installs without an internet connection) to 8.8.8.8

I was using the following command:

sudo awk '{sub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

however this doesn't appear to be working under gawk/new OS version.

sudo awkgawk '{gensub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

What am I doing wrong? Is there a better way to change the default DNS entry?

Current Server OS: Ubuntu 24.04.2-live-server

Previous Server OS: Ubuntu 20.04.6-live-server

EDIT:

Sample line input file: #DNS= #FallbackDNS= #Domains

The command should find the first line above and replace it with DNS=8.8.8.8 however it is not. When I run the awk command the file still reads:

#DNS= #FallbackDNS= #Domains

Additionally, it should only find and replace an exact match of #DNS=

What command and syntax will replace #DNS= with DNS=8.8.8.8?

I have a program that will run a set of commands against new server installs and I need to change an entry in a file for each install. We need to change the default DNS from 127.0.0.X (which it defaults to as it installs without an internet connection) to 8.8.8.8

I was using the following command:

sudo awk '{sub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

however this doesn't appear to be working under gawk/new OS version.

sudo awk '{gensub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

What am I doing wrong? Is there a better way to change the default DNS entry?

Current Server OS: Ubuntu 24.04.2-live-server

Previous Server OS: Ubuntu 20.04.6-live-server

EDIT:

Sample line input file: #DNS= #FallbackDNS= #Domains

The command should find the first line above and replace it with DNS=8.8.8.8 however it is not. When I run the awk command the file still reads:

#DNS= #FallbackDNS= #Domains

Additionally, it should only find and replace an exact match of #DNS=

What command and syntax will replace #DNS= with DNS=8.8.8.8?

I have a program that will run a set of commands against new server installs and I need to change an entry in a file for each install. We need to change the default DNS from 127.0.0.X (which it defaults to as it installs without an internet connection) to 8.8.8.8

I was using the following command:

sudo awk '{sub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

however this doesn't appear to be working under gawk/new OS version.

sudo gawk '{gensub(/#DNS=/,"DNS=8.8.8.8")}' /etc/systemd/resolved.conf

What am I doing wrong? Is there a better way to change the default DNS entry?

Current Server OS: Ubuntu 24.04.2-live-server

Previous Server OS: Ubuntu 20.04.6-live-server

EDIT:

Sample line input file: #DNS= #FallbackDNS= #Domains

The command should find the first line above and replace it with DNS=8.8.8.8 however it is not. When I run the awk command the file still reads:

#DNS= #FallbackDNS= #Domains

Additionally, it should only find and replace an exact match of #DNS=

What command and syntax will replace #DNS= with DNS=8.8.8.8?

deleted 3 characters in body
Source Link
Loading
added 4 characters in body
Source Link
Loading
added 393 characters in body
Source Link
Loading
Markdown
Source Link
Prabhjot Singh
  • 2.4k
  • 1
  • 6
  • 20
Loading
Source Link
Loading