in reply to Systemd Network Problem

Problem: when your programs try to resolve a name, glibc caches the contents of /etc/resolv.conf, which may be still empty by the time when /etc/rc.local is run. Wget process is restarted and has a chance to read a valid /etc/resolv.conf with nameservers inside, while your Perl script just runs and doesn't know that resolv.conf was overwritten with valid nameservers.

Solutions:

  1. (proper) Write a proper unit file for your scripts, so they start after NetworkManager has a working connection to the internet.
  2. Discard NM and use a static resolv.conf which does not change between reboots.
  3. (improper solutions start here) Add some sleep in your rc.local before launching your scripts.
  4. Move sleep 180 to the beginning of the loop, so the first gethostbyname will have a chance to wait for the connection to appear before caching resolv.conf.

Replies are listed 'Best First'.
Re^2: Systemd Network Problem
by Anonymous Monk on Jun 14, 2015 at 07:37 UTC
    Yup, I already found that inserting an initial sleep would resolve the problem, but I couldn't understand why; now I do! Thanks a million. The code segment is part of the DnsPixie.pl program which you can find at http://www.cpan.org/scripts/. It's intended to update dynamic DNS records when the host address changes. And it actually works well on other (Ubuntu, OpenBSD, Windows-XP, etc.) platforms. So I guess I need to force a cache refresh at each pass? Perhaps by a call to gethostbyname? Or .. ??
      In glibc, there is res_init function to reread resolv.conf. I'm not sure whether it's possible to call it from Perl without writing XS/Inline::C.