Sometimes the Mac will have weird internet behavior,
this usually happens after you travel and connect to other wifis or gateways
The commands to attempt to fix this are:
we assume usage of Mac OS X 10.10.x (Yosemite), if you are on an older system, the commands are different
//clear arp cache
$ sudo arp -a -d
//clear dns cache
$ sudo killall -HUP mDNSResponder
ARP (Address Resolution Protocol) handles the low-level exchanges in order to map an IP address to a link layer address on demand. Sometimes if the connection has cached bad link layer addresses, clearing the cache can help.
DNS (Domain Name System) handles the conversion of domain names to IPs. for example facebook.com translates to 18.104.22.168 and this is how a computer decides how to reach facebook. In some cases, there is an attack called dns poisoning, basically what happens is that when your computer goes to the DNS master, to resolve facebook.com, the master (in this case the attacker, most likely using a man-in-the-middle attack) will return a different IP, this basically makes it so that you are unable to goto facebook or redirected to a facebook-looking site. This attack is commonly used in China to block access to certain sites. Clearing the cache sometimes helps because it forces the system to go resolve the domain name/IP addresses mapping again.