Ubuntu – Can’t browse the internet nor ping a host, but dig works

dnsnetworking

I am not able to browse any websites. Please take a look at the following error:

karthick@karthick:~$ ping www.google.com                         
ping: unknown host www.google.com

Update

karthick@karthick:~$ dig www.google.com

; <<>> DiG 9.7.1-P2 <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26402
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 4, ADDITIONAL: 4

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

;; ANSWER SECTION:
www.google.com.     238583  IN  CNAME   www.l.google.com.
www.l.google.com.   97  IN  A   74.125.236.50
www.l.google.com.   97  IN  A   74.125.236.48
www.l.google.com.   97  IN  A   74.125.236.52
www.l.google.com.   97  IN  A   74.125.236.49
www.l.google.com.   97  IN  A   74.125.236.51

;; AUTHORITY SECTION:
google.com.     146866  IN  NS  ns3.google.com.
google.com.     146866  IN  NS  ns2.google.com.
google.com.     146866  IN  NS  ns1.google.com.
google.com.     146866  IN  NS  ns4.google.com.

;; ADDITIONAL SECTION:
ns2.google.com.     317814  IN  A   216.239.34.10
ns1.google.com.     317814  IN  A   216.239.32.10
ns3.google.com.     317814  IN  A   216.239.36.10
ns4.google.com.     317814  IN  A   216.239.38.10

;; Query time: 5 msec
;; SERVER: 172.29.39.212#53(172.29.39.212)
;; WHEN: Wed Aug  3 15:30:38 2011
;; MSG SIZE  rcvd: 268

Output:

karthick@karthick:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr bc:30:5b:c4:fd:dc  
inet addr:172.29.XX.XX  Bcast:172.29.XX.XXX  Mask:255.255.255.0
inet6 addr: fe80::be30:5bff:fec4:fddc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:1757954 errors:0 dropped:0 overruns:0 frame:0
TX packets:1422948 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:1329324192 (1.3 GB)  TX bytes:1231317787 (1.2 GB)
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:10528 errors:0 dropped:0 overruns:0 frame:0
TX packets:10528 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0 
RX bytes:768164 (768.1 KB)  TX bytes:768164 (768.1 KB)

karthick@karthick:~$ sudo iptables -nvL
[sudo] password for karthick: 
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target     prot opt in     out     source           destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target     prot opt in     out     source           destination         

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target     prot opt in     out     source               destination 

Best Answer

I have found that the problem lies in this file /etc/nsswitch.conf. In that file dns entry was missed. After adding that entry i am able to browse the sites.

NSSWITCH