Forums

Issue with systemd-resolved.service in Console

Hi!!

I am having issue with the systemd-resolved service or at least with its configuration when I am trying to execute code through the console. In short all address resolution fails when I am trying to use it. Although seem to not affect socket.getaddrinfo calls, since those I assume use a system call.

Note that last time I ran code from console, around 3 weeks ago, everything worked fine.

To reproduce the issue, first I read the resolve configuration at: /etc/resolv.conf:

nameserver 127.0.0.53
options edns0 trust-ad
search ec2.internal

I see here that I should connect to 127.0.0.53. From the manual, https://www.man7.org/linux/man-pages/man8/systemd-resolved.service.8.html, I see I should be using port 53. So business as usual so far, but when I am trying to create the connection, I get connection refused.

In [19]: socket.create_connection(('127.0.0.53', 53))
Traceback (most recent call last):
    File "<console in[19]>", line 1, in <module>
        1 >>> socket.create_connection(('127.0.0.53', 53))
    File "/usr/lib/python3.8/socket.py", line 808, in create_connection
        806   | if err is not None:
        807   |     try:
        808 >>>         raise err
        809   |     finally:
        810   |         # Break explicitly a reference cycle
    File "/usr/lib/python3.8/socket.py", line 796, in create_connection
        794   | if source_address:
        795   |     sock.bind(source_address)
        796 >>> sock.connect(sa)
        797   | # Break explicitly a reference cycle
        798   | err = None
ConnectionRefusedError(111, 'Connection refused')

System information:

$ uname -a
Linux blue-liveconsole14 6.8.0-1061-aws #64~22.04.1-Ubuntu SMP Thu Jul 16 14:38:59 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux

Python information:

3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0] on linux

If I am doing anything wrong, please correct me, although everything worked for me previously, for like half year; and I am having no issues in my Always on Tasks. If this is actually an issue please fix it.

Thank you.

Could you shed some more light on what you're trying to actually solve and what kind of errors you're getting when you run your original code that started to fail?

I am trying to do asynchronous address info resolution.

To do that, my program on startup reads the /etc/resolv.conf file for the preferred address to do these kind of requests towards. On the environment this file exists and defines a name server; therefore my code is trying to use this name server instead of the default ones (like 8.8.8.8). When the time comes to get address info, It creates a connection to the name server which fails.

I am not sure whether a full traceback would be really useful, but here is me trying to get address info of pythonanywhere:

In [3]: output = await get_address_info_async(loop, 'www.pythonanywhere.com', 443)
Traceback (most recent call last):
    File "<console in[3]>", line 1, in <module>
        1 >>> output = await get_address_info_async(loop, 'www.pythonanywhere.com', 443)
    File "/home/HuyaneMatsu/scarletio_repo/scarletio/dns_query/requests.py", around line 712, in get_address_info_async
        710   | 
        711   | for labels in iter_labels_with_searches(resolve_configuration, parse_labels_from_name(host_name)):
        712 >>>     async for result in async_iter_execute_query_async(
        713   ~         event_loop,
        714   ~         Query(
        715   ~             _get_next_id(),
        716   ~             True,
        717   ~             True,
        718   ~             (*(
        719   ~                 Question(
        720   ~                     labels,
        721   ~                     (
        722   ~                         RESOURCE_RECORD_TYPE_IP_V4_ADDRESS
        723   ~                         if socket_family == SOCKET_FAMILY_IP_V4 else
        724   ~                         RESOURCE_RECORD_TYPE_IP_V6_ADDRESS
        725   ~                     ),
        726   ~                     CLASS_CODE_INTERNET,
        727   ~                 )
        728   ~                 for socket_family in socket_families
        729   ~             ),),
        730   ~             None,
        731   ~         ),
        732   ~         resolve_configuration,
        733   ~         ssl_context,
        734   ~     ):
    File "/home/HuyaneMatsu/scarletio_repo/scarletio/dns_query/requests.py", line 197, in async_iter_execute_query_async
        195   | task.apply_timeout(resolve_configuration.option_timeout)
        196   | try:
        197 >>>     result = await task
        198   | except TimeoutError:
        199   |     continue
    File "/home/HuyaneMatsu/scarletio_repo/scarletio/dns_query/requests.py", around line 342, in _execute_query_tcp
        340   | protocol = None
        341   | try:
        342 >>>     protocol = await event_loop.create_connection_to(
        343   ~         partial_func(ReadWriteProtocolBase, event_loop),
        344   ~         ''.join([*produce_ip_string(name_server_configuration.ip_type, name_server_configuration.ip_value)]),
        345   ~         53,
        346   ~         socket_flags = ADDRESS_INFO_NUMERIC_HOST,
        347   ~     )
        348   |     
    File "/home/HuyaneMatsu/scarletio_repo/scarletio/core/event_loop/event_loop.py", line 1516, in create_connection_to
        1514   | else:
        1515   |     if len(exceptions) == 1:
        1516 >>>         raise exceptions[0]
        1517   |     else:
        1518   |         # If they all have the same str(), raise one.
    File "/home/HuyaneMatsu/scarletio_repo/scarletio/core/event_loop/event_loop.py", line 1499, in create_connection_to
        1497   |             continue
        1498   |     
        1499 >>>     await self.socket_connect(socket, address)
        1500   | except OSError as err:
        1501   |     if (socket is not None):
    File "/home/HuyaneMatsu/scarletio_repo/scarletio/core/event_loop/event_loop.py", line 2278, in socket_connect
        2276   | future.add_done_callback(partial_func(self._socket_write_done_callback, file_descriptor, handle))
        2277   | 
        2278 >>> return await future
        2279   | 
        2280   | 
ConnectionRefusedError(111, "Connect call failed to: ('127.0.0.53', 53).")

Technically I could be using a custom configuration to do my address resolution, but this should be working based on the configuration the environment is providing me.

The resolv.conf in user jails is not intended as something that should be used like that

Do you know any ways how I can determine whether resolv.conf can or cannot be used?

No, it cannot

Okay, Thank you still.

Its Saturday, do not overwork yourself, take care :)