gftd
Posts: 1
Joined: Mon Jul 02, 2012 8:47 pm

Cannot Resolve Hostname

Mon Jul 02, 2012 8:53 pm

My Raspberry Pi is up and running, but when I try to use Midori to go to any website, I get this error: "Cannot Resolve Hostname." How do I fix this? I'm new to Debian and the LXDE desktop.

timothy3592
Posts: 64
Joined: Wed Jun 13, 2012 6:06 am

Re: Cannot Resolve Hostname

Tue Jul 03, 2012 4:59 pm

This is usually a DNS problem. Assuming you plugged the LAN cable into the pi and let it connect on its own, your router should have handed out an IP address and the IP of a DNS server (usually itself). You can check /etc/resolv.conf and see if the text "nameserver" appears at all followed by an IP address. If it doesn't you can add one manually (for example google's DNS at 8.8.8.8) using the command "echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf". You should also check to see if you have a IP address via the command "ifconfig eth0" if the Inet: field is blank then you don't have an IP. The easiest way to fix the missing IP is to connect to the router again with "sudo dhclient eth0" which may also fix the missing DNS. If you have both a DNS and an IP and the pi is securely plugged into the ethernet cable, then the problem lies with the router. In that case, plug it into another computer and see if it works. See if that works, if not then at least your closer to diagnosing the problem

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Cannot Resolve Hostname

Mon Dec 10, 2012 10:11 am

I am having a similar problem. I can not 'find' the hostname of the raspberry pi from another computer.

Code: Select all

>>> a('10.0.128.2')[0]

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    a('10.0.128.2')[0]
herror: [Errno 11004] host not found
where a = gethostbyaddr
This is the output from the important files:

/etc/hostname:

Code: Select all

CMDoverwatch
/etc/hosts:

Code: Select all

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

127.0.1.1	CMDoverwatch
/etc/resolv.conf:

Code: Select all

nameserver 10.0.128.1
nameserver 8.8.8.8
Router page 1:

Code: Select all

ID	Client Name	MAC Address	Assigned IP	Lease Time
1	XXXXXX	10-9A-DD-BC-8F-D2	10.0.128.100	01:44:04
2	CMDoverwatch	00-0D-A5-AF-2B-5D	10.0.128.2	Permanent
Any idea why I can't resolve hostname when the router can? This has puzzled me for ages considering that it is so simple to change the hostname in all the youtube videos I have watched.

there is no firewall on the router, no blocking of any protocol. This to me should work...but it doesn't.

HELP! :(

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia

Re: Cannot Resolve Hostname

Tue Dec 11, 2012 6:10 am

@wallarug your hostname will appear in your router when the Raspberry Pi and your router communicate (DHCP) to negotiate the IP address of your Pi. This is different to another computer being able to find the hostname of the Pi. When you use a hostname on a computer (say www.rapberrypi.org) your computer queries the configured DNS server to turn the address into an IP address. Typically, you will use the DNS server of your ISP. Most ISPs won't allow you to add records to their DNS. Some routers will allow you to have local DNS entries (most wont). You can get your computer to convert hostnames in to IP addresses using the /etc/hosts file (or equivalent).

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Cannot Resolve Hostname

Tue Dec 11, 2012 6:22 am

AndyD wrote:@wallarug your hostname will appear in your router when the Raspberry Pi and your router communicate (DHCP) to negotiate the IP address of your Pi. This is different to another computer being able to find the hostname of the Pi. When you use a hostname on a computer (say http://www.rapberrypi.org) your computer queries the configured DNS server to turn the address into an IP address. Typically, you will use the DNS server of your ISP. Most ISPs won't allow you to add records to their DNS. Some routers will allow you to have local DNS entries (most wont). You can get your computer to convert hostnames in to IP addresses using the /etc/hosts file (or equivalent).
I have just posted over on the E14 forums some information about the router and the settings I am using:
http://www.element14.com/community/thre ... 1?tstart=0

The DNS settings on the router **should** use the router for DNS. I don't understand why I can get every-other device but the raspberrypi.

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK

Re: Cannot Resolve Hostname

Tue Dec 11, 2012 7:20 am

If you only need to access the pi from 1 or two other machines, the easiest way is to put the pi's hostname and IP address into the other machines hosts file. Where it is varies by machine OS, windows buries it about 4 layers down, typically in c:\windows\system32\drivers\etc\ . If you need to be able to do it for a whole load of machines, installing samba on the pi, is probably the easiest way of achieving it. Using a dynamic IP address on the Pi probably isn't a good idea if you want to be able to access it reliably over a LAN.

Resolving hostnames on a local lan always has been a pain because there isn't a central authority. Windows has done it about 3 different ways over the years. Routers don't usually deal with lan hostnames.

Ever wonder what the service bonjour did on your windows machine ? Its not standard - its installed with some apple software (principally iTunes) so your PC can find your iPod/Iphone on the network.

The OP's problem is entirely unrelated, that is a networking setup shortcoming or his router not doing the business. That is a DNS problem, resolving hostnames on a lan that doesn't have a central file/DNS server isn't.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Cannot Resolve Hostname

Tue Dec 11, 2012 7:47 am

pluggy wrote:If you only need to access the pi from 1 or two other machines, the easiest way is to put the pi's hostname and IP address into the other machines hosts file. Where it is varies by machine OS, windows buries it about 4 layers down, typically in c:\windows\system32\drivers\etc\ . If you need to be able to do it for a whole load of machines, installing samba on the pi, is probably the easiest way of achieving it. Using a dynamic IP address on the Pi probably isn't a good idea if you want to be able to access it reliably over a LAN.

Resolving hostnames on a local lan always has been a pain because there isn't a central authority. Windows has done it about 3 different ways over the years. Routers don't usually deal with lan hostnames.

Ever wonder what the service bonjour did on your windows machine ? Its not standard - its installed with some apple software (principally iTunes) so your PC can find your iPod/Iphone on the network.

The OP's problem is entirely unrelated, that is a networking setup shortcoming or his router not doing the business. That is a DNS problem, resolving hostnames on a lan that doesn't have a central file/DNS server isn't.
So what I should do is:
1. Static IP on the RPi (s) that I am using.
2. Add there hostnames to the file called hosts in C://Windows/system32/drivers/etc/hosts
3. Make sure that the router knows that they have static IP addresses (so IPs not in range)

And from what your saying, the python module command:

Code: Select all

>>> socket.gethostbyaddr('<ip_address>')
... should work.

Is that all correct?

EDIT: What if I am using multiple machines to connect to the RPis? Then I have a problem.

EDIT 2: How come this works on my friend's home network?

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia

Re: Cannot Resolve Hostname

Tue Dec 11, 2012 10:21 am

wallarug wrote: EDIT: What if I am using multiple machines to connect to the RPis? Then I have a problem.
Why do you have a problem? As long as the hosts file on each machine has the same entries for your Raspberry Pi(s) then all should work.
wallarug wrote: EDIT 2: How come this works on my friend's home network?
My guess would be that your friends router works as a local DNS. You tell us what is different with your friends home network! It is a bit hard for us to guess!

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK

Re: Cannot Resolve Hostname

Tue Dec 11, 2012 7:07 pm

wallarug wrote:
So what I should do is:
1. Static IP on the RPi (s) that I am using.
2. Add there hostnames to the file called hosts in C://Windows/system32/drivers/etc/hosts
3. Make sure that the router knows that they have static IP addresses (so IPs not in range)

And from what your saying, the python module command:

Code: Select all

>>> socket.gethostbyaddr('<ip_address>')
... should work.

Is that all correct?

EDIT: What if I am using multiple machines to connect to the RPis? Then I have a problem.

EDIT 2: How come this works on my friend's home network?
The hosts file needs a line with both the IP address and the hostname. Its fairly simple, it checks the local hosts file before it goes looking at DNS. You can override a website's DNS entry if you wish using hosts (which is how some malware does its dirty business)

Personally I give my pi's static IPs and have desktop shortcuts going to the IP addresses.

Most routers have a limited range of DHCP IP addresses they dole out, almost always in the middle of the 255 addresses of the subnet. Using the last octet at the low end (say below 50) or at the high end (above 200) is a pretty safe bet it won't run into the DHCP system.

Python isn't my strong suit, I'll leave that one.

The EDITS have been answered by an earlier poster.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

Steven boyd
Posts: 1
Joined: Mon Oct 14, 2013 11:47 pm

Re: Cannot Resolve Hostname

Mon Oct 14, 2013 11:58 pm

I solved this problem by not entering my wireless network key but instead using the option of push button on Ap router. Connected straight away with no more problems even using wireless keyboard and mouse (via powered USB hub)

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Cannot Resolve Hostname

Tue Oct 15, 2013 8:27 am

I think that might have been having a router problem back then. After a firmware update all has come good and I can get IPs by hostname. This does not work outside the network though. That is expected (No DNS Server).

User avatar
winkleink
Forum Moderator
Forum Moderator
Posts: 288
Joined: Mon Nov 07, 2011 9:12 am
Location: UK

Re: Cannot Resolve Hostname

Tue Oct 15, 2013 9:50 am

I had a similar problem with an Ubuntu laptop, so no Raspberry Pi a few years ago.
I didn't personally figure out exactly what was causing the problem but I believe it is a combination of IPv6 being enabled on the computer, using an old router and using the name servers provided by your ISP.
I updated my router to use OpenDNS setting 208.67.222.222 & 208.67.220.220 as the name servers and that fixed the problem
I suspect the Google DNS setting will work just as well.
Twitter:Winkleink
Google+: Winkleink

Return to “Beginners”