1. install hostapd sudo apt-get install hostapd
2. konfigurasi hostapd sudo nano /etc/hostapd/hostapd.conf seperti berikut ini:
Klik untuk menampilkan...
#konfigurasi hostapd untuk hotspot wifi
interface=wlan0
driver=nl80211
ssid=AP_pupil
hw_mode=g
channel=1
#Jika ingin menggunakan password, hilangakan tanda (#)
#pada baris-baris dibawah ini
#untuk mengganti password, ganti nilai dari wpa_passphrase=
#wpa=1
#wpa_passphrase=opensourcejaya
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP CCMP
#wpa_ptk_rekey=600
interface=wlan0
driver=nl80211
ssid=AP_pupil
hw_mode=g
channel=1
#Jika ingin menggunakan password, hilangakan tanda (#)
#pada baris-baris dibawah ini
#untuk mengganti password, ganti nilai dari wpa_passphrase=
#wpa=1
#wpa_passphrase=opensourcejaya
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP CCMP
#wpa_ptk_rekey=600
3. install dnsmasq sudo apt-get install dnsmasq, jika sudah, lakukan konfigurasi dengan perintah sudo nano /etc/dnsmasq.conf(terima kasih buat thrvers, atas koreksinya) seperti di bawah ini
Klik untuk menampilkan...
interface=wlan0
dhcp-range=net:wlan0,192.168.0.100,192.168.0.150,255.255.255.0,1440m
dhcp-option=wlan0,3,192.168.0.1
dhcp-option=wlan0,6,208.67.222.222,208.67.220.220
dhcp-range=net:wlan0,192.168.0.100,192.168.0.150,255.255.255.0,1440m
dhcp-option=wlan0,3,192.168.0.1
dhcp-option=wlan0,6,208.67.222.222,208.67.220.220
4. Cegah jangan sampai dnsmasq otomatis jalan saat boot, dengan perintah sudo update-rc.d -f dnsmasq remove
5. Sekarang kita buat script untuk mengendalikan sharing internet melalui wifi, dan simpan script tersebut di /usr/bin. Ketik perintah di terminal,
sudo nano /usr/bin/ap_ctl kemudian copy script berikut
Klik untuk menampilkan...
#!/bin/bash
# broadcasting interface
BROADCAST="wlan0"
# receiving interface broadcast is connected to
RECEIVE="eth0"
if [[ $1 == "-0" || $1 == "--start" ]]
then
## start hostapd
echo "Starting hostapd"
echo " You can view the log at /var/log/hostapd.log"
# launch hostapd daemon
hostapd -d /etc/hostapd/hostapd.conf > /var/log/hostapd.log &
## start dhcp server
echo "Starting dnsmasq"
# set IP address
ifconfig $BROADCAST 192.168.0.1
sleep 2
# launch dhcpd3 daemon
# echo "INTERFACES=$BROADCAST" > /etc/default/dhcp
# dhcpd3 $BROADCAST &
dnsmasq
elif [[ $1 == "-1" || $1 == "--stop" ]]
then
# send signal 2 to hostapd and dhcpd3
killall -2 hostapd dnsmasq
elif [[ $1 == "-2" || $1 == "--ics" ]]
then
# create iptables rules
iptables -A FORWARD -i $RECEIVE -o $BROADCAST -s 192.168.0.1/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE
# set kernel variable(s)
echo 1 > /proc/sys/net/ipv4/conf/all/forwarding
# edit kernel configuration
cp /etc/sysctl.conf /etc/sysctl.conf.ap_ctl
echo "net.ipv4.conf.default.forwarding=1" >> /etc/sysctl.conf
echo "net.ipv4.conf.all.forwarding=1" >> /etc/sysctl.conf
# restart networking
/etc/init.d/networking restart
elif [[ $1 == "-3" || $1 == "--noics" ]]
then
# remove iptables rules
iptables -D FORWARD 1
iptables -D FORWARD 1
# set kernel variable(s)
echo 0 > /proc/sys/net/ipv4/conf/all/forwarding
# revert kernel configuration
mv -i /etc/sysctl.conf.ap_ctl /etc/sysctl.conf
# restart networking
/etc/init.d/networking restart
else
echo $0
echo "A tool to manage hostapd and dhcpd3"
echo "Usage:"
echo " -0 --start Start hostapd and dhcpd3"
echo " -1 --stop Stop hostapd and dhcpd3 with signal 2"
echo " -2 --ics Activate internet connection sharing"
echo " between specified interfaces"
echo " -3 --noics Undo internet connection sharing settings"
fi
exit 0
# broadcasting interface
BROADCAST="wlan0"
# receiving interface broadcast is connected to
RECEIVE="eth0"
if [[ $1 == "-0" || $1 == "--start" ]]
then
## start hostapd
echo "Starting hostapd"
echo " You can view the log at /var/log/hostapd.log"
# launch hostapd daemon
hostapd -d /etc/hostapd/hostapd.conf > /var/log/hostapd.log &
## start dhcp server
echo "Starting dnsmasq"
# set IP address
ifconfig $BROADCAST 192.168.0.1
sleep 2
# launch dhcpd3 daemon
# echo "INTERFACES=$BROADCAST" > /etc/default/dhcp
# dhcpd3 $BROADCAST &
dnsmasq
elif [[ $1 == "-1" || $1 == "--stop" ]]
then
# send signal 2 to hostapd and dhcpd3
killall -2 hostapd dnsmasq
elif [[ $1 == "-2" || $1 == "--ics" ]]
then
# create iptables rules
iptables -A FORWARD -i $RECEIVE -o $BROADCAST -s 192.168.0.1/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE
# set kernel variable(s)
echo 1 > /proc/sys/net/ipv4/conf/all/forwarding
# edit kernel configuration
cp /etc/sysctl.conf /etc/sysctl.conf.ap_ctl
echo "net.ipv4.conf.default.forwarding=1" >> /etc/sysctl.conf
echo "net.ipv4.conf.all.forwarding=1" >> /etc/sysctl.conf
# restart networking
/etc/init.d/networking restart
elif [[ $1 == "-3" || $1 == "--noics" ]]
then
# remove iptables rules
iptables -D FORWARD 1
iptables -D FORWARD 1
# set kernel variable(s)
echo 0 > /proc/sys/net/ipv4/conf/all/forwarding
# revert kernel configuration
mv -i /etc/sysctl.conf.ap_ctl /etc/sysctl.conf
# restart networking
/etc/init.d/networking restart
else
echo $0
echo "A tool to manage hostapd and dhcpd3"
echo "Usage:"
echo " -0 --start Start hostapd and dhcpd3"
echo " -1 --stop Stop hostapd and dhcpd3 with signal 2"
echo " -2 --ics Activate internet connection sharing"
echo " between specified interfaces"
echo " -3 --noics Undo internet connection sharing settings"
fi
exit 0
tutup dan simpan script tersebut
6. Jadikan script yang dibuat tadi menjadi executable,
sudo chmod +x /usr/bin/ap_ctl
7. Untuk menjalankan hotspot wifi, ketik pada terminal
sudo ap_ctl --start
sudo ap_ctl --ics
8. Untuk berhenti, ketik
sudo ap_ctl --stop
>>>Sedikit Semoga Banyak Manfaatnya<<<
0 komentar:
Posting Komentar