LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Running command "hostname mysite.com" at startup? (https://www.linuxquestions.org/questions/linux-newbie-8/running-command-hostname-mysite-com-at-startup-741700/)

FireRaven 07-21-2009 10:04 AM

Running command "hostname mysite.com" at startup?
 
Hi,

I want to run this command at the startup since my system keeps resetting the hostname to "ubuntu" upon startup.

I tried adding it to crontab under "@reboot hostname mysite.com" and it would not work, it would work if i set cron to "* * * * * hostname mysite.com" but that means I have wait 1 minute after machine boots plus, it keeps running every minute on a schedule which is not good practice.

Where abouts am I supposed to run this command?

colucix 07-21-2009 10:20 AM

To change the hostname permanently you have to edit the file /etc/hostname and write the new hostname then run
Code:

/etc/init.d/hostname.sh restart
then you can also edit /etc/hosts and /etc/resolv.conf to change the hostname and the domain name accordingly. If for some reason it doesn't work (in that case you have to investigate the reasons) you can try to add the command to /etc/init.d/rc.local.

FireRaven 07-21-2009 10:32 AM

It looks like it works if I do "crontab -e" and enter:

@reboot /bin/hostname mysite.com && /bin/echo "nameserver 4.2.2.2" > /etc/resolv.conf

But how can I be sure these will happen in the last order or the scripts that get run at startup?
I don't want them to be overwritten by the default "nameserver ubuntu" or whatever that gets run.

Changing it using your command doesn't save when you reboot either it looks like.

unSpawn 07-29-2009 09:41 AM

Quote:

Originally Posted by FireRaven (Post 3615249)
echo "nameserver 4.2.2.2" > /etc/resolv.conf

If the machine uses DHCP then you should probably fix that with prepend, append or supersede statements in your dhclient.conf.

onebuck 07-29-2009 10:08 AM

Hi,

I would also be careful with using 'third' level DNS. Not always there. You can always your ISP DNS then append to your file '/etc/resolv.conf' by 'echo "nameserver 4.2.2.2" >> /etc/resolv.conf';

Code:

~# echo "nameserver 4.2.2.1" >> /etc/resolv.conf
~# cat /etc/resolv.conf
search workgroup
nameserver xxx.xxx.xxx.xxx
nameserver 4.2.2.1
~#


FireRaven 07-29-2009 10:25 AM

Quote:

Originally Posted by onebuck (Post 3624273)
Hi,
I would also be careful with using 'third' level DNS. Not always there. You can always your ISP DNS then append to your file '/etc/resolv.conf' by 'echo "nameserver 4.2.2.2" >> /etc/resolv.conf';

What do you mean by 'third' level DNS?

onebuck 07-29-2009 10:47 AM

Hi,
Quote:

Originally Posted by FireRaven (Post 3624296)
What do you mean by 'third' level DNS?

The '4.2.2.2' is one of Verizon's Third level DNS;

Quote:

excerpt from 'Enter DNS';

Depending on its location in the name hierarchy, a domain may be called top-level, second-level, or third-level. More levels of subdivision occur, but are rare.

FireRaven 07-29-2009 11:58 AM

Quote:

Originally Posted by onebuck (Post 3624315)
Hi,


The '4.2.2.2' is one of Verizon's Third level DNS;

How did you hear that?
I have been using that address for DNS for a long time. Does this mean it's not recommended to use it or it's unreliable?

I do understand what top level, second level, third level mean in domain names (like zone.third.second.com) but didn't know what it means for an IP address such as 4.2.2.2

onebuck 07-29-2009 12:45 PM

Hi,

Read the links that I provided. You should be using your ISP 'DNS'.

There are several third level DNS available;

Quote:

Verizon has these;

4.2.2.1
4.2.2.2
4.2.2.3
4.2.2.4
4.2.2.5
4.2.2.6
You can look at 'Listed DNS Servers'.

The above link and others are available from 'Slackware-Links'. More than just SlackwareŽ links!


All times are GMT -5. The time now is 05:15 PM.