#!/bin/sh # Script to start/stop a hostapd-based access point # # Symbols for needed programs IPTABLES=/sbin/iptables IFCONFIG=/sbin/ifconfig DHCPD=/usr/sbin/dhcpd3 # Symbols for internal and external interfaces NET_INT=$2 NET_EXT=eth0 # IP address for the AP INT_ADDR=192.168.0.1 date '+%s%N' case "$1" in start) echo " This script sets up iptables to configure IP packet forwarding\n" echo " between $NET_INT and $NET_EXT" sleep 2; # Disable packet forwarding echo " Disable IP packet forwarding" echo 0 > /proc/sys/net/ipv4/ip_forward killall dhcpd3 #Set up forwarding echo " Set up IP packet forwarding" $IPTABLES -t nat -A POSTROUTING -o $NET_EXT -j MASQUERADE $IPTABLES -A FORWARD -i $NET_EXT -o $NET_INT -m state \ --state RELATED,ESTABLISHED -j ACCEPT $IPTABLES -A FORWARD -i $NET_INT -o $NET_EXT -j ACCEPT # Enable packet forwarding echo " Enable IP packet forwarding" echo 1 > /proc/sys/net/ipv4/ip_forward # Get the internal interface in the right state echo " Get the internal interface in the right state" $IFCONFIG $NET_INT down $IFCONFIG $NET_INT up $IFCONFIG $NET_INT $INT_ADDR # dhcpd needs to have a leases file available - create it if needed if [ ! -f /var/lib/dhcp3/dhcpd.leases ]; then echo " dhcpd needs to have a leases file available - create it if needed" touch /var/lib/dhcp3/dhcpd.leases fi # Bring up the DHCP server echo " Bring up the DHCP server for $NET_INT" #/etc/init.d/dhcp3-server start $DHCPD -cf /etc/dhcp3/dhcpd.conf $NET_INT # Bring up AP echo " Now Bring up AP" ;; stop) echo " Make sure that AP is stopped " sleep 2; echo " Stopping DHCP server on $NET_INT" killall dhcpd3 # Get the internal interface in the right state echo " Get the internal interface in the right state" $IFCONFIG $NET_INT down $IFCONFIG $NET_INT up $IFCONFIG $NET_INT $INT_ADDR ;; *) echo " Usage: $0 {start|stop} {AP interface name eg.eth1,wlan2..}" exit 1 ;; esac