connect: Network is unreachable? - ping

The following line is wrong:

iface eth0 inet static
    address 192.168.0.5
    netmask 255.255.255.0
    network 192.168.1.0 <<<<<<<<<<<<<<<<<<<<<<<< It should be 192.168.0.0
    broadcast 192.168.0.255
    post-up iptables-restore < /etc/iptables.up.rules
    dns-nameservers 192.168.0.5 8.8.8.8

Also, there doesn't seem to be any default gateway setup.

Not having more info about your network, I would suggest adding the following line at the end:

    gateway <YOUR.ROUTER.IP.ADDRESS>

So, assuming your router ip address is 192.168.0.1, this would be the whole entry:

iface eth0 inet static
    address 192.168.0.5
    netmask 255.255.255.0
    network 192.168.0.0
    broadcast 192.168.0.255
    post-up iptables-restore < /etc/iptables.up.rules
    gateway 192.168.0.1
    dns-nameservers 192.168.0.5 8.8.8.8

The problem is ,you need to set your default gateway

1)Take terminal

2)sudo su

3)Type in

$ route add default gw (eg:192.168.136.1) eth0

4)sometimes you will be able to ping(ping 8.8.8.8) but no internet connection in the browser,then

5)go to 'nano /etc/resolv.conf'

6)Add

7)nameserver 8.8.8.8

8)nameserver 192.168.136.0(gateway) or nameserver 127.0.1.1

9)sudo /etc/init.d/networking restart or service networking restart


You may need to add a default gateway. As a root user, execute this command.

E.g.

root@localhost:~# route add default gw 172.23.5.1

You can get the first 3 octets, 172.23.5 from eth0/eoM

Then ping an IP to see if connection works.

root@localhost:~# ping 10.56.94.81    
PING 10.56.94.81 (10.56.94.81) 56(84) bytes of data.    
64 bytes from 10.56.94.81: icmp_seq=1 ttl=62 time=0.203 ms    
64 bytes from 10.56.94.81: icmp_seq=2 ttl=62 time=0.197 ms    
64 bytes from 10.56.94.81: icmp_seq=3 ttl=62 time=0.210 ms    
^C    
--- 10.56.94.81 ping statistics ---    
3 packets transmitted, 3 received, 0% packet loss, time 2033ms    
rtt min/avg/max/mdev = 0.197/0.203/0.210/0.012 ms