Ubuntu Server 12.04 can access LAN but not internet

linux-networkingnetworkingUbuntu

Using Ubuntu Server (12.04) via command line, I can access the LAN (e.g. ping local machines) but not the internet (e.g. "ping google.com" or "sudo apt-get update"). How should I troubleshoot this?

I'll start by saying that I was able to access the internet (using sudo apt-get) but after some 'configuration work' I can now only access the LAN. It previously worked when I had a DHCP connection. I noticed the problem some time after I'd switched to a static IP. I've switched back to DHCP but with no luck.

/etc/network/interfaces currently looks like this:

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet dhcp
wpa-ssid myrouterssid
wpa-psk myrouterpassword

ifconfig -a reports:

eth0      Link encap:Ethernet  HWaddr 00:1e:7a:d9:1b:07
          inet addr:192.168.0.101  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::21e:68ff:fed9:1b07/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:217 errors:0 dropped:0 overruns:0 frame:0
          TX packets:414 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:23826 (23.8 KB)  TX bytes:47487 (47.4 KB)
          Interrupt:16

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:720 (720.0 B)  TX bytes:720 (720.0 B)

virbr0    Link encap:Ethernet  HWaddr 86:19:a7:9b:a6:4a
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 00:94:ea:de:1f:78
          inet addr:192.168.0.3  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::216:eaff:fede:1f78/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:328 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:58008 (58.0 KB)  TX bytes:1852 (1.8 KB)

"ping 192.168.0.1" (gateway) works. "ping 192.168.0.100" (self) works. "ping 192.168.0.7" (another PC) works. "ping google.com" reports "ping: unknown host google.com". "ping 173.194.34.72" (google.com) fails.

I can also SSH to this ubuntu server from another PC (although it now waits about 20 seconds before it asks for the password whereas it was previously instantaneous – significant?)

EDIT: route -n reports:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    100    0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

Best Answer

Your resolv.conf entries are probably bad. You should determine the proper address(es) and write them manually in resolv.conf (removing current entries).
I guess that DNS server is the same as gateway (192.168.0.1).

You can try this before making changes in resolv.conf by command:

dig @192.168.0.1 google.com

Above command tries to ask 192.168.0.1 (not Your current set in resolv.conf) for google.com IP, if there is working DNS server the answer will contain following text:

;; ANSWER SECTION:
google.com.             300     IN      A       173.194.35.162
google.com.             300     IN      A       173.194.35.161
google.com.             300     IN      A       173.194.35.164
[...]

If it fails try entering different IPs in dig command

Another problem is that trying to ping google by IP fails (as you wrote). To make a quick test why it fails try following command:

traceroute 173.194.35.162

You'll see which one of the hops causes the problem. It's possible that Your gateway is not working.