Skip to content

Instantly share code, notes, and snippets.

@CarlosMecha
Created December 22, 2014 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarlosMecha/3ca85f25a43f9d5e3c6a to your computer and use it in GitHub Desktop.
Save CarlosMecha/3ca85f25a43f9d5e3c6a to your computer and use it in GitHub Desktop.
Script to turn your computer in a WiFi hotspot and a DHCP service.
#!/bin/bash
#
# Simple WIFI portable Hotspot.
# Requirements:
# * hostapd
# * dhcpd
#
# Tested in Debian environments.
#
# Configuration file.
CONF="./portable-wifi-hostapd.conf";
DHCP_CONF="./portable-wifi-dhcp.conf";
# IP Address
IP="10.0.0.1";
# Out interface
OUT_IFACE="wlan0";
# In interface
IN_IFACE="eth0";
# Shutting down.
if [ "$1" == "-r" ]; then {
killall hostapd;
killall dhcpd;
iwconfig $OUT_IFACE mode Managed;
echo "0" > /proc/sys/net/ipv4/ip_forward;
iptables -t nat -D POSTROUTING -o $IN_IFACE -j MASQUERADE;
exit 0;
} fi;
iwconfig $OUT_IFACE mode Master;
ifconfig $OUT_IFACE $IP;
echo "1" > /proc/sys/net/ipv4/ip_forward;
iptables -t nat -A POSTROUTING -o $IN_IFACE -j MASQUERADE;
nohup hostapd $CONF 2>&1 >> /dev/null &
dhcpd -cf $DHCP_CONF 2>&1 >> /dev/null
unset CONF;
unset DHCP_CONF;
unset IP;
unset IN_IFACE;
unset OUT_IFACE;
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment