MacBook DNS works behind some routers, doesn't behind others I've found WiFi routers where I cannot open domains, but ping IP addresses just fine. This means I can't browse websites. This happens only on my Macbook, and these connections work fine for Windows laptops. How do I fix this?

I have two internet AP at my office, one is problematic, one isn't. I also have a wifi at home that works, but another wifi at my friend's house doesn't work.

Details

These tests were performed on the same machine. I can switch to either WiFi and this always happens.

Routers that are fine:

$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=48 time=246.502 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=48 time=256.395 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=48 time=233.746 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=48 time=391.504 ms
^C
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 233.746/282.037/391.504/63.709 ms

$ ping google.com
PING google.com (172.217.24.110): 56 data bytes
64 bytes from 172.217.24.110: icmp_seq=0 ttl=56 time=301.756 ms
64 bytes from 172.217.24.110: icmp_seq=1 ttl=56 time=146.550 ms
64 bytes from 172.217.24.110: icmp_seq=2 ttl=56 time=159.926 ms
64 bytes from 172.217.24.110: icmp_seq=3 ttl=56 time=160.761 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 146.550/192.248/301.756/63.475 ms

$ nslookup google.com
Server:     8.8.8.8
Address:    8.8.8.8#53

Non-authoritative answer:
Name:   google.com
Address: 74.125.200.113
Name:   google.com
Address: 74.125.200.138
Name:   google.com
Address: 74.125.200.101
Name:   google.com
Address: 74.125.200.102
Name:   google.com
Address: 74.125.200.100
Name:   google.com
Address: 74.125.200.139


$ dig google.com

; &lt;&lt;&gt;&gt; DiG 9.8.3-P1 &lt;&lt;&gt;&gt; google.com
;; global options: +cmd
;; Got answer:
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 52892
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com.            IN  A

;; ANSWER SECTION:
google.com.     299 IN  A   172.217.24.110

;; Query time: 254 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Oct 20 14:28:26 2016
;; MSG SIZE  rcvd: 44


Routers that are problematic:

$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=43 time=275.333 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=43 time=167.851 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=43 time=160.801 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=43 time=193.566 ms
^C
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 160.801/199.388/275.333/45.511 ms

$ ping google.com
ping: cannot resolve google.com: Unknown host

$ nslookup google.com
;; connection timed out; no servers could be reached

$ dig google.com

; &lt;&lt;&gt;&gt; DiG 9.8.3-P1 &lt;&lt;&gt;&gt; google.com
;; global options: +cmd
;; connection timed out; no servers could be reached
You have statically set network adapter settings (IP address, DNS server, etc.) and you are moving between different networks.  Keep in mind, though many networks are similar in configuration, no network is exactly alike.

There are many different reasons why you experienced what you did, and it would be impossible without actually looking at your individual configuration, but suffice to say the static setup you had working in one network wasn't exactly right for the other network and may have been good enough for the third network, and so on.

This is why it's good (among other reasons like IP address conflicts), when going between various networks, to obtain the network settings via DHCP.  This way, there can be no conflicts.