Disable modern internet to work around issue?

I was hoping FreePBX 17 would have better support for IPv6, not eliminate the possibility altogether.


The route here should be to NOT disable ipv6 and IF there is an issue with a specific script call that script with backwards compatibility until a fix is implemented.

node --dns-result-order=ipv4first your_script.js
1 Like

Disabling IPv6 is a 2005 solution and even then it was a hacky idea. What’s the deal with node? Is this a node bug or an issue with one of the FreePBX scripts specifically? Whatever the situation I am appalled that someone thought the right way to solve the problem is to disable the entire IPv6 stack.


I haven’t seen issues but obviously someone did and didn’t take 5 minutes to google and instead just killed ipv6 and said “works for me”. Fortunately as seen in some recent power points you don’t even need to think any more… Courtesy of two AI bots here is information and solutions that don’t require disabling IPv6. Choose your favorite AI overlord and use a solution that doesn’t suck.

Gemini 1.0 Pro Says

I understand your concern. Disabling IPv6 entirely isn’t ideal, so let’s explore why this might be happening and how to fix it without resorting to that.

The Issue:

In Node.js versions 16 and later, how localhost resolves changed. Previously, it prioritized IPv4 addresses (like Now, it respects the order your operating system provides, which might list IPv6 addresses (like ::1) first.

Here’s the potential problem: Your application code might be assuming it will connect on (IPv4), but if IPv6 is enabled, Node.js might try ::1 first. If your server code isn’t listening on IPv6, this attempt will fail.


There are a few ways to address this:

  1. Force IPv4 in your Node.js code:

    You can use the dns.lookup() function with the verbatim option to explicitly request an IPv4 address:

    const dns = require('dns');
    dns.lookup('localhost', { verbatim: true }, (err, address) => {
        if (err) throw err;
        // Use the resolved IPv4 address (address[0].family === 'IPv4')
        const server = net.createServer(...).listen(address[0].address);
        // ...
  2. Make your server listen on both IPv4 and IPv6:

    Update your server code to listen on (all IPv4 addresses) and :: (all IPv6 addresses):

    const server = net.createServer(...).listen({
        host: '',
        port: 8080
    }, () => {
        console.log('Server listening on port 8080 (IPv4 and IPv6)');
  3. Change OS preference (Not recommended, but an option):

    You can modify your system’s behavior to prioritize IPv4 addresses. This approach has broader implications and might affect other applications, so it’s generally not recommended. Edit /etc/gai.conf and add the line: precedence ::ffff:0:0/96 rfc3484 (Caution: Proceed with care)


  • Use ping localhost to see which address resolves first (IPv4 or IPv6).
  • Temporarily enable IPv6 and test your application thoroughly.

By implementing one of these solutions, your Node.js application can function correctly regardless of the system’s IPv6 preference. This allows you to keep IPv6 enabled and benefit from its future prevalence.

ChatGPT 3.5 says

The issue with applications breaking when IPv6 is enabled on Debian systems typically arises due to the default behavior of Node.js to prefer IPv6 addresses over IPv4 when both are available. This preference can lead to connection issues if the application or the server it’s trying to connect to isn’t properly configured to handle IPv6.

To resolve this issue without disabling IPv6, you can explicitly specify the IP version when creating network connections in your Node.js application. Here’s how you can do it:

const net = require('net');

// Create a client socket with specified IP version
const client = net.createConnection({
  host: 'localhost',
  port: 3000,
  family: 4 // Use IPv4

client.on('connect', () => {
  console.log('Connected to server');
  // Now you can send/receive data

client.on('error', (err) => {
  console.error('Error connecting to server:', err);

In this example, family: 4 explicitly tells Node.js to use IPv4 for the connection. You can also use family: 6 to specify IPv6 if needed.

Additionally, you can configure the system to prioritize IPv4 over IPv6 globally. On Debian, you can do this by editing the /etc/gai.conf file:

sudo nano /etc/gai.conf

Uncomment (remove the ‘#’ symbol) from the following line:

precedence ::ffff:0:0/96  100

This change instructs the system to prioritize IPv4 addresses over IPv6. After saving the file, you may need to restart your Node.js application for the changes to take effect.

By explicitly specifying the IP version or adjusting system-level configurations, you can ensure that your Node.js applications work correctly without needing to disable IPv6 altogether.

PROMPT For those wanting to use a different AI overlord

You are a senior software engineer and node expert. A developer comes up to you and says on his applications that call ‘localhost’ things break if ipv6 is enabled. Explain the potential issue and what may be done to resolve the issues in simple terms. Use code examples and system level configurations if necessary. These nodejs scripts will be running on Debian and the current workaround is to disable ipv6 which we want to avoid.


This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.