It all depends upon your configuration.
You should first determine in a case like this if your iPhone or other device has been assigned a valid DHCP address.
If you see a value like 169.x.x.x, you have not been assigned a valid DHCP address. This may occur for many reasons, most often because the DHCP server component of your router is not issuing them, or your device is not commmunicating with it. Valid DHCP addresses are generally in the ranges of…
• class A: 10.0.0.1 through 10.255.255.255
• class B: 172.16.0.1. through 172.31.255.255 and seldom used, and
• class C: 192.168.0.1 through 192.168.255.255
If you have a valid DHCP address, then the issue is likely that your router is not properly configured, in that it does not have valid DNS server addresses stored in its configuration files.
Generally, a router or gateway requires that you configure its assigned address, a valid subnet mask, and primary and secondary DNS servers. While you can use any valid DNS address for primary, secondary, tertiary and subsequent server entries, by convention, most technicians set the pair assigned by the internet service provider for your service area. In Eugene OR, for example, Comcast DNS addresses are set to…
• primary: 68.87.69.146 and
• secondary: 68.87.85.98
Check to see that your router or gateway configuration contains such information, as the result of being issued a valid DHCP address but not being able to identify a DNS server leads to the sort of issue outlined by the original poster.
You can easily determine if this is the case by querying a known site by its numeric address, rather than by its canonical name. If one takes you to the site but the other fails to do so, then you have the DNS issue I referred to.