DD-L / lproxy

8 stars 3 forks source link

Host not found (authoritative) #107

Open DD-L opened 8 years ago

DD-L commented 8 years ago

lssserver.exe:

2016-Apr-09 12:06:07.268711 [DEBUG] start socks5_request_processing...  [tid:7f0723367780] session_server.cpp:274 left_read_handler
2016-Apr-09 12:06:07.268715 [DEBUG] lproxy::socks5::req::AddrType = domain  [tid:7f0723367780] session_server.cpp:943 socks5_request_processing
2016-Apr-09 12:06:07.268734 [DEBUG] lproxy::socks5::req::Addr.domain = cn.bing.com  [tid:7f0723367780] session_server.cpp:949 socks5_request_processing
2016-Apr-09 12:06:07.268739 [DEBUG] lproxy::socks5::req::Port = 80  [tid:7f0723367780] session_server.cpp:973 socks5_request_processing
2016-Apr-09 12:06:07.268754 [DEBUG] lproxy::socks5::req::Cmd = TCP-CONNECT  [tid:7f0723367780] session_server.cpp:977 socks5_request_processing
2016-Apr-09 12:06:07.268842 [DEBUG] start async_read local...   [tid:7f0723367780] session_server.cpp:287 left_read_handler
2016-Apr-09 12:06:07.269290 [ WARN] Host not found (authoritative)  [tid:7f0721935700] session_server.cpp:1106 tcp_resolve_handler

在 deel/lproxy-dev 里运行的好好的,到了基于 docker.io/busybox 制作的镜像的容器中,就会报上面的那个问题,导致 lproxy 服务不可用。

网搜查到几个可能有帮助的链接:

  1. http://stackoverflow.com/questions/12542460/boost-asio-host-not-found-authorative
  2. http://stackoverflow.com/questions/5971242/how-does-boost-asios-hostname-resolution-work-on-linux-is-it-possible-to-use-n

摘录下来就是

The problem was that the constructor for query has the address_configured flag set by default which won't return an address if the loopback device is the only device with an address. By just settings flags to 0 or anything other than address_configured the problem is fixed. Here is what I'm successfully using now: tcp::resolver::query query(host, PORT, boost::asio::ip::resolver_query_base::numeric_service);

查了下文档:

http://www.boost.org/doc/libs/1_60_0/doc/html/boost_asio/reference/ip__resolver_query_base.html#boost_asio.reference.ip__resolver_query_base.data_members

Name Description
address_configured Only return IPv4 addresses if a non-loopback IPv4 address is configured for the system. Only return IPv6 addresses if a non-loopback IPv6 address is configured for the system.
all_matching If used with v4_mapped, return all matching IPv6 and IPv4 addresses.
canonical_name Determine the canonical name of the host specified in the query.
numeric_host Host name should be treated as a numeric string defining an IPv4 or IPv6 address and no name resolution should be attempted.
numeric_service Service name should be treated as a numeric string defining a port number and no name resolution should be attempted.
passive Indicate that returned endpoint is intended for use as a locally bound socket endpoint.
v4_mapped If the query protocol family is specified as IPv6, return IPv4-mapped IPv6 addresses on finding no IPv6 addresses.

记录下来,以便查阅

DD-L commented 8 years ago

刚试了下,添加 boost::asio::ip::resolver_query_base::numeric_service 参数后还是不行,同样的错误。

服务发现 出了问题,那应该就是和 DNS 或 /etc/hosts 相关。

用 docker.io/busybox 做基础镜像的容器中的情况:

/opt/bin # ping bing.com
PING bing.com (204.79.197.200): 56 data bytes
64 bytes from 204.79.197.200: seq=0 ttl=114 time=55.593 ms
64 bytes from 204.79.197.200: seq=1 ttl=114 time=54.869 ms
^C
--- bing.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 54.869/55.231/55.593 ms

/opt/bin # cat /etc/hosts
172.17.0.12 c61e42d66d3b
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.12 lproxy
172.17.0.12 lproxy.bridge

/opt/lproxy/bin # cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.33.1

基于 deel/lproxy-dev 创建的容器中的情况:

/opt/lproxy# cat /etc/hosts 
172.17.0.13 a23ee976e4c3
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.13 lproxy_dev
172.17.0.13 lproxy_dev.bridge

/opt/lproxy# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 192.168.33.1

我去,简直一毛一样

DD-L commented 8 years ago

可能是 docker.io/busybox 中的 gethostbyname 出了问题。那就不用 docker.io/busybox 做基础镜像了,更换基础镜像,可解决此问题。(busybox体积很小,不足 2MB,真是舍不得啊)