6

I have been trying to set up a static IP for my Raspberry Pi. From what I understand I need to change the interfaces file at /etc/network/interfaces. My file (based on this tutorial) looks like this:

auto lo 
iface lo inet loopback 
auto eth0

iface eth0 inet static 
    address 192.168.1.184 
    gateway 192.168.1.1 
    netmask 255.255.255.0

I then type sudo /etc/init.d/networking restart, which gives me this message:

Running /etc/init.d/networking restart is deprecated because it may not re-enable some interfaces

I then do sudo reboot.

With the above settings, I do not receive any Internet access on my Raspberry Pi. Can anyone point out where I am going wrong? I have successfully managed to setup static IPs on my Windows/Ubuntu machine, phone and iPad.

  • so what is your question? – gurcanozturk May 25 '13 at 22:44
  • lol i see you point edited... – Harpal May 25 '13 at 23:18
3

After "ifup" or "networking restart" command, you have to check your network interfaces with "ifconfig" or "ip addr" command. Also checking routes of device may be useful.

Sample "ifconfig eth0" output:

root@pi:~# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr b8:27:eb:30:42:ef  
          inet addr:192.168.1.5  Bcast:0.0.0.0  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:243477 errors:0 dropped:0 overruns:0 frame:0
          TX packets:102566 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:197482011 (188.3 MiB)  TX bytes:11086659 (10.5 MiB)

Sample "ip addr" output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether b8:27:eb:30:42:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.5/24 scope global eth0

Sample "route -n" output:

root@pi:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

To connect to internet through "eth0" interface, you should see the line with "UG" flag correctly. That line means that every packet from the local network will go to outside through 192.168.1.1 and eth0 interface. Without this line device can't know where to go.

If there is no route line which has 0.0.0.0 destination, you can test with adding by manually with "route command" ;

route add default gw 192.168.1.1 netmask 255.255.255.0 eth0

Also check your DNS settings by "/etc/resolv.conf" file. Because you not mentioned how you test the internet connection maybe your system does not resolve addresses. Nameserver line should contains a DNS server IP address. To test it you can use Google's DNS server IP addresses. (8.8.8.8 or 8.8.4.4)

root@pi:~# cat /etc/resolv.conf 
nameserver 192.168.1.1
  • Google saves the day, changing the nameserver worked for me. – Mateo Jul 10 '13 at 1:10
1

Restarting networking may work, but I've never had much luck with it.

I would recommend using the ifup command. Once you have set up your /etc/network/interfaces as you have, try the following:

sudo ifdown eth0

sudo ifup eth0

Example /etc/network/interfaces:

dhcp (automatic)

auto lo
iface lo inet loopback
iface eth0 inet dhcp

static (manual)

auto lo
iface lo inet loopback
iface eth0 inet static
address        192.168.1.200
netmask        255.255.255.0
gateway        192.168.1.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.