How to disable IPv6 support PHP

feerdispzoo

Verified User
Joined
Jan 17, 2022
Messages
189
Hello,
I've only IPv4 address and everytime I get API CURL ERROR timeout (28)

I see this issue because I need disable IPv6.

I disable IPv6 in:
an alternative method is to configure GRUB to pass kernel parameters at boot time. You’ll have to edit /etc/default/grub

now ip a I not see IPv6

but still I see in php.info

IPv6 Supportenabled

How can I disable it from php config? (because still I have CURL Api error)

Also I see in CURL
IPv6Yes


How to also disable this from here?
 
What distro and OS are you using? Seems ipv6 is not disabled as should be completely.
I presume you also rebooted after making the grub change.
 
Centos7 converted to CloudLinux.

Yes, I also reboot server but still API curl error. Also I check and see still:

[root@vim735ac ~]# curl -V
curl 7.84.0 (x86_64-pc-linux-gnu) libcurl/7.84.0 OpenSSL/1.0.2k-fips zlib/1.2.7 zstd/1.5.2 nghttp2/1.33.0
Release-Date: 2022-06-27
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HSTS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL UnixSockets zstd
[root@vim735ac ~]#

I also uncomment resolve IPv4
[root@vim735ac ~]# cd /usr/include/curl
[root@vim735ac curl]# ls
curlbuild-64.h curlbuild.h curl.h curlrules.h curlver.h easy.h mprintf.h multi.h stdcheaders.h typecheck-gcc.h
[root@vim735ac curl]# vi curl.h

Im not sure with this but this also not resolve issue.
 
Oke I don't use Cloudlinux but in some cases changing Grub does not do all you want.

For Centos 7, use this guide. I used it for my Centos 7 server and ipv6 and I don't have any ipv6 on my servers.

If needed, you can even stop named from using ipv6 by editting this file:
/etc/sysconfig/named
add this:
OPTIONS="-4"

Comment out any ipv6 stuff in your /etc/hosts file and I also editted my network card.
In /etc/sysconfig/network-scripts I editted the network card, in my case it was named ifcfg-enp0s31f6.
I removed ipv6 stuff if present and changed this from yes to no:
IPV6INIT=no

The I rebooted my server and never seen ipv6 anymore anywhere.
Make backups of your configs and/or network card if you want to add ipv6 later on and don't know how.

This trick should work for you, unless Cloudlinux would do something with this.
 
Hello @Richard,
thank you for reply! Before I apply this changes, can I ask you with last thing.

I see that when I do a lot of things on the websites, this error comes back to me and keeps telling me that my server is misconfigured.

example:
Now in my Magento I get:
"Warning: get_headers(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/.....Driver/Http.php on line 26"

I check this error in Google:

and again every error points me to "bad server configuration":
"I have encountered the same error but i think it was from a bad server configuration in "etc/resolf.conf" and "etc/hosts""


What do you think about it? Because now I do not know if this is an IPv6 issue or maybe something else?
 
Before I apply this changes, can I ask you with last thing.
I don't know if this could be ipv6 related, sometimes ipv6 things can cause odd issues.

However, since you said Magento I had a look on Google en found this:
which says if there are multiple (also older) xml files, Magento will read those too and cause this error message.
Maybe you don't have Magento 1 but another one I don't know. But as you can see it might be related to Magento and/or database connection issues from Magento and maybe not even php itself.

However, it could well be something else, this error can have several causes.

In /etc/resolv.conf I would suggest to use the datacenters resolver and 1.1.1.1 instead of 8.8.8.8 because with Googles resolve one can run into limit issues sometimes.
As for the /etc/hosts file, it seems not needed but I always have this in there:
Code:
127.0.0.1 localhost.localdomain localhost
95.xx.xx.xx            server.mycompany.com server

Where the ip is ofcourse the full ip and the hostname is the correct hostname. Some applications require the localhost to be present and stated correctly.
Als in /etc/hostname I always have the correct hostname present (server.mycompany.com) because I once also encountered an issue with something complaining about a missing host name (only looking in /etc/hostname for the name apparently).
 
@Richard G
please see what I've in /etc/resolv.conf.

Should I change this, or this is okay?

1662901719931.png



For network-script I've
1662901973961.png
 
Back
Top