Jasmin Amarea's picture

Hi everybody,

?

I just started with this, but I would like to know if the following is possible:

街拍vip第一站I wish to run a few different virtual machines, using the great Turnkey distro. So far, so good, just installed VM Virtual Box, added a template, cloned and reset the mac address. Now I have a simple website (php) that asks me for the server name, IP address, Gateway, Primary DNS and Secondary DNS. After filling out the fields, it creates a script (network.sh) for me to download and place on the server. The purpose of this script will likely not be a surprise: set the given values for the server.

街拍vip第一站Is there any way to set the DNS servers from the Command Line ONLY? I have searched over 20 different websites and each and everyone of them tell me to edit the /etc/resolv.conf file. Since I want to minimize the user interaction, this is not the desired way. If I wish to add / change the Gateway, I can do a "ip route add default" / "route add default gw".

街拍vip第一站Can I run a similar command to set the Primary DNS and / or Secondary DNS?

Thanks in advance,

街拍vip第一站Jasmin Amarea

Forum:?
Jeremy Davis's picture

街拍vip第一站Sed allows you to use regular expressions to alter the contents of text files, which can be really handy when you're trying to do what you want to do. However TBH I'm not totally up on how to use sed so it'd be the blind leading the blind (everytime I want to do that I find an example online that is close and tweak it to do what I want - I still don't really get RegEx...).

Another option if you don't mind overwriting (i.e. deleting) the existing contents is to use ">" and just echo in the DNS server you want. E.g.:

echo "nameserver 8.8.8.8" > /etc/resolv.conf

Another way would be to have a generic resolv.conf stored somewhere and use your script to copy it over the top of the existing resolv.conf

Jasmin Amarea's picture

Hi Heremy,

街拍vip第一站Thank you for you answer. I was hoping for something along the lines of "ifconfig eth0 ns1 x.y.z.a", similar to "ifconfig eth0 netmask x.y.z.a". But if this is the way to go, I will sure give it a try.

Lucky for me, I have absolutely no understanding of Regular Expressions, but I love to try my hand at "anything" once.

Thanks again,

Jasmin Amarea

Jeremy Davis's picture

But not one that I'm aware of.

Good luck
Jasmin Amarea's picture

I have been giving your sed suggestion a try somewhere else and got what I wanted there. I now use sed to uniformly add new websites (domains) to my Apache, so it sure helped.

I will look into a way to do something like it for editing the resolv.conf file also. Just adding a name server there is not all I mean to do. The new domains will be added to that file also, but only when first created.

So, thanks again, this sure has been a great help :))

Login as the root, enter:
# vi /etc/resolv.conf
OR
$ sudo vi /etc/resolv.conf
Modify or enter nameserver as follows:
nameserver 208.67.222.222
nameserver 208.67.220.220


Save and close the file. To test DNS configuration type any one of the following command:
$ host google.com
$ dig google.com
$ ping google.com
$ nslookup your-domain.com

?

also check Linux chown commnad tutorial here

Add new comment