开发者

Programmatically set DNS nameserver on Linux

开发者 https://www.devze.com 2023-02-10 23:12 出处:网络
I\'d like to be able to add IP addresses for DNS nameservers on Linux from my C/C++ program.I\'m on a somewhat embedded platform with a read-only /etc/resolv.conf.This means I开发者_JAVA百科 can\'t si

I'd like to be able to add IP addresses for DNS nameservers on Linux from my C/C++ program. I'm on a somewhat embedded platform with a read-only /etc/resolv.conf. This means I开发者_JAVA百科 can't simply add a "nameserver xxx.xxx.xxx.xxx" line to the file without a little trickery. Are there any clean ways to do this from code?

I could try symlinking /etc/resolv.conf to a file in tmpfs, but that seems hackish and it feels like something I should be able to do without writing to a file.


Have a look at nsaddr_list in resolv.conf from your libc.

This question says:

Although not documented, the common way to set the resolver used is to update _res.nsaddr_list.

In uClibc 0.9.31 specifically there is a comment on line 533 in resolv.c describing how this works.

0

精彩评论

暂无评论...
验证码 换一张
取 消