A host name in external_signaling_address can silently resolve to 127.0.1.1 (no audio, calls drop at 32 s)

Posting this one because the symptom pointed in completely the wrong direction and it cost us a day.

Setup: Asterisk 22 on Ubuntu on a cloud VM, PJSIP, one UDP transport with external_signaling_address and external_media_address set to the box’s own host name instead of its public IP.

Symptom: calls were set up and answered, no audio in either direction, and every call ended at exactly 32 seconds with no BYE from the far end. pjsip show channelstats showed 0 RTP received and 0 sent on both legs, including a desk phone on the same LAN as Asterisk — which is what sent us hunting an SRTP/codec problem that did not exist.

Cause: Debian and Ubuntu put

127.0.1.1   my-host-name

in /etc/hosts. Asterisk resolves the name in external_signaling_address / external_media_address through the normal resolver, so it got 127.0.1.1 and put that on the wire: c=IN IP4 127.0.1.1 in the SDP and 127.0.1.1 in the Contact:. Media went nowhere, and the ACK — and later the BYE — was addressed to the far end’s own loopback, so the 200 OK was retransmitted until timer H gave up: 64 × T1 = 32 s. Hence the suspiciously round billsec=32.

Confirming it in a minute:

  • pjsip show transports prints the configured value, not what it resolved to, so it looks perfectly fine. Look at the wire instead: pjsip set logger host <far-end-ip>, place a call, and read the Contact: and c= lines of the INVITE.
  • getent hosts $(hostname) on the box. If that answers 127.0.1.1, that is what Asterisk saw.

Fixes:

  • Put an IP literal in external_signaling_address / external_media_address. A name is resolved once when the transport is loaded and transports cannot be reloaded, so a name buys you nothing anyway: a changed address needs a restart either way.
  • If a script writes that config, take the address from a resolver that cannot see /etc/hosts — dig +short @1.1.1.1 <name> — rather than hostname -I, getent or hostname -f.
  • Check local_net covers every network that really is local. A handset on the office wi-fi that hairpins through the public IP counts as outside it.

Two things I would do differently next time: no RTP in either direction on both legs means Asterisk is not even trying to send to a reachable address, so read the SDP before looking at media; and any host name in pjsip.conf on a Debian-family box deserves a getent check before anything else.

Hi there

If I understand correctly, this won’t happen if you set host name, domain and IP address during install;

Regards,
Rob