Ad Widget

Collapse

net.tcp.service on localhost fails but 127.0.0.1 works?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yurtesen
    Senior Member
    • Aug 2008
    • 130

    #1

    net.tcp.service on localhost fails but 127.0.0.1 works?

    I have a strange problem. This does not seem to work with localhost but it works with 127.0.0.1. Why might this happen? localhost resolves to 127.0.0.1 ?

    Code:
    $ zabbix_agent -t net.tcp.service["http","127.0.0.1","9200"]
    net.tcp.service[http,127.0.0.1,9200] [u|1]
    $ zabbix_agent -t net.tcp.service["http","localhost","9200"]
    net.tcp.service[http,localhost,9200] [u|0]
    $ dig localhost
    
    ; <<>> DiG 9.9.5-3ubuntu0.4-Ubuntu <<>> localhost
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56237
    ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
    
    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 4096
    ;; QUESTION SECTION:
    ;localhost. IN A
    
    ;; ANSWER SECTION:
    localhost. 10800 IN A 127.0.0.1
    
    ;; AUTHORITY SECTION:
    localhost. 10800 IN NS localhost.
    
    ;; ADDITIONAL SECTION:
    localhost. 10800 IN AAAA ::1
    
    ;; Query time: 0 msec
    ;; SERVER: 185.29.15.15#53(185.29.15.15)
    ;; WHEN: Wed Jul 08 10:21:58 CEST 2020
    ;; MSG SIZE rcvd: 96
    
    $ ping localhost
    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.041 ms
    ^C
    --- localhost ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.041/0.041/0.041/0.000 ms
    $ telnet localhost 9200
    Trying ::1...
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    ^]
    telnet> Connection closed.
    
    $
  • tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    #2
    If you look carefully at the output you provided, the answer to your question is there:

    Originally posted by yurtesen
    $ telnet localhost 9200
    Trying ::1...
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    ^]
    telnet> Connection closed.
    $[/CODE]
    Notice the "::1" in the output? That's the IPv6 localhost address. It's probably coming from your /etc/hosts file, which is probably searched before the DNS (see /etc/nsswitch.conf for more info).

    When you use "localhost", your the IPv6 address ::1 is returned first, followed by the IPv4 address. So the zabbix_agentd item that's failing is failing because it's trying the IPv6 address, and your web config apparently isn't listening on IPv6. When you use "127.0.0.1", that forces it to use IPv4.

    The 'dig' command is specifically for interrogating nameservers, so it bypasses the contents of your /etc/hosts file.

    The 'ping' command (on Linux, at least) can handle either IPv4 or IPv6, but it appears to default to IPv4, even when an IPv6 address is returned first. That's a little weird, but ping operates at a slightly lower level than many other networking commands, and it may be doing that for backward compatibility, since there used to be a separate ping6 command (again, on Linux).

    Comment

    • yurtesen
      Senior Member
      • Aug 2008
      • 130

      #3
      tim.mooney yes, you seem to be correct. I looked at zabbix_agent execution with strace command it seems to be doing some ipv6 stuff... Thanks!

      Comment

      Working...