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

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
  • 454
  • 2
  • 7
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,592
  • 19
  • 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
  • 60,325
  • 17
  • 117
  • 234
Colin Wray
  • 31
  • 1
2

Disable ifplugd, then static IP address should work.

Lawrence
  • 2,692
  • 15
  • 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
  • 131
  • 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
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