In my case, I don't have a dhcp server but I use isc-dhcp-relay in order to reuse my master DHCP server for wireless endpoints. The advantage over one single point of control is that fixed and wireless endpoints will share the same network 192.168.0/24.
/etc/default/isc-dhcp-relay
# What servers should the DHCP relay forward requests to?
SERVERS="192.168.0.254"
# On what interfaces should the DHCP relay (dhrelay) serve DHCP requests?
INTERFACES="wlan0"
# Additional options that are passed to the DHCP relay daemon?
OPTIONS="-d"
Here are the results when using Larry's script:
sudo ./control_ap.sh start wlan0 eth0
Starting AP mode for wlan0 at address 192.168.0.200
hostapd: no process found
isc-dhcp-relay: no process found
touch: cannot touch `/var/lib/dhcp/db/dhcpd.leases': No such file or directory
Configuration file: /home/xabix/hostapd.conf
Could not set interface mon.wlan0 flags: Success
nl80211: Failed to set interface wlan0 into AP mode
nl80211 driver initialization failed.
rmdir[ctrl_interface]: No such file or directory
ELOOP: remaining socket: sock=4 eloop_data=0x85a1910 user_data=0x85a3720 handler=0x807c5e0
ELOOP: remaining socket: sock=6 eloop_data=0x85a5538 user_data=(nil) handler=0x8086770
I think the problem I am having is the same as without the script.
Do you want me to enable additional logging? (plz confirmed how to do so)
Merci
XabiX
PS: I have attached the updated script for my case. Mainly I just changed the IPTABLES=, the dhcpd with isc-dhcp-relay, .1 with .200, name of the SSID and the pwd I remove the "\"...""" entry with a pwd like WPA_SECRET=test1234)
#!/bin/sh
# Script to start/stop a hostapd-based access point
#
# Sample start call "control_ap start wlan0 eth0"
# Stop with "control_ap stop"
#
case "$1" in
start)
if [ $# -ne 3 ]
then
echo "Usage: $0 start AP_iface NET_iface"
exit 1
fi
;;
stop)
if [ $# -ne 1 ]
then
echo "Usage: $0 stop"
exit 1
fi
;;
*)
echo "Usage:"
echo "$0 start AP-iface net_iface"
echo "or"
echo "$0 stop"
exit 1
;;
esac
# Symbols for needed programs
IPTABLES=/sbin/iptables
IFCONFIG=/sbin/ifconfig
DHCPD=/etc/init.d/isc-dhcp-relay
HOSTAPD=/usr/sbin/hostapd
# Symbols for AP and external interfaces
NET_AP=$2
NET_EXT=$3
# First 3 octets of IP address for the AP
AP_ADDR=192.168.0
# IP address for nameserver
NAME_SERVER=8.8.8.8
# AP Channel, SSID, Encryption method, and Encryption secret
AP_CHANNEL=11
AP_SSID='Sweet Home 2'
WPA_SECRET=test1234
ENCRYPT_MODE=2
case "$1" in
start)
echo "Starting AP mode for $NET_AP at address $AP_ADDR.200"
# Disable packet forwarding
echo 0 > /proc/sys/net/ipv4/ip_forward
# Stop any existing hostapd and dhcpd daemons
killall hostapd
killall isc-dhcp-relay
#Set up forwarding
$IPTABLES -t nat -A POSTROUTING -o $NET_EXT -j MASQUERADE
$IPTABLES -A FORWARD -i $NET_EXT -o $NET_AP -m state \
--state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -A FORWARD -i $NET_AP -o $NET_EXT -j ACCEPT
# Enable packet forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
# Get the AP interface in the right state
$IFCONFIG $NET_AP down
$IFCONFIG $NET_AP up
$IFCONFIG $NET_AP $AP_ADDR.200
# dhcpd needs to have a leases file available - create it if needed
if [ ! -f /var/lib/dhcp/db/dhcpd.leases ]; then
touch /var/lib/dhcp/db/dhcpd.leases
fi
# Write the DHCP server configuration file
#echo "option domain-name-servers $NAME_SERVER;" > ~/dhcpd.conf
#echo "default-lease-time 600;" >> ~/dhcpd.conf
#echo "max-lease-time 7200;" >> ~/dhcpd.conf
#echo "ddns-update-style none; ddns-updates off;" >> ~/dhcpd.conf
#echo "subnet $AP_ADDR.0 netmask 255.255.255.0 {" >> ~/dhcpd.conf
#echo " range $AP_ADDR.200 $AP_ADDR.229;" >> ~/dhcpd.conf
#echo " option subnet-mask 255.255.255.0;" >> ~/dhcpd.conf
#echo " option broadcast-address $AP_ADDR.255;" >> ~/dhcpd.conf
#echo " option routers $AP_ADDR.1;" >> ~/dhcpd.conf
#echo "}" >> ~/dhcpd.conf
# Bring up the DHCP server
# $DHCPD -cf ~/dhcpd.conf $NET_AP
# Write the hostapd configuration file
cat > ~/hostapd.conf << EOF
auth_algs=1
beacon_int=100
#bridge=br0
country_code=US
ctrl_interface_group=0
ctrl_interface=/var/run/hostapd
dtim_period=2
dump_file=/tmp/hostapd.dump
fragm_threshold=2346
ht_capab=[HT40-][SHORT-GI-20][SHORT-GI-40][MAX-AMSDU-7935][DSSS_CCK-40]
ieee80211d=1
ieee80211n=1
ignore_broadcast_ssid=0
logger_stdout=-1
logger_stdout_level=2
logger_syslog=-1
logger_syslog_level=2
macaddr_acl=0
max_num_sta=255
rts_threshold=2347
wmm_ac_be_acm=0
wmm_ac_be_aifs=3
wmm_ac_be_cwmax=10
wmm_ac_be_cwmin=4
wmm_ac_be_txop_limit=0
wmm_ac_bk_acm=0
wmm_ac_bk_aifs=7
wmm_ac_bk_cwmax=10
wmm_ac_bk_cwmin=4
wmm_ac_bk_txop_limit=0
wmm_ac_vi_acm=0
wmm_ac_vi_aifs=2
wmm_ac_vi_cwmax=4
wmm_ac_vi_cwmin=3
wmm_ac_vi_txop_limit=94
wmm_ac_vo_acm=0
wmm_ac_vo_aifs=2
wmm_ac_vo_cwmax=3
wmm_ac_vo_cwmin=2
wmm_ac_vo_txop_limit=47
wmm_enabled=1
EOF
echo "interface=$NET_AP" >> ~/hostapd.conf
echo "ssid=$AP_SSID" >> ~/hostapd.conf
echo "driver=nl80211" >> ~/hostapd.conf
echo "hw_mode=g" >> ~/hostapd.conf
echo "channel=$AP_CHANNEL" >> ~/hostapd.conf
echo "wpa=$ENCRYPT_MODE" >> ~/hostapd.conf
echo "wpa_key_mgmt=WPA-PSK" >> ~/hostapd.conf
echo "wpa_pairwise=TKIP CCMP" >> ~/hostapd.conf
echo "rsn_pairwise=CCMP" >> ~/hostapd.conf
echo "wpa_passphrase=$WPA_SECRET" >> ~/hostapd.conf
# Bring up hostapd
$HOSTAPD -B ~/hostapd.conf
;;
stop)
echo "Stopping AP mode"
# Stop hostapd and dhcpd daemons
killall hostapd
killall isc-dhcp-relay
rm -f ~/hostapd.conf
#rm -f ~/dhcpd.conf
;;
esac