WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [SOLVED] about file /etc/hosts  (Read 14135 times)

Offline ndrancs

  • Newbie
  • *
  • Posts: 34
  • I Love Linux
[SOLVED] about file /etc/hosts
« on: May 11, 2012, 10:33:56 PM »
Hi all,

What has changed the file /etc/hosts after booting?

i am edited file /etc/hosts but this file revert to default after boot.

this my /opt/.filetool.lst

Code: [Select]
opt
home
etc/shadow
usr/bin/tce-fetch.sh
usr/bin/tce-load
usr/local/etc/cups/cupsd.conf
usr/local/etc/cups/ppd
usr/local/etc/cups/printers.conf
etc/hosts
/etc/resolv.conf
/etc/wvdial.conf

and this onboot.lst
Code: [Select]
fltk-1.10.tcz
wbar.tcz
flwm_topside.tcz
wget.tcz
htop.tcz
mc.tcz
nano.tcz
Xorg-7.5-3d.tcz
Xorg-7.5.tcz
Xprogs.tcz
Xlibs.tcz
Xorg-fonts.tcz
tar.tcz
xfe.tcz
OSS.tcz
ossxmix.tcz
axel.tcz
cups.tcz
gutenprint.tcz
ghostscript.tcz
ghostscript_common.tcz
wifi.tcz
firmware-iwlwifi.tcz
wvdial.tcz
usb-modeswitch-data.tcz
bmpanel-themes.tcz
openbox.tcz
cpufreqd.tcz
ntpclient.tcz

Thanks.
« Last Edit: May 12, 2012, 01:48:46 AM by ndrancs »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11504
Re: about file /etc/hosts
« Reply #1 on: May 11, 2012, 11:34:04 PM »
Hi ndrancs
Your backup is probably not completing because you have an error in your .filetool.lst::
Quote
/etc/resolv.conf
/etc/wvdial.conf
should be:
Quote
etc/resolv.conf
etc/wvdial.conf

Offline ndrancs

  • Newbie
  • *
  • Posts: 34
  • I Love Linux
Re: about file /etc/hosts
« Reply #2 on: May 12, 2012, 12:16:32 AM »
Hi Rich
Thanks for reply.
I've changed the contents .filetool.lst accordance with what you say but the file /etc/hosts still come back to the default.

here is the content of /etc/hosts  after boot:
Code: [Select]
127.0.0.1 box localhost

# The following lines are desirable for IPv6 capable hosts
# (added automatically by netbase upgrade)

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts


if i use the commands in the following bootlocal.sh like this, then there is a permissions problem. permission denied:

bootlocal.sh:
Code: [Select]
#!/bin/sh
# put other system startup commands here
/usr/local/etc/init.d/dbus start
/usr/local/etc/init.d/cups start
/usr/local/etc/init.d/cpufreqd start
/bin/cat /home/tc/hosts >> /etc/hosts


Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11504
Re: about file /etc/hosts
« Reply #3 on: May 12, 2012, 12:42:32 AM »
Hi ndrancs
If you try to run bootlocal from the command line, that's normal. If you get permission denied when
it runs during the boot process, then maybe your hosts file has the wrong permissions set.
Check it with   ls -l /etc/hosts

Offline ndrancs

  • Newbie
  • *
  • Posts: 34
  • I Love Linux
Re: about file /etc/hosts
« Reply #4 on: May 12, 2012, 01:44:37 AM »
Hi Rich
Thanks for reply
The following are the results of the ls command.
Code: [Select]
tc@box:~$ ls -l /etc/hosts
-rw-r--r--    1 root     staff          274 May 12 10:55 /etc/hosts
then I think it's better to change permissions when booting, right? like this:
bootlocal.sh:
Code: [Select]
#!/bin/sh
# put other system startup commands here
/usr/local/etc/init.d/dbus start
/usr/local/etc/init.d/cups start
/usr/local/etc/init.d/cpufreqd start
/bin/chmod 0775 /etc/hosts
/bin/cat /home/tc/hosts >> /etc/hosts
and delete etc/hosts from /opt/.filetool.lst too.

once again thanks a lot Rich.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11504
Re: [SOLVED] about file /etc/hosts
« Reply #5 on: May 12, 2012, 12:58:52 PM »
Hi ndrancs
The permissions were set correctly, but the owners should be root root, not root staff, though I don't
think that should cause a problem. Since bootlocal runs as root and restore is executed after hosts
is created, backing up a modified hosts file should work. Try this:
Code: [Select]
Remove  /bin/chmod 0775 /etc/hosts  and  /bin/cat /home/tc/hosts >> /etc/hosts  from bootlocal
Enter  sudo /bin/cat /home/tc/hosts >> /etc/hosts  at the command line
Do a backup, reboot, and see if the hosts file remembers its changes

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11504
Re: [SOLVED] about file /etc/hosts
« Reply #6 on: May 12, 2012, 01:17:39 PM »
Hi ndrancs
Based on what I read here:
http://forum.tinycorelinux.net/index.php/topic,11426.msg60236.html#msg60236
Entering  sudo /bin/cat /home/tc/hosts >> /etc/hosts  at the command line might still fail, if it does, try:
Code: [Select]
sudo sh -c "/bin/cat /home/tc/hosts >> /etc/hosts"

Offline ndrancs

  • Newbie
  • *
  • Posts: 34
  • I Love Linux
Re: [SOLVED] about file /etc/hosts
« Reply #7 on: May 13, 2012, 03:40:29 AM »
Hi Rich
I try this:
Code: [Select]
Remove  /bin/chmod 0775 /etc/hosts  and  /bin/cat /home/tc/hosts >> /etc/hosts  from bootlocal
Enter  sudo sh -c "/bin/cat /home/tc/hosts >> /etc/hosts"
Do a backup, reboot, and see if the hosts file remembers its changes
after reboot file hosts remain same as default.
I do not understand what is actually changing the contents /etc/hosts to its original state and to set this permission and group root staff.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11504
Re: [SOLVED] about file /etc/hosts
« Reply #8 on: May 13, 2012, 09:55:58 AM »
Hi ndrancs
At this point I do not understand it either. While following the instructions, did you get any error messages?
I see you are also backing up some  .conf  files, presumably because you made some modifications
to them. Are they being being restored with their changes intact? On a side note, why are you backing
up  usr/bin/tce-fetch.sh  and  usr/bin/tce-load?
« Last Edit: May 13, 2012, 03:59:35 PM by Rich »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11504
Re: [SOLVED] about file /etc/hosts
« Reply #9 on: May 13, 2012, 04:02:18 PM »
Hi ndrancs
Are you by any chance booting from a USB drive? If so, did you remember to add the boot code
waitusb=10?

Offline ndrancs

  • Newbie
  • *
  • Posts: 34
  • I Love Linux
Re: [SOLVED] about file /etc/hosts
« Reply #10 on: May 21, 2012, 12:01:52 AM »
Hi Rich
I do not get any error messages. for conf file. yes I make changes to them. and yes they are properly restored. exception hosts file.
I also changed the contents of usr/bin/tce-fetch.sh  and  usr/bin/tce-load, but since the upgrade from 4.5.1 to 4.5.2 I have removed this line from filetool.
yes true i boot with usb. and have added waitusb=10 to the kernel parameter line. with grub4dos as bootloader.

did you notice this line:
Code: [Select]
127.0.0.1 box localhost

# The following lines are desirable for IPv6 capable hosts
# (added automatically by netbase upgrade) <--- this line, what does that mean?

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

« Last Edit: May 21, 2012, 07:04:34 AM by ndrancs »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11504
Re: [SOLVED] about file /etc/hosts
« Reply #11 on: May 21, 2012, 12:15:54 AM »
Hi ndrancs
Those lines are created by  /usr/bin/sethostname. As it turns out, that script removes  /etc/hosts  and creates it from
scratch. That script is called from  /opt/bootsync.sh.

Offline ndrancs

  • Newbie
  • *
  • Posts: 34
  • I Love Linux
Re: [SOLVED] about file /etc/hosts
« Reply #12 on: May 21, 2012, 07:15:19 AM »
Hi Rich
Thanks for reply  :D
I've checked this /usr/bin/sethostname, so how do you think?
whether just remove the line that calls the /usr/bin/sethostname? like this?
Code: [Select]
#!/bin/sh
# put other system startup commands here, the boot process will wait until they complete.
# Use bootlocal.sh for system startup commands that can run in the background
# and therefore not slow down the boot process.
# /usr/bin/sethostname box
/opt/bootlocal.sh &
or how do you recommend?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11504
Re: [SOLVED] about file /etc/hosts
« Reply #13 on: May 21, 2012, 08:38:15 AM »
Hi ndrancs
I would leave the call to  /usr/bin/sethostname  right where it is since it also sets up the  /etc/hostname  file.
Set up a copy of hosts the way you want it under /opt. Then:
Code: [Select]
sudo chmod 644 /opt/hosts
sudo chown root:root /opt/hosts
Add this line after the call to  /usr/bin/sethostname :
Code: [Select]
cp -fp /opt/hosts /etc/hostsI would also add a comment in the hosts file indicating that it comes from  /opt/hosts  upon startup.
Backup, reboot, and verify that /etc/hosts contains the desired entries.

Offline ndrancs

  • Newbie
  • *
  • Posts: 34
  • I Love Linux
Re: [SOLVED] about file /etc/hosts
« Reply #14 on: May 22, 2012, 10:16:10 PM »
Hi Rich
Thanks for reply.
I follow the way you describe, and finally I managed without any error message. I verify the hosts file is as desired.
Thank you so much Rich.

Topic solved.  ;)