#!/bin/sh # this script will work with eth0 INTERNET_IFACE=eth0 # should be wireless MOBILE_IFACE=wlan0 # your network name your mobile will connect to MOBILE_ESSID="Mobile Router" # Configure your dhcp server ! # dhcp client (for internet interface) : this script uses dhcpcd # dhcp server (for mobile interface) : this script uses dhcpd if [ "${UID}" != "0" ]; then echo "You should be root to run this program" echo "Hint : sudo $0" exit 1 fi # Step 1 : halt scripts /etc/init.d/NetworkManager stop &> /dev/null /etc/init.d/wicd stop &> /dev/null sleep 2 # Step 2 : internet connection dhcpcd -b ${INTERNET_IFACE} iptables -t nat -A POSTROUTING -o ${INTERNET_IFACE} -j MASQUERADE sysctl net.ipv4.ip_forward=1 # Step 3 : wifi connection iwconfig ${MOBILE_IFACE} mode ad-hoc essid "${MOBILE_ESSID}" ifconfig ${MOBILE_IFACE} 10.10.10.1 up # Step 3b : dhpd /etc/init.d/dhcpd start # Wait for closing echo "Press Ctrl-D to stop sniffing" cat # Step -3b /etc/init.d/dhcpd stop # Step -3 # Step -2 iptables -t nat -D POSTROUTING -o ${INTERNET_IFACE} -j MASQUERADE sysctl net.ipv4.ip_forward=0 dhcpcd -k ${INTERNET_IFACE} # Step -1 /etc/init.d/NetworkManager start &> /dev/null /etc/init.d/wicd start &> /dev/null echo Sniff finished