13

I am currently trying to set up my Raspberry Pi as an Access Point using hostapd using the following directions:

RPI Wireless Hotspot

Unfortunately, my static IP Address refuses to set at startup. Below is the contents of my /etc/network/interfaces:

auto lo

iface lo inet loopabck
iface eth0 inet dhcp

iface wlan0 inet static
address 192.168.42.1
broadcast 192.168.42.255
netmask 255.255.255.0

up iptables-restore < /etc/iptables.ipv4.nat

Oddly enough, if I run the following command after boot, everything works fine:

sudo ifconfig wlan0 192.168.42.1

Does anybody see any glaring issues that I may be missing? It's been so long since I've worked with Linux configuration that I feel that I'm missing something easy.

Justin Niessner
  • 231
  • 1
  • 2
  • 5
  • As a quick workaround you could just run the ifconfig as a boot script after interfaces are connected or the last boot scripts. Did you upgrade the firmware to latest? Not aptitude update but raspi script for firmware. That fixes a few interface issues. – Piotr Kula Sep 19 '13 at 19:24
  • @ppumkin - I'm still a Raspberry Pi n00b. What's the command to run the raspi script to update the firmware? – Justin Niessner Sep 19 '13 at 19:29
  • 4
    https://github.com/Hexxeh/rpi-update Go there and read it. Also after restart do an aptitude update too. – Piotr Kula Sep 19 '13 at 19:40
  • @ppumkin - I've run both updates and neither took care of the issue. Looks like I'm going to have to go with the workaround for now. – Justin Niessner Sep 19 '13 at 20:24
  • The last resort is trying to burn the Rasbpian from fresh using the latest image. Do the updates again and see if that helps. That helped with mi WiFi problems. – Piotr Kula Sep 19 '13 at 20:51
  • don´t you need to enter a "gateway" address as well? – HectorLector Sep 20 '13 at 13:27
  • @HectorLector - The RaspberryPi will be serving as the Gateway (it's going to be serving as a wireless Access Point). – Justin Niessner Sep 20 '13 at 14:50
  • Your interface is not set up automatically at boot. Try `ifup wlan0` just after boot. If it works, then add `auto wlan0` in /etc/network/interfaces. – M Noit Sep 21 '13 at 11:40
  • @MNoit - I had actually tried adding `auto wlan0` to the top of the /etc/network/interfaces file to no avail. – Justin Niessner Sep 21 '13 at 20:23
  • Have you solved your problem? If so, please mark the answer that helped you, or if you solved it on your own, create a self-answer and mark it as such. We are trying to get the site Q:A ratio up and marking answers is what does that. If you resolved it and mark then people in the future will be able to profit from what you did *and* it helps move the site closer to graduation. Thanks! – RPiAwesomeness Mar 23 '14 at 16:41
  • @RPiAwesomeness - I actually never did solve my problem and the new answer that have been posted didn't fix the issue either. Unfortunately I've given up on the RPi project that I was trying to get working with this. – Justin Niessner Mar 24 '14 at 13:43
  • I'm sorry to hear that you weren't able to get this working. It always stinks when you have to give up on a project. Hope we can help in the future. – RPiAwesomeness Mar 24 '14 at 15:34

9 Answers9

4

My interfaces file look a bit different but works for me all the time.

auto lo

iface lo inet loopback
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0

iface wlan0 inet static
    address 192.168.1.123
    netmask 255.255.255.0
    network 192.168.1.1
    broadcast 255.255.255.255
    gateway 192.168.1.1
    wpa-ssid "SSID"
    wpa-psk "PASSWORD"

Maybe this might help

karan
  • 399
  • 1
  • 7
  • Shouldn't the broadcast IP look like this: `192.168.1.255`, the 255 is just on last place because otherwise you don't broadcast on all devices of your router. – XandruCea Dec 31 '13 at 17:34
  • I believe the missing piece from the original question was the above "auto wlan0" line. You may also want to add a "dns-nameservers 8.8.8.8" (as an example) after the broadcast line. – joat Jan 25 '14 at 22:53
2

I suspect that hostapd reinitialises the interface which is what causes this to fail. You can manually add the ifconfig command to the /etc/rc.local file which will auto-execute it on boot.

Fred
  • 4,422
  • 16
  • 29
2

It is definitely a race condition in raspbian jessie, which has stopped using runlevel based init in favour of a package-tree-based "start everything at the same time" approach. I think I might have got round it by putting these lines in /etc/rc.local:

/sbin/ifdown wlan0
/sbin/ifup wlan0
/sbin/ifconfig wlan0 192.168.42.1
/usr/sbin/service isc-dhcp-server start

Time will tell I suppose.

goldilocks
  • 56,430
  • 17
  • 109
  • 217
Colin Wray
  • 31
  • 1
  • OK, unix certainly had runlevels and telinit when I worked on it from 1984 to 1992, but have regretfully only returned recently. Maybe if we go through all the things it is not, someone will explain what it actually **is**. (My fix is still working, but I don't like it). – Colin Wray Nov 11 '15 at 15:31
  • I decided it was a race condition because there are two possible outcomes of the boot sequence, and they occur randomly. – Colin Wray Nov 11 '15 at 15:40
  • Yikes. I apologize for having misread this answer backward -- that it was a problem *caused* by SysV init fixed w/ systemd. In any case, neither of them can *prevent* a race condition, since by nature many of the services they start fork and persist. Misconfiguring anything can cause a problem and what I do object to here is the implication that systemd is by nature to blame (it could be argued it has a better methodology for resolving dependencies, and it does not simply "start everything at the same time" willy-nilly -- but this is going off on a tangent)... – goldilocks Nov 12 '15 at 00:31
  • I have a slightly [unorthodox attitude toward networking on linux boxes generally](http://raspberrypi.stackexchange.com/q/37594/5538) which leaves me with little perspective on problems like this, and if you have a solution which works for you, great, but your diagnosis seems very conjectural (looks alike a race condition, walks like a race condition...but the shadow of a duck is not a duck...etc). – goldilocks Nov 12 '15 at 00:32
  • P.S. I made a very minor cosmetic edit so the system would let me undo my downvote, since it was based on a misreading. I still think you should seriously qualify your claim though, right now it is borderline hyperbole. – goldilocks Nov 12 '15 at 12:54
  • 1
    On reading my OP I can see why you thought I was blaming the system directly, and why it fired up a staunch defender like yourself. No, I think the problem must lie in the package dependency tree which they profess to be following, and which I know zero about. Somehow it must recognise the clash between ifup and hostapd. – Colin Wray Nov 13 '15 at 06:36
  • I'm not sure if I'm quite a staunch defender so much as concerned about the trickle down effect of "oh screw this newfangled init" sentiments on neophytes, something propagated a bit by Fedora users (including me...) a few years ago when systemd appeared there. I think that mostly came down to resistance to learning something new from scratch; I'm now convinced it really is a significant improvement on SysVinit. Very likely it is something in the hostapd vs. dhcpd (?) dependency, since systemd is now new to Debian and I *think* Raspbian then adds twists to dhcpd. – goldilocks Nov 13 '15 at 15:31
2

Disable ifplugd, then static IP address should work.

Lawrence
  • 2,632
  • 13
  • 14
1

I would be trying to add the following lines just above your current wirless interface config:

auto wlan0
allow-hotplug wlan0

This tells your interface config to start the wlan0 interface automatically, and that it may be inserted later (hotplug).

You may also need to add a gateway <IP Address> line as well to get routing working.

Hurgh
  • 391
  • 1
  • 2
0

Not necessarily a great solution but since I had problems with my staticip when using /etc/network/interfaces I switched to using a static ip through my router instead? Have you tried it this way as an alternative?

gray_fox
  • 121
  • 1
  • 1
  • 6
0

I follow the same tutorial to setup the WAP on my Pi.

Unfortunately, the dhcp service doesn’t start at boot. After the boot, checking the service shows that it is not running : service isc-dhcp-server status Status of ISC DHCP server: dhcpd is not running

Actually, the interface wlan0 doesn’t get an IP address and that’s why the dhcp server doesn’t start.

I follow the instruction in the link below, but it doesn’t solve the issue : http://sirlagz.net/2013/02/10/how-to-use-the-raspberry-pi-as-a-wireless-access-pointrouter-part-3b/

Then, I follow the instruction in this post : http://www.novitiate.co.uk/?p=183

nano /etc/rc.local

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

# Print the IP address
sleep 5
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
      sudo ifup wlan0                           #start wlan0 with ip adress in  /etc/network/interfaces
#      sudo service hostapd start               #not necessary if you already start hostapd as a service
      sudo service isc-dhcp-server start        #start dhcp server
exit 0

After the reboot, the DHCP server is running.

Also a possible another solution that I don't test : oops, I don't have enough reputation to post more than 2 links.

esa1966
  • 1
  • 1
0

I have had the same problem. wlan0 loses it's static ip address somehow when the dhcp server starts. Edit /etc/default/ifplugd and change to this:

INTERFACES="eth0"
HOTPLUG_INTERFACES="eth0"
Stef
  • 21
  • This answer is corrent! don't know why voted down – flotto May 31 '15 at 15:35
  • I was having the pi boot, and sometimes it would end up with a 169.xx.xx.xx address, and sometimes the static address I wanted. This is was made it reliably get the static address. Thanks @Stef! – Peter Bagnall Aug 08 '15 at 10:12
0

Alternatively, you can create a mini-service which restarts the wlan0, making sure it starts at boot before hostapd and isc-dhcp-server.

Create the new script /etc/init.d/wlan0-restart

sudo vi /etc/init.d/wlan0-restart

with the following content:

#!/bin/sh
#
#

### BEGIN INIT INFO
# Provides:          wlan0-restart
# Required-Start:    $network
# Required-Stop:     $network
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Restarts wlan0 interface
# Description:       Restarts wlan0 interface to fix problem with static address in WiFi AP
# X-Start-Before:    hostapd isc-dhcp-server
### END INIT INFO

PATH=/sbin:/usr/sbin:$PATH

do_start() {
  ifdown wlan0
  ifup wlan0
}

case "$1" in
  start)
    do_start
    ;;
  restart|reload|force-reload)
    echo "Error: argument '$1' not supported" >&2
    exit 3
    ;;
  stop)
    ;;
  status)
    ;;
  *)
    echo "Usage: $0 start|stop" >&2
    exit 3
    ;;
esac
exit 0

Then execute the following commands:

sudo chmod 755 /etc/init.d/wlan0-restart
sudo update-rc.d –f hostapd remove
sudo update-rc.d –f isc-dhcp-server remove
sudo update-rc.d wlan0-restart defaults
sudo update-rc.d hostapd defaults
sudo update-rc.d isc-dhcp-server defaults

Reboot and check that wlan0 has its static IP address and that isc-dhcpd-server is running:

pi@raspberrypi:~$ ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr e8:de:27:07:92:6a  
          inet addr:192.168.10.1  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING 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:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

pi@raspberrypi:~$ pgrep -l dhcpd
2315 dhcpd