How to get list of dns server of <network> on Linux - Documentation does not seem to cover this

I need to retrieve the DNS servers in use, from a group of Linux boxes. Looking at the documentation https://support.bigfix.com/inspectors/Networking%20Objects_Lin.html DNS property does not seem to be present.
I did find the equivalent to this for Windows platforms: “dns server of , Plural: dns servers Returns a list of DNS servers used by the local computer”. However this property is not applicable to Linux.
I guess I could come up with a code to retrieve values from “/etc/resolv.conf”, but is there a BigFix way of doing this ?

You can use BigFix relevance to retrieve the values from your file, what parts do you need to get and how do you want to use it ?

1 Like

I am writing a fixlet to update DNS settings for a group of RHEL6 servers, IEM platform version is 9.2.
The old DNS servers are XX.XX.XX.XX and XZ.XZ.XZ.XZ, and I have already wrote a bash script to update the settings to YY.YY.YY.YY and YZ.YZ.YZ.YZ, everything is working nice so far.

I would like my fixlet to become relevant (applicable) if only XX.XX.XX.XX or/and XZ.XZ.XZ.XZ are detected, so I would not have to apply this fixlet again over and over to all the clients.

A BigFix way like “concatenation “,” of (addresses of dns servers of adapters of network as string)” like for Windows would have been an elegant way of doing this.

You can do the replacement without having to use a shell script - you can do that directly through BigFix action script if you like.

But to answer your question something like this should work for applicability

Q: exists lines whose (it contains "XX.XX.XX.XX" or it contains "ZZ.ZZ.ZZ.ZZ") of file "/etc/resolv.conf"
A: True
2 Likes

@ gearoid : Thank you for your reply.
The reason I am using bash is because when my script is doing more than to only update this file, it is actually a post install script.

The problem with retrieving values form “/etc/resolv.conf” is that in some cases there are multiple entries, some of them commented out. #XX.XX.XX.XX may be already present.

/etc/resolv.conf may look like this:

search www.myDomain.org
#nameserver XX.XX.XX.XX
#nameserver XZ.XZ.XZ.XZ
nameserver YY.YY.YY.YY
nameserver YZ.YZ.YZ.YZ

or like this
search www.myDomain.org
nameserver XX.XX.XX.XX
nameserver XZ.XZ.XZ.XZ
#nameserver YY.YY.YY.YY
#nameserver YZ.YZ.YZ.YZ

So you need to exclude lines that start with # from your search ?
Is that all ?

yes, that is correct.

Something like this:
exists lines whose (it contains “XX.XX.XX.XX” or it contains “ZZ.ZZ.ZZ.ZZ” and (not starts with “#”)) of file “/etc/resolv.conf”

Q: exists lines whose ((it contains "XX.XX.XX.XX" or it contains "ZZ.ZZ.ZZ.ZZ") and character 0 of it != "#") of file "/etc/resolv.conf"
A: True
3 Likes

Thank you @gearoid !
Much appreciated.

1 Like

Hi! I am facing the same scenario almost. However I would like to use bigifx to change the DNS servers in resolve.conf. Any tips on how to proceed?

Thanks in advance

lines starting with “nameserver” eliminates the “#”

Q: (lines starting with “nameserver” of file “/etc/resolv.conf”)
A: nameserver%09xx.xx.xx.xxx
A: nameserver%09xx.xx.xx.xxx
A: nameserver%09xx.xx.xx.xxx
T: 744

vs

Q: (lines containing “nameserver” of file “/etc/resolv.conf”)
A: #nameserver%09xx.xx.xx.xxx
A: nameserver%09xx.xx.xx.xxx
A: nameserver%09xx.xx.xx.xxx
A: nameserver%09xx.xx.xx.xxx
A: ##nameserver%09xx.xx.xx.xxx

Eventually it gets to this.

Q: if (exists file “/etc/resolv.conf”) then if exists (lines starting with “nameserver” of file “/etc/resolv.conf”) then (following texts of firsts “nameserver” of lines starting with “nameserver” of file “/etc/resolv.conf”) as trimmed string else (“nameserver not found in /etc/resolv.conf”) else ("/etc/resolv.conf not found")
A: 101.69.101.253
A: 101.69.111.254
A: 101.69.111.11

hello,

/etc/resolv.conf file conains nameserver entries. You can add new nameserver entries and get list of nameservers from this file