0

I am currently using the Raspberry Pi to create a wireless controlled robot that I plan on controlling using an HTML GUI.

I followed some instructions online and made my Raspberry Pi act as a wireless AP and gave it a static IP address. Now the problem is that I have got the wireless AP working and can connect to my Raspberry Pi. The problem is that the static IP address isn't kicking in, so I have to manually enter the command "$ sudo ifdown wlan0; sudo ifup wlan0; sudo service hostapd restart" and only then does it start to work (example below). I have also entered a copy of the contents in etc/network/interfaces.

I have only been playing with the Raspberry Pi for about a month now, so I am still fairly new to it, but I really need a solution to this problem so that I can load the static IP address on start-up.

The Problem and My Temporary Solution

pi@raspberrypi ~ $ hostname -I
192.168.1.108
pi@raspberrypi ~ $ sudo ifdown wlan0
pi@raspberrypi ~ $ sudo ifup wlan0
pi@raspberrypi ~ $ sudo service hostapd restart
[ ok ] Stopping advanced IEEE 802.11 management: hostapd.
[ ok ] Starting advanced IEEE 802.11 management: hostapd.
pi@raspberrypi ~ $ hostname -I
192.168.1.108 10.0.0.1

Content in /etc/network/interfaces

auto lo
iface lo inet loopback
iface eth0 inet dhcp
iface wlan0 inet static
---address 10.0.0.1
---netmask 255.255.255.0

The following part is in my file but commented out
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

2
  • hint: "iface eth0 inet dhcp" is saying "ask the dhcp function in the router to assign an IP address" which is where 192.168.1.108 is coming from. Probably want to load it the same way as wlan0, but I've not done this personally.
    – Tyson
    Commented Aug 15, 2014 at 16:42
  • With this comment i no longer understand your question, I thought you wanted a static IP.
    – Tyson
    Commented Aug 16, 2014 at 1:30

3 Answers 3

1

The first thing I notice is your interfaces file. When you connect to a router with a static IP address you ought to have three things:

  • IP address
  • Netmask
  • Default gateway

You put the address as 10.0.0.1. If you have a router that uses a 10.0.0.0 public network address translation (NAT) network, with a 255.255.255.0 netmask, the router's IP address is more than likely 10.0.0.1, so I would assume that that'd also be an issue. Change the interfaces file to look like this:

auto lo
iface lo inet loopback
iface eth0 inet dhcp
iface wlan0 inet static
    address 10.0.0.2
    netmask 255.255.255.0
    gateway 10.0.0.1

Finally if you've connected an Ethernet cable into the jack (eth0) on the Raspberry Pi and it's obtaining an IP address of 192.168.1.108, more than likely your router is on the 192.168.1.0 network and so you should change

address 10.0.0.2
...
gateway 10.0.0.1

to

address 192.168.1.2
...
gateway 192.168.1.1

If someone is already using the address 192.168.1.2 you might get some odd behavior. Log into your router and select an IP address that is not being used AND is not part of the DHCP "pool" (sometimes also called range). You can log into your router by going to 192.168.1.1 in your address bar like as though you were going to google.com. It will prompt you for a username and password which the deaults are in the product manual (google for it) or under/on the side of the router.

1

The easiest way I found getting static IP is from the router itself. The router is the one that fixes IP for all devices. Each router, in its admin page, will have Static Routes option. I copied the MAC Address for the Pi WiFi module and then fixed the IP for the same. This way there is no possibility of the ip in your file being assigned to some other device.

0

I found the answer just following the instructions on the last page of a sirlagz post. I did this and it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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