Mercurial hg clone error - "abort: error: Name or service not known"

17,619

Solution 1

The problem is (likely) that your http proxy is not able to:

  1. Resolve localmachine
  2. Reach your (or localmachine's) local IP, even if it could resolve 'localmachine' to your correct local address.

First, make sure nothing on your side (iptables / NAT / firewall) is preventing egress or ingress on the proxy port. If it works if you're root, that's the problem - work backwards from there.

Its also conceivable that your proxy is mangling the responses from the remote HG sufficiently to confuse Mercurial, but not your browser. In either case, its best to just go around the proxy if the HG is on the local (localhost/lan) network.

Fortunately, the [http_proxy] directive supports bypassing the proxy for certain host names, which is ideal for dealing with stuff on the same side of a NAT, or hosts that only exist on one machine (e.g. resolved via /etc/hosts.) This saves the pain from having to edit .hgrc every time you need to change the behavior.

See the documentation, or simply make your .hgrc look something like this:

[http_proxy]
host=proxy:8080
no=localmachine,192.168.1.123,192.168.1.234,...,...

The operative directive of course being no. I'm not sure if you can use wildcards when specifying the hosts (I don't use the proxy feature, so no way of testing that .. and its not specified in the documentation). You might try experimenting with that, e.g. 192.168.1.* and let us know if that works as well.

Anyway, for the terminally lazy (or people in a rather big hurry), the related section of the documentation linked above:

http_proxy

Used to access web-based Mercurial repositories through a HTTP proxy.

host
    Host name and (optional) port of the proxy server, for example "myproxy:8000".
no
    Optional. Comma-separated list of host names that should bypass the proxy.
passwd
    Optional. Password to authenticate with at the proxy server.
user
    Optional. User name to authenticate with at the proxy server.

Solution 2

Running hg as root solved the problem for me. But still don't know why.

Solution 3

This happened to me when my DNS name server settings weren't configured. Try to ping the remote repository host and try to ping some well-known host e.g. google.com. If it doesn't work, fix your DNS settings.

Solution 4

The error is because of DNS, add entry into /etc/resolve.conf.

$ cat /etc/resolve.conf
search xyz.com abc.com   --> DOMAINS
nameserver 10.192.160.12 -->DNS1
nameserver 10.193.180.23 -->DNS2

This enables to reach local machine by name, & hence clone will be successful.

Share:
17,619
Bojan Milankovic
Author by

Bojan Milankovic

C programmers never die. They are just cast into void.

Updated on June 04, 2022

Comments

  • Bojan Milankovic
    Bojan Milankovic about 2 years

    I have installed the latest hg package available for Fedora Linux. However, hg clone reports an error.

    hg clone http://localmachine001:8000/ repository
    

    reports:

    "abort: error: Name or service not known"
    

    localmachine001 is a computer within the local network. I can ping it from my Linux box without any problems. I can also use the same http address and browse the existing code. However, hg clone does not work.

    If I execute the same command from my Macintosh machine, I can easily clone the repository.

    Some Internet resources recommend editing .hgrc file, and adding proxy to it:

    [http_proxy]
    host=proxy:8080
    

    I have tried that without any success. Also, I assume that proxy is not needed in this case, since the hg server machine is in my local network.

    Can anyone recommend me what should I do, or how could I track the problem?

    Thank you in advance.