Problems with /etc/hosts | Editing not take effect

Hi there I’m running OpenSUSE 12.3 and when I edit the /etc/hosts it does not take immediately effect?

I’ve added to hosts

192.168.0.11 mywebsite.com

did save and quit and when I ping it, it still pinging the production server?

I’m kind new to opensuse am I missing something?

Editing /etc/hosts does immediately take effect here on my system.

Have you edited it as “root”? Otherwise the changes can’t be saved because of unsufficient permissions.

Could you post your /etc/hosts?

yes I’m editing with root

special IPv6 addresses

::1 localhost ipv6-localhost ipv6-loopback
127.0.0.1 localhost
127.0.0.2 hanatux.helmi hanatux
192.168.0.11 acervoindustrial.com.br

Okay I see that is necessary to reboot the system to the changes take effect!

There is some way to reload hosts without reboot?

Hm, I replaced my /etc/hosts with exactly this and immediately after saving it was respected:

amiga:/etc # ping acervoindustrial.com.br
PING acervoindustrial.com.br (**192.168.0.11**) 56(84) bytes of data.
^C

How did you check?

now try to comment the line save and try to ping again.

Okay let me try to explain so you could replicate.

add the line save and ping it, it will take effect the first time,
then go to the file and comment the line save and ping it again you will see that will still pinging the 192.168.0.11 now if you reboot you will see that it is pinging to the production server again.
then if you go to edit the file again and comment out the line, it will take effect again and will ping to 192.168.0.11, now if you comment the line again and ping it you will see that it will still ping the 192.168.0.11 even after remove the comment.
so wierd han???

Sorry, can’t reproduce. Everything’s working as expected:

amiga:/etc # ping acervoindustria.com.br
PING acervoindustrial.com.br (192.168.0.11) 56(84) bytes of data.
^C
--- acervoindustrial.com.br ping statistics ---
6 packets transmitted, 0 received, 100% packet loss, time 4999ms


amiga:/etc # vim hosts #comment out the line with acervoindustrial.com.br
amiga:/etc # ping acervoindustrial.com.br
PING acervoindustrial.com.br (198.154.203.42) 56(84) bytes of data.
64 bytes from odg.odghost.tk (198.154.203.42): icmp_seq=1 ttl=41 time=306 ms
64 bytes from odg.odghost.tk (198.154.203.42): icmp_seq=2 ttl=41 time=319 ms
64 bytes from odg.odghost.tk (198.154.203.42): icmp_seq=3 ttl=41 time=251 ms

But this sounds like a caching issue. Do you maybe have weird values in /etc/nscd.conf? Not sure if ping uses that, though.


enable-cache            passwd          yes
        positive-time-to-live   passwd          600
        negative-time-to-live   passwd          20
        suggested-size          passwd          211
        check-files             passwd          yes
        persistent              passwd          yes
        shared                  passwd          yes
        max-db-size             passwd          33554432
        auto-propagate          passwd          yes

        enable-cache            group           yes
        positive-time-to-live   group           3600
        negative-time-to-live   group           60
        suggested-size          group           211
        check-files             group           yes
        persistent              group           yes
        shared                  group           yes
        max-db-size             group           33554432
        auto-propagate          group           yes

        enable-cache            hosts           yes
        positive-time-to-live   hosts           600
        negative-time-to-live   hosts           0
        suggested-size          hosts           211
        check-files             hosts           yes
        persistent              hosts           no
        shared                  hosts           yes
        max-db-size             hosts           33554432

        enable-cache            services        yes
        positive-time-to-live   services        28800
        negative-time-to-live   services        20
        suggested-size          services        211
        check-files             services        yes
        persistent              services        yes
        shared                  services        yes
        max-db-size             services        33554432

        enable-cache            netgroup        yes
        positive-time-to-live   netgroup        28800
        negative-time-to-live   netgroup        20
        suggested-size          netgroup        211
        check-files             netgroup        yes
        persistent              netgroup        yes
        shared                  netgroup        yes
        max-db-size             netgroup        33554432

Okay Solved

I did change the line

enable-cache            hosts           yes

to:

enable-cache            hosts           no

and did reboot the system now it’s working like a charm thanks @wolfi323

On Wed, 22 May 2013 22:36:01 +0000, FelipeMiranda wrote:

> Hi there I’m running OpenSUSE 12.3 and when I edit the /etc/hosts it
> does not take immediately effect?
>
> I’ve added to hosts
>
> 192.168.0.11 mywebsite.com
>
> did save and quit and when I ping it, it still pinging the production
> server?
>
> I’m kind new to opensuse am I missing something?

After editing the file, run:

sudo /sbin/rcnscd restart

That should take care of this.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

Hm, strange.
I have the same settings in there and don’t encounter your issue.

Anyway, great if it’s solved for you now. :wink:

On 2013-05-23 01:26, FelipeMiranda wrote:
> and did reboot the system now it’s working like a charm thanks

Simply reload the nscd service.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

  1. Normally the Hosts file is read only once during boot (or restarting the appropriate service)

  2. Don’t forget, in openSUSE you need to make Hostname changes in <two> places… not only to the Hosts file but in your YAST > Network Devices

TSU

That’s not true. See above.

  1. Don’t forget, in openSUSE you need to make Hostname changes in <two> places… not only to the Hosts file but in your YAST > Network Devices

TSU

No you don’t have to. You can make the change **either **in YaST or directly in /etc/hosts!

Agreed, and I make changes in /etc/hosts all of the time and they seem to
apply pretty-stinkin’-quickly. For example:

Code:

me@mybox0:~/Desktop> ping lalaland
ping: unknown host lalaland
2013-05-24 11:08:52 Jobs:0 Err:2

me@mybox0:~/Desktop> ping lalaland
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.024 ms
^C
— localhost ping statistics —
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.024/0.024/0.024/0.000 ms
2013-05-24 11:09:04 Jobs:0 Err:0

me@mybox0:~/Desktop> ping lalaland
ping: unknown host lalaland
2013-05-24 11:09:12 Jobs:0 Err:2

So in twenty seconds I went from not-resolving, to resolving, to
not-resolving, just by modifying /etc/hosts (no service restarts, no
logouts, didn’t even exit ‘vi’ in between writes to the file).

Good luck.

On 2013-05-24 19:11, ab wrote:
> So in twenty seconds I went from not-resolving, to resolving, to
> not-resolving, just by modifying /etc/hosts (no service restarts, no
> logouts, didn’t even exit ‘vi’ in between writes to the file).

Yes, that’s the normal behaviour.
I think I saw problems years ago with the nscd cache, long ago, not
noticing changes. I don’t remember why it was, maybe a bug.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

On Fri, 24 May 2013 16:56:02 +0000, tsu2 wrote:

> 1. Normally the Hosts file is read only once during boot (or restarting
> the appropriate service)
>
> 2. Don’t forget, in openSUSE you need to make Hostname changes in <two>
> places… not only to the Hosts file but in your YAST > Network Devices
>
> TSU

I have not found the second change to be necessary in my setup, FWIW.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

Interesting.
If these steps are not required any longer, it’s a relatively new development.

Will verify and likely find the same results others have posted.

TSU

Hm, depends on what you mean with “relatively new”. :wink:

I remember it being this way since years…

On 2013-05-27 16:26, tsu2 wrote:
>
> tsu2;2559824 Wrote:
>> 1. Normally the Hosts file is read only once during boot (or restarting
>> the appropriate service)
>>
>> 2. Don’t forget, in openSUSE you need to make Hostname changes in <two>
>> places… not only to the Hosts file but in your YAST > Network Devices
>
> Interesting.
> If these steps are not required any longer, it’s a relatively new
> development.

You may, some times, need change both. Sometimes the hosts file does not
end with the exact settings you want. But certainly, any change there
has immediate effects. If it doesn’t, there is a problem somewhere.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)