AdGuardHome icon indicating copy to clipboard operation
AdGuardHome copied to clipboard

Container shows only the Docker network's IP as the Client in logs

Open YouveGotMeowxy opened this issue 4 years ago • 10 comments

Have a question or an idea? Please search it on our forum to make sure it was not yet asked. If you cannot find what you had in mind, please submit it here.

Prerequisites

Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • [X] I am running the latest version
  • [X] I checked the documentation and found no answer
  • [X] I checked to make sure that this issue has not already been filed

Issue Details

  • Version of AdGuard Home server:
    • Version: v0.107.5
  • How did you install AdGuard Home:
    • Docker container: adguard/adguardhome:latest

My Compose:

version: "3.8"

services:

    adguard:
        hostname: adguard
        image: adguard/adguardhome:latest
        environment:
          TZ: 'America/Chicago'
          PUID: 1000
          PGID: 1000
        volumes:
          - '/opt/docker/configs/adguard/config:/opt/adguardhome/conf:rw'
          - '/mnt/e/Docker/adguard/data:/opt/adguardhome/work:rw'
        ports:
          - '3000:3000/tcp'
          - '53:53/tcp'
          - '53:53/udp'
          - '853:853/tcp'
          - '853:853/udp'
          - '784:784/udp'
          - '8853:8853/udp'
          - '5443:5443/tcp'
          - '5443:5443/udp'
        networks:
          - ocdns
        deploy:
          mode: replicated
          replicas: 1
          placement:
            constraints:
              - node.labels.Main == true
          restart_policy:
            condition: any

networks:
  ocdns:
    external: true
    name: dns
  • How did you setup DNS configuration:
    • Just setup through adg's settings, then put the host ip and port in the device I want to use adg. i.e. on another windows pc I set it's nic to use that dns.

image

  • Operating system and version:
    • Win 10 x64 running WSL2 + Ubuntu

Expected Behavior

See real/actual IP of the client in the logs

Actual Behavior

It's only showing the IP of Docker's network (10.0.0.2) for every single item.

Screenshots

Screenshot:

Sample of client queries from Adguard (ALL client IP's are always the same): image

Additional Information

I'm also using Linuxserver.io's SWAG Nginx container, and serving the web ui up via a reverse proxy (https://adguard.mydomain.com), but that's only for the web ui; the regular adguard ports are still open to the host and all devices connect to the host's ip + port 53.

YouveGotMeowxy avatar Mar 18 '22 09:03 YouveGotMeowxy

Can confirm same issue.

nikkadim avatar Mar 18 '22 15:03 nikkadim

If you're using Docker Networking, this is expected behavior.

You should use host networking if you want to see requests by client. This should be documented in the wiki.

agneevX avatar Mar 19 '22 09:03 agneevX

So don't use a container if we want to see actual IP's?

YouveGotMeowxy avatar Mar 20 '22 18:03 YouveGotMeowxy

Same here, same config. But as far as I remember, this doesn't happen before. Even with rDNS and upstreams servers with my router address, only appears as a client de gateway of the docker network. Any solution on this?

decisoft avatar Mar 20 '22 22:03 decisoft

So don't use a container if we want to see actual IP's?

You can containerize, but you need to use host networking as I said.

agneevX avatar Mar 21 '22 05:03 agneevX

So don't use a container if we want to see actual IP's?

You can containerize, but you need to use host networking as I said.

How do you do that when using docker swarm?

YouveGotMeowxy avatar Mar 21 '22 06:03 YouveGotMeowxy

https://forums.docker.com/t/use-host-network-for-swarm-container/74878/4

agneevX avatar Mar 22 '22 12:03 agneevX

@YouveGotMeowxy, if the @agneevX's suggestion worked?

EugeneOne1 avatar Mar 30 '22 16:03 EugeneOne1

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 10 '22 15:07 stale[bot]

@EugeneOne1 I can confirm that running AdGuard Home docker container with network_mode host fixes this issue.

I myself was seeing only one client (the gateway of the docker network all my other containers are connected to), and now all containers show up.

I am running a reverse proxy (nginx-proxy/nginx-proxy) that uses ports 80 and 443, so to enable AGH encryption I configured the AGH HTTPS port to be 444 and ran a socat container so that the Web UI / HTTPS traffic can be exposed in the vlan where the reverse proxy can see it. Putting my working compose here for others having similar issues:

---
version: "3.2"

services: 
  adguard:
    container_name: adguard
    image: adguard/adguardhome
    user: "1000:1000"
    network_mode: host
    volumes: 
      - ./data:/opt/adguardhome/work
      - ./conf:/opt/adguardhome/conf
      - ../nginx-proxy/certs/dns.domain.tld:/certs:ro
    restart: unless-stopped

  adguard-socat:
    image: alpine/socat:latest
    container_name: adguard-socat
    cap_add: [ 'NET_ADMIN', 'NET_RAW' ]
    entrypoint: "socat tcp-listen:445,fork,reuseaddr tcp-connect:<HOST_IP>:444"
    environment:
      - LETSENCRYPT_HOST=dns.domain.tld
      - VIRTUAL_PORT=445
      - VIRTUAL_HOST=dns.domain.tld
      - VIRTUAL_PROTO=https
    ports:
      - 445:445
    restart: always

networks:
  default:
    external:
      name: webproxy

a1ex4 avatar Jul 12 '22 10:07 a1ex4

How do I fix this if I don't want to use the host mode in docker?

Can AdGuard Home not take IP from HTTP header from trusted reverse proxy by specifying trusted reverse proxy IP? That's how it's usually handled.

nextlogic-ono avatar Aug 30 '22 23:08 nextlogic-ono

Can AdGuard Home not take IP from HTTP header from trusted reverse proxy by specifying trusted reverse proxy IP? That's how it's usually handled.

Are you referring to this header?: proxy_set_header X-VerifiedViaNginx yes;

I recently came across this header for the first time and am not fully sure what it does/how it works, and can't really find any info on it?

STaRDoGG avatar Aug 31 '22 02:08 STaRDoGG

No, I meant the generally used X-Forwarded-For header.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For

I have a reverse proxy in front of AdGuard Home, which can send the client's real IP through that header and if I specify the reverse proxy's IP (such as 172.17.0.1 using docker) as a trusted source IP in AdGuard Home, then AdGuard Home may use that header's value as the client's IP instead of listing every access is from 172.17.0.1.

nextlogic-ono avatar Aug 31 '22 02:08 nextlogic-ono

No, I meant the generally used X-Forwarded-For header.

I'm not an expert in this area, but if I had to guess I'd say those are only for http headers, and when doing a DNS lookup http headers aren't sent to AGH (or any DNS resolver), so the forwarded for header wouldn't matter. It only matters to the AGH Web UI. (again, just guessing).

STaRDoGG avatar Aug 31 '22 02:08 STaRDoGG

Yes, this is only for DoH.

Regarding plain DNS on port 53 and DoT, you cannot reverse proxy those like web servers do, so it's ok to take the client's IP as is, as client's IP is exposed to AdGuard Home even through NAT, but for DoH through a reverse proxy, the client that's directly accessing AdGuard Home would be the reverse proxy web server making it looking like all requests are coming from the reverse proxy but by utilizing that header, AdGuard Home can obtain the actual client's IP.

Client (1.2.3.4) -> Reverse proxy (172.17.0.1) -> AdGuard Home

  • Currently AdGuard Home logs 172.17.0.1 as client IP no matter what the actual client IP is.
  • Reverse proxy can send X-Forwarded-For: 1.2.3.4header to AdGuard Home.
  • AdGuard Home should have a setting for what IP to trust (as anyone else can also set that header to pretend to be another IP) that can send X-Forwarded-For (in this case, set the trusted source as 172.17.0.1) and use the header value as client's IP instead.

Without this, you cannot also restrict access by IP as AdGuard Home thinks it's only interacting with 172.17.0.1.

nextlogic-ono avatar Aug 31 '22 03:08 nextlogic-ono

@windware-ono, hello. AdGuard Home actually has this setting in the configuration file, it's called trusted_proxies. AGH treats those subnets as trusted and check the HTTP headers for real client's IP. The wiki has a description of those headers. As @STaRDoGG correctly noted, this is the DNS-over-HTTP only solution.

By the way, we've got a feature request for extracting the real client's IP from the DNS message itself (#1727).

EugeneOne1 avatar Aug 31 '22 10:08 EugeneOne1

@EugeneOne1 Sorry for the mess. I'll make sure to read the doc first.

nextlogic-ono avatar Aug 31 '22 14:08 nextlogic-ono

@windware-ono, we'd appreciate your feedback on using trusted_proxies. If that works as expected?

EugeneOne1 avatar Sep 05 '22 16:09 EugeneOne1

@windware-ono, we'd appreciate your feedback on using trusted_proxies. If that works as expected?

Yes it did! Thanks.

nextlogic-ono avatar Sep 05 '22 16:09 nextlogic-ono

I haven't really figured this out! I'm seeing three solutions, none of which aren't working on my docker swarm setup:

version: "3"
services:
  adguardhome:
    image: adguard/adguardhome
    ports:
      - 53:53/tcp
      - 53:53/udp
      - 67:67/udp
      - 68:68/tcp
      - 68:68/udp
      - 853:853/tcp
      - 82:80/tcp #change this to something like 81:80 if port 80 is already in use
      - 3000:3000/tcp
    volumes:
      - adguard-data:/opt/adguardhome/work
      - adguard-config:/opt/adguardhome/conf
    restart: unless-stopped
    network_mode: host

volumes:
  adguard-data:
    external: true
  adguard-config:
    external: true
version: "3"
services:
  adguardhome:
    image: adguard/adguardhome
    ports:
      - 53:53/tcp
      - 53:53/udp
      - 67:67/udp
      - 68:68/tcp
      - 68:68/udp
      - 853:853/tcp
      - 82:80/tcp #change this to something like 81:80 if port 80 is already in use
      - 3000:3000/tcp
    volumes:
      - adguard-data:/opt/adguardhome/work
      - adguard-config:/opt/adguardhome/conf
    restart: unless-stopped
    networks:
      - outside

volumes:
  adguard-data:
    external: true
  adguard-config:
    external: true

networks:
  outside:
    external:
      name: "host"
version: "3"
services:
  adguardhome:
    image: adguard/adguardhome
    ports:
      - 53:53/tcp
      - 53:53/udp
      - 67:67/udp
      - 68:68/tcp
      - 68:68/udp
      - 853:853/tcp
      - 82:80/tcp #change this to something like 81:80 if port 80 is already in use
      - 3000:3000/tcp
    volumes:
      - adguard-data:/opt/adguardhome/work
      - adguard-config:/opt/adguardhome/conf
    restart: unless-stopped

volumes:
  adguard-data:
    external: true
  adguard-config:
    external: true

networks:
  outside:
    external:
      name: "host"

Plus the socat stuff, which I don't even know what it is.

  1. Starts up fine. I can set it up, but it only shows 10.0.0.2 as a client.
  2. The docker container fails to start without any error and I don't even know what exactly to change in Portainer or such, like whether I should actually add the network "outside" and if yes how to configure it.
  3. Same as 2.

Can anybody give an idiot-proof step-by-step on what to do here, please?

FlyingPersian avatar Sep 10 '22 16:09 FlyingPersian

@FlyingPersian, it's better to start new Discussions as opposed to writing to closed issues. Also, not a lot of people have enough experience with Portainer/Docker Swarm, so it's generally better to check if AdGuard Home works outside of a container before filing an issue. Because if it does, the problem is most probably with the system configuration, and is thus better discussed on the Discussions page.

ainar-g avatar Sep 12 '22 12:09 ainar-g

Can anybody give an idiot-proof step-by-step on what to do here, please?

I suspect you won't really get any "good" answer to that exact request. I've tried several times in the past and still have never gotten one that works.

YouveGotMeowxy avatar Sep 12 '22 15:09 YouveGotMeowxy

@FlyingPersian, it's better to start new Discussions as opposed to writing to closed issues. Also, not a lot of people have enough experience with Portainer/Docker Swarm, so it's generally better to check if AdGuard Home works outside of a container before filing an issue. Because if it does, the problem is most probably with the system configuration, and is thus better discussed on the Discussions page.

It'd probably be great if the owner of this repo converted this thread into a discussion rather than create another, brand new one revolving around the same exact question.

YouveGotMeowxy avatar Sep 12 '22 15:09 YouveGotMeowxy

Can't you just run in network_mode: host and eliminate all those ports?

That's the simplest solution if you're fine with no network isolation for your AdGuardHome instance.

flavorgold1 avatar Oct 17 '22 00:10 flavorgold1

Can't you just run in network_mode: host and eliminate all those ports?

That's the simplest solution if you're fine with no network isolation for your AdGuardHome instance.

I have that already, doesn't solve the problem

FlyingPersian avatar Nov 08 '22 22:11 FlyingPersian

I have many AdGuardHome installations, all with non-default bridge networking. One of these correctly log the real IP address of my host in my lan (10.20....) . The other instead log the docker gateway ip address (172.20...) for any client. Why?

outofsight avatar Feb 06 '23 18:02 outofsight

For me, the correct IP is displayed first and the URL e.g. blocked and then the docker IP afterwards without the URL being blocked It would be nice if you could get rid of the docker IP.

Blue765 avatar Apr 26 '23 20:04 Blue765

Maybe we can use macvlan in docker, it will create a virtual network device for docker, also we will get a new IP by this virtual network interface.

Reference(missing test, enp2s0 is my network interface id):

version: "2.1"
services:
  adguardhome:
    container_name: adguardhome
    restart: unless-stopped
    volumes:
      - ./adguardhome/workdir:/opt/adguardhome/work
      - ./adguardhome/confdir:/opt/adguardhome/conf
    ports:
      - 53:53/tcp
      - 53:53/udp
        #- 67:67/udp
        #- 68:68/udp
      - 18099:80/tcp
        #- 443:443/tcp
        #- 443:443/udp
      - 18090:3000/tcp
        #- 853:853/tcp
        #- 784:784/udp
        #- 853:853/udp
        #- 8853:8853/udp
        #- 5443:5443/tcp
        #- 5443:5443/udp
    networks:
      openwrt_lan:
    image: adguard/adguardhome:v0.107.36
    
networks:
  openwrt_lan:
    driver: macvlan
    driver_opts:
      parent: enp2s0
    ipam:
      config: default

wangerzi avatar Aug 10 '23 15:08 wangerzi

I have a similar issue with a rootless podman installation. I have another installation with Docker Swarm and overlay network, it works without any problem. From what I understand, my problem is the bridge driver with splirp4netns. It doesn't support original IP address.

Using network_mode=host will be insecure, I believe that switching to pasta (passt) will fix the problem. I've not tested yet because my host is a LTS 22.04 ubuntu and passt is only available (from package) with 23.04/23.10

mTrax- avatar Oct 29 '23 15:10 mTrax-