No DNS with PHP in LXC

Pablo1732

Member
Dec 25, 2021
47
3
13
I cannot make DNS queries with PHP in LXC containers, in VM's it works without problems.
I have not changed anything in the Proxmox firewall settings, everything is set to default.
Normal DNS queries with "ping" work fine with PHP but not,
What could be the problem?
 
Hi,

Can you use request DNS using CLI?
Hi,
It depends on how.
e.g. “ping google.de” works everywhere on the Proxmox host, LXC's and VM's.
But e.g. “host -t SOA google.de” works fine in a VM, but doesnt work on the Host or LXC's.

Error:
Code:
root@rack-pve:~# host -t SOA google.de
;; communications error to 192.168.22.18#53: timed out
;; communications error to 192.168.22.18#53: timed out
;; communications error to 192.168.22.13#53: timed out
;; communications error to 9.9.9.9#53: timed out
;; no servers could be reached
I know the error says that the DNS servers cannot be reached. But the DNS servers from the host/LXC's are the same as are set on the VM's.
I can also run “apt update” on the host/LXC's without any problems. I am sure that the DNS servers are working because when I execute “ping google.com” in the LXC I can see this in the logs of the DNS servers. And nslookup works as well:

Code:
root@rack-pve:~# nslookup google.de
Server:         192.168.22.18
Address:        192.168.22.18#53

Non-authoritative answer:
Name:   google.de
Address: 172.217.16.163
Name:   google.de
Address: 2a00:1450:4016:80c::2003

I guess PHP DNS requests don't work for the same reason as “host -t SOA google.com”.

What can I do?
 
Last edited:
I cannot make DNS queries with PHP in LXC containers, in VM's it works without problems.
I have not changed anything in the Proxmox firewall settings, everything is set to default.
Normal DNS queries with "ping" work fine with PHP but not,
What could be the problem?

If you really want to debug it properly, you could start sniffing the connections to find out where your packages get lost.

As a quick and dirty workaround, you could use the PHP system functions exec(), system(), popen(), etc. and make PHP use
the system tools that work on that container.
 
If you really want to debug it properly, you could start sniffing the connections to find out where your packages get lost.

As a quick and dirty workaround, you could use the PHP system functions exec(), system(), popen(), etc. and make PHP use
the system tools that work on that container.
Hello,

Thank you for your reply.
Unfortunately I can't use other PHP functions because the problem occurs in Nextcloud (cloud based on PHP). I can't or don't want to change the entire code, and everything is overwritten after an update.

How can I sniff the connection?
 
Hello,

Thank you for your reply.
Unfortunately I can't use other PHP functions because the problem occurs in Nextcloud (cloud based on PHP). I can't or don't want to change the entire code, and everything is overwritten after an update.

How can I sniff the connection?

Hey, look into "tcpdump". You can sniff for DNS traffic on the containers interface, the bridge and the host to check where your DNS-traffic gets lost.

But.. Maybe this is no networking problem and rather a Nextcloud or PHP-configuration issue? Maybe try some other PHP-DNS-tool first to see if that one fails as well or not.
 
Hey, look into "tcpdump". You can sniff for DNS traffic on the containers interface, the bridge and the host to check where your DNS-traffic gets lost.

But.. Maybe this is no networking problem and rather a Nextcloud or PHP-configuration issue? Maybe try some other PHP-DNS-tool first to see if that one fails as well or not.
I will try "tcpdump". But I don't really know how to use it.

It's not a Nextcloud Error, read my third Post in this thread.
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!