You are not logged in.

#1 2016-10-24 15:17:36

shsina
Member
Registered: 2016-10-22
Posts: 47

[SOLVED] Name or service not known

Hi

According to this I want to set my hostname in /etc/hosts file but after this I can't connect to any URL using PHP with tho following error:

getaddrinfo failed: Name or service not known

why? is it important to setting my hostname in /etc/hosts? (in Ubuntu I had this) and my hostname is not a real hostname.

Last edited by shsina (2016-10-28 11:39:41)

Offline

#2 2016-10-24 15:25:44

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Name or service not known

What does "connect to an URL using PHP" mean? What are you putting in /etc/hosts?


Moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2016-10-24 15:30:32

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

jasonwryan wrote:

What does "connect to an URL using PHP" mean? What are you putting in /etc/hosts?

for example:

file_get_content('a url here')
simplexml_load_file('a url here')

and etc...

my host name is "sina-X550DP"

I am putting:

127.0.1.1	sina-X550DP.localdomain	sina-X550DP

Last edited by shsina (2016-10-24 15:30:45)

Offline

#4 2016-10-24 16:08:31

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,803

Re: [SOLVED] Name or service not known

localhost is 127.0.0.1


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2016-10-24 16:12:35

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

ewaller wrote:

localhost is 127.0.0.1

All IPs which start with 127 are localhost.
Plz read topic carefully again and see URLs in it.

Offline

#6 2016-10-24 16:45:31

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,803

Re: [SOLVED] Name or service not known

It seems you are correct. Sorry.  Can you ping your system locally with the target being sina-X550DP? Can you ssh or http using sina-X550DP?
Trying to see if it is host name determination issues or php issues.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#7 2016-10-24 16:49:02

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

ewaller wrote:

It seems you are correct. Sorry.  Can you ping your system locally with the target being sina-X550DP? Can you ssh or http using sina-X550DP?
Trying to see if it is host name determination issues or php issues.

Yes I can ping and HTTP.

Without my hostname in /etc/hosts PHP works well.

In Ubuntu I had my hostname in /etc/hosts and PHP worked well. it seems it is my issue big_smile

Offline

#8 2016-10-26 14:10:57

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

Today after removing my hostname from /etc/hosts this problem occurred again.
I have restarted httpd from systemctl and problem fixed... It seems I need restart httpd each time after rebooting!

---

Is this cause of ordering? I mean Apache starts before NetworkManager.

Last edited by shsina (2016-10-26 14:15:53)

Offline

#9 2016-10-26 14:53:40

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] Name or service not known

Apache needs your network, so it would start after NetworkManager.

Offline

#10 2016-10-26 14:54:38

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

qinohe wrote:

Apache needs your network, so it would start after NetworkManager.

So what problem is?

Offline

#11 2016-10-26 15:05:16

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] Name or service not known

Do you mean how to fix that? Edit your httpd.service and start after your Networkmanger.
Have a look at the examples in systemd wiki

Offline

#12 2016-10-26 15:10:35

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

qinohe wrote:

Do you mean how to fix that? Edit your httpd.service and start after your Networkmanger.
Have a look at the examples in systemd wiki

My /usr/lib/systemd/system/httpd.serivce file:

[Unit]
Description=Apache Web Server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
ExecStart=/usr/bin/httpd -k start -DFOREGROUND
ExecStop=/usr/bin/httpd -k graceful-stop
ExecReload=/usr/bin/httpd -k graceful
PrivateTmp=true
LimitNOFILE=infinity
KillMode=mixed

[Install]
WantedBy=multi-user.target

I think it is ok...

Offline

#13 2016-10-26 15:19:22

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,754

Re: [SOLVED] Name or service not known

You should have your hostname in /etc/hosts... What are the contents of your /etc/hosts and /etc/hostname now? Throw in the output of

hostnamectl status

while you're at it

Offline

#14 2016-10-26 15:23:42

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

V1del wrote:

You should have your hostname in /etc/hosts... What are the contents of your /etc/hosts and /etc/hostname now? Throw in the output of

hostnamectl status

while you're at it

/etc/hostname

sina-X550DP

/etc/hosts

#
# /etc/hosts: static lookup table for host names
#

#<ip-address>	<hostname.domain.org>	  <hostname>
127.0.0.1	localhost.localdomain	  localhost
127.0.1.1       sina-X550DP.localdomain   sina-X550DP
::1		localhost.localdomain	  localhost

# End of file

hostnamectl status

   Static hostname: sina-X550DP
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: ba826b1bea3944a4af83c5ae1875daca
           Boot ID: 8c0953dbf6b7488e9ae4d1a166bf8f7d
  Operating System: Arch Linux
            Kernel: Linux 4.8.4-1-ARCH
      Architecture: x86-64

Offline

#15 2016-10-26 15:34:01

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] Name or service not known

I'm not using NetworkManager, but you can try and set this in your httpd.service.

After=network.target remote-fs.target nss-lookup.target NetworkManager

Mind you, if you edit the files in '/usr/' they might be overwritten when updating systemd, best put in '/etc/'
I don't even know if this is going to work, but hey.

Offline

#16 2016-10-26 15:45:46

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

qinohe wrote:

I'm not using NetworkManager, but you can try and set this in your httpd.service.

After=network.target remote-fs.target nss-lookup.target NetworkManager

Mind you, if you edit the files in '/usr/' they might be overwritten when updating systemd, best put in '/etc/'
I don't even know if this is going to work, but hey.

It didn't help, still need restart...

Offline

#17 2016-10-26 15:56:36

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] Name or service not known

What say your logs about this?

Offline

#18 2016-10-26 15:58:30

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

qinohe wrote:

What say your logs about this?

if you mean logs with running the systemctl status command, nothing.

Last edited by shsina (2016-10-26 15:58:55)

Offline

#19 2016-10-26 16:04:48

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] Name or service not known

Look in your httpd logs for a clue, about you needing to restart it.

Offline

#20 2016-10-26 16:07:13

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

qinohe wrote:

Look in your httpd logs for a clue, about you needing to restart it.

There is no error in there.

Last edited by shsina (2016-10-26 16:07:46)

Offline

#21 2016-10-27 10:51:08

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,754

Re: [SOLVED] Name or service not known

I'm still not entirely convinced on the hostname thing, my guess is your hostname is only correctly resolved once you have a connection and as httpd starts earlier it still uses the old one and can't be accessed anymore. For reference my hosts file looks like this

#
# /etc/hosts: static lookup table for host names
#

#<ip-address>	<hostname.domain.org>	  <hostname>
127.0.0.1	localhost.localdomain	  localhost arch-videl
::1		localhost.localdomain	  localhost arch-videl

# End of file 

So I've appended my hostname to the existing localhost definitions. The 127.0.1.1 thing seems to be new and maybe something bites here.

Also if you are already customizing your unit files, iirc the correct target to wait on (until you have an actual connection) is network-online. network.target will afaik be triggered simply when your network interfaces are available, which is before you have an actual usable connection and after NetworkManager won't help either, since NetworkManager has completed its startup by then). You might also need to

systemctl enable NetworkManager-wait-online.service

so that NetworkManager will trigger network-online.target

Last edited by V1del (2016-10-27 10:59:49)

Offline

#22 2016-10-27 11:20:51

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

V1del wrote:

I'm still not entirely convinced on the hostname thing, my guess is your hostname is only correctly resolved once you have a connection and as httpd starts earlier it still uses the old one and can't be accessed anymore. For reference my hosts file looks like this

#
# /etc/hosts: static lookup table for host names
#

#<ip-address>	<hostname.domain.org>	  <hostname>
127.0.0.1	localhost.localdomain	  localhost arch-videl
::1		localhost.localdomain	  localhost arch-videl

# End of file 

So I've appended my hostname to the existing localhost definitions. The 127.0.1.1 thing seems to be new and maybe something bites here.

Also if you are already customizing your unit files, iirc the correct target to wait on (until you have an actual connection) is network-online. network.target will afaik be triggered simply when your network interfaces are available, which is before you have an actual usable connection and after NetworkManager won't help either, since NetworkManager has completed its startup by then). You might also need to

systemctl enable NetworkManager-wait-online.service

so that NetworkManager will trigger network-online.target

I have done all of your solutions together and separately but problem still exists...
There is nothing about this issue is google...
I didn't change any config file and I have a fresh install of Arch...

Offline

#23 2016-10-27 21:26:25

seth
Member
Registered: 2012-09-03
Posts: 51,553

Re: [SOLVED] Name or service not known

Is your hostname resolved w/o the entry in /etc/hosts? (Eg. because your router has dnsmasq and assigns it to 192.168.1.x?)
"any URL" implies www.google.com - or just your LAN?

I've localhost assigned in /etc/hosts, but not my <hostname>
For a start, i'd try to disable NM and enable netctl. NM does mess around with the hostname if it doesn't like it (famously breaking X11 if /etc/hostname is empty ...)

Offline

#24 2016-10-27 21:36:17

shsina
Member
Registered: 2016-10-22
Posts: 47

Re: [SOLVED] Name or service not known

V1del wrote:

Also if you are already customizing your unit files, iirc the correct target to wait on (until you have an actual connection) is network-online. network.target will afaik be triggered simply when your network interfaces are available, which is before you have an actual usable connection and after NetworkManager won't help either, since NetworkManager has completed its startup by then). You might also need to

systemctl enable NetworkManager-wait-online.service

so that NetworkManager will trigger network-online.target

https://bbs.archlinux.org/viewtopic.php?id=78849

This guy had a same problem, we are in correct way, problem is cause of ordering and It seems your answer can fix it, but when I am enabling NetworkManager-wait-online service it doesn't start on boot automatically I have changed the timeout value but it doesn't start again.

Some info:

[sina@sina-X550DP ~]$ systemctl status NetworkManager-wait-online
● NetworkManager-wait-online.service - Network Manager Wait Online
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager-wait-online.service; d
   Active: inactive (dead)
     Docs: man:nm-online(1)
[sina@sina-X550DP ~]$ systemctl status network-online.target
● network-online.target - Network is Online
   Loaded: loaded (/usr/lib/systemd/system/network-online.target; static; vendor
   Active: inactive (dead)
     Docs: man:systemd.special(7)
           http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget
[sina@sina-X550DP ~]$ sudo cat /usr/lib/systemd/system/NetworkManager-wait-online.service
[Unit]
Description=Network Manager Wait Online
Documentation=man:nm-online(1)
Requisite=NetworkManager.service
After=NetworkManager.service
Before=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/nm-online -s -q --timeout=180
RemainAfterExit=yes

[Install]
WantedBy=network-online.target

Last edited by shsina (2016-10-27 21:49:39)

Offline

#25 2016-10-27 22:02:18

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,754

Re: [SOLVED] Name or service not known

Yeah that's normal, NetworkManager-wait-online target is only supposed to trigger execution of the network-online.target . What is your httpd.service pointing to now? It should have an After=network-online.target now (maybe WantedBy=network-online.target and Wants=network-online.target as well) and remove the references to NetworkManager there. Don't hang yourself up on that DAEMONS line, that's for pre-systemd configuration.

Last edited by V1del (2016-10-28 11:32:30)

Offline

Board footer

Powered by FluxBB