Voilà, testé de mon côté, ça fonctionne 
[code]#!/bin/bash
Wifi Hotspot script
Quickly create a wireless hotspot to share access from your wired network
hardware requirements : 1 ethernet NIC + 1 wireless NIC (must support hostap mode)
software requirements : iptables, hostapd, dnsmasq, dhclient (or dhcpcd)
This is a standalone script, it will not use your existing configuration files
(for wpa_supplicant or hostapd)
Wireless will use WPA/WPA2 encryption.
BEFORE STARTING THIS SCRIPT :
- you must have root rights
- stop your wireless connection manager (networkmanager, wicd, etc…)
- disable your firewall
- disable power management (prevent the computer to go into suspend mode when unused)
This script has been tested on Debian 7 (Wheezy), but should work on other Linux systems with minor adaptations.
this is the wireless interface we use to create our new AP
WLAN_AP=« wlan0 »
your new AP’s SSID
WLAN_AP_SSID=« MY_NEW_SSID »
Change passphrase here
WLAN_AP_PASSPHRASE=« myinsecurepassphrase »
change channel if needed
WLAN_AP_CHANNEL=6
WLAN_AP_IP=« 192.168.7.1 »
WLAN_AP_DHCP_RANGE=« 192.168.7.10,192.168.7.20 »
temp files (will contain clear passphrases!)
HOSTAP_TEMP_CONF=« /root/hostap_temp.conf »
Path for used commands (adapt to your system)
DHCPCD=« /sbin/dhclient »
HOSTAPD=« /usr/sbin/hostapd »
DNSMASQ=« /usr/sbin/dnsmasq »
IPTABLES=« /sbin/iptables »
Main program
check if we are root
if [[ $EUID -ne 0 ]]; then
echo basename $0 « : must be run as root! » 1>&2
exit 1
fi
check for software we need
if [[ ! -x $DHCPCD ]]; then
echo « FATAL: $DHCPCD not found! »; exit 1
fi
if [[ ! -x $HOSTAPD ]]; then
echo « FATAL: $HOSTAPD not found! »; exit 1
fi
if [[ ! -x $DNSMASQ ]]; then
echo « FATAL: $DNSMASQ not found! »; exit 1
fi
if [[ ! -x $IPTABLES ]]; then
echo « FATAL: $IPTABLES not found! »; exit 1
fi
check for wireless interfaces
ifconfig $WLAN_STA 1>&2>/dev/null
if [[ $? -ne 0 ]]; then
echo « FATAL: Wireless interface $WLAN_STA unavailable! »; exit 1
fi
some cleanup
kill existing wireless connections
$DHCPCD -x $WLAN_AP 2>/dev/null
killall wpa_supplicant 2>/dev/null
kill running hostapd daemon if it exists
killall hostapd 2>/dev/null
kill dnsmasq dhcp
killall dnsmasq 2>/dev/null
empty existing temp.conf files, for security
$HOSTAP_TEMP_CONF
stop the repeater? then just exit, we have already cleaned up!
if [ « $1 » == « stop » ]; then
echo « Repeater has been stopped. »
exit 0;
fi
else, continue and create our AP
echo "Please wait, starting up… "
create temp wpa_supplicant.conf file for our STA interface
cat >$HOSTAP_TEMP_CONF <<EOF
interface=$WLAN_AP
country_code=FR
ieee80211d=1
ssid=$WLAN_AP_SSID
hw_mode=g
channel=$WLAN_AP_CHANNEL
wme_enabled=0
macaddr_acl=0
auth_algs=1
wpa=2
wpa_passphrase=$WLAN_AP_PASSPHRASE
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
EOF
start hostapd daemon to create the « hotspot » AP
$HOSTAPD -B $HOSTAP_TEMP_CONF
if [[ $? -ne 0 ]]; then
echo « FATAL: unable to start $WLAN_AP interface (hostapd)! »; exit 1
fi
assign an IP address to the AP, and start a new DHCP server
ifconfig $WLAN_AP $WLAN_AP_IP netmask 255.255.255.0
$DNSMASQ --dhcp-range=$WLAN_AP_DHCP_RANGE --interface=$WLAN_AP
if [[ $? -ne 0 ]]; then
echo « FATAL: unable to start dhcp server! (dnsmasq) »; exit 1
fi
enable packet forwarding and add firewall rules to allow forwarding packets
between our 2 network interfaces.
IF_IN=« eth0 »
IF_OUT=$WLAN_AP
warning : permissive firewall rules here. Adapt to your liking.
sysctl -w net.ipv4.ip_forward=1
$IPTABLES -F
$IPTABLES -X
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -t nat -A POSTROUTING -o $IF_IN -j MASQUERADE
$IPTABLES -A FORWARD -i $IF_IN -o $IF_OUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -A FORWARD -i $IF_OUT -o $IF_IN -j ACCEPT
echo « ------------------------------------------------------------------------- »
echo « Wireless Access Point "$WLAN_AP_SSID" is up! »
echo « To kill it : basename $0 stop »
exit 0
[/code]