Before proceeding with the instructions for configuring DNS for an OpenVZ container, it is important to have root access and an understanding of Unix command line prompts.
Here’s a step-by-step guide on how to set this up:
1. Open your SSH client and log in as root.
1. Locate the configuration file for the VPS you wish to configure. The configuration file typically resides in the /etc/vz/conf/ directory. Each configuration file is named after the VPS ID and has a “conf” extension.
1. Open the relevant VPS config file. You can use any text editor for this, e.g., “vi” or “nano”. The following command will allow you to edit this configuration when using the “nano” text editor:
```
nano /etc/vz/conf/vpsid.conf
```
Note: Replace “vpsid” with the ID of your virtual server.
1. Look for the line which starts with `NAMESERVER=`. Remove any existing lines and add the resolvers.
```
NAMESERVER=“8.8.8.8 8.8.4.4“
```
Note: In this example, 8.8.8.8 and 8.8.4.4 are Google DNS servers. Replace these values with the DNS server IP addresses of your choice.
1. Save and exit the config file. If you are using the `nano` text editor, you can do this by pressing `CTRL + X`, then `Y` for Yes to save changes, then `ENTER` to confirm the file name.
1. Restart the VPS using the command `vzctl restart vpsid`. Replace “vpsid” with the ID of your virtual server.
1. Your VPS should now be using the new DNS servers. You can verify this by opening the “resolv.conf” file from the container.
```
vzctl exec vpsid cat /etc/resolv.conf
```
Note: Replace “vpsid” with the ID of your virtual server.
In this case, you should see the nameservers you entered in step 4.
Remember to replace “vpsid” with your service ID number. If you’re not sure what this is, you can use the “vzlist” command to see a list of currently running VPS and their IDs.
Also keep in mind that you should update the DNS settings inside the container as well, especially if you have a control panel inside it.