New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
How to set custom dns server within OpenVZ container (Ubuntu 14.04)?
I am using wable and their system automatically reverts the nameservers to 8.8.8.8 on system restart. Changing it in /etc/resolv.conf will work for sometime, but it doesn't persist ofc. Tried following these suggestions here:
http://unix.stackexchange.com/questions/128220/how-do-i-set-my-dns-on-ubuntu-14-04
But the network config within an ovz container seem to be drastically different.. Anyone have any experience with this?
Comments
Open /etc/rc.local and add these lines to the end:
If you use more DNS server just add another "echo "nameserver ip3" >> /etc/resolv.conf" line. On every boot/reboot the system will change the DNS servers to the one you specified in rc.local and they should stay so all the time.
I have a few OpenVZ and DNS servers never changed magically by themselves ones changed once I changed them manually. Only on reboot/boot. And the solution above will change them on reboot/boot to the one you want.
You can just set chattr +i on /etc/resolv.conf after you set your DNS.
Umm, what does that actually do? Sry, kind of a linux noob...
@smallet The command "chattr +i" sets a immutable file attribute for /etc/resolv.conf. That means that "a file with the i attribute cannot be modified. It cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. When set, prevents, even the superuser, from erasing or changing the contents of the file."
Oh, nice. But does feel kind of hacky. Had to do:
apt-get install e2fsprogs
before I could use the command though. So I just use chattr -i to remove the 'lock' right?Thanks for the help. I saw the same suggestion in stackexchange, but didn't understand how that would help me. Didn't know what an immutable flag was.
@smallet Yes, chattr syntax is a bit like the chmod syntax. + adds the attribute and - removes it. The tool needs e2fsprogs in order to set all the advanced and additional filesystem attributes.
If you don't really want to use that way you can try my solution. The system will simply override the changes made by OpenVZ when you reboot your VPS, back to the DNS servers you want. No need to install anything or use any other software.
Networking is controlled by the host node, you can kludge it with /etc/rc.local or you could ask the provider to vzctl set CTID --nameserver x.x.x.x --nameserver x.x.x.x --save
Doesn't that only work on filesystems mounted with extended attributes? Debian and Ubuntu both discourage the usage of extended attributes and will not have them on by default. As it will never be fully supported under Debian I would be careful using them.
You could use something like dnsmasq as a local caching DNS server. You could then override the system DNS servers at will.
I personally use SaltStack to maintain a consistent state (RamNode changes the hostname automatically).
Yeah, I needed this for using dnsmasq (Though installing it doesn't make it the system default dns resolver). I am gonna go with /etc/rc.local solution then.
It appears that user_xattr is actually one of the default mount options on any ext4 file system in Debian:
The reason it's set to immutable on my VPS'es is due to the DNSCrypt autoinstall script, which also contains the same command that @Kupol mentioned.
When did they do that? I do remember them defaulting to disabled because of the inconsistent compatibility of the userland tools.