Skip to content

Instantly share code, notes, and snippets.

@copyninja
Created August 7, 2011 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save copyninja/1130164 to your computer and use it in GitHub Desktop.
Save copyninja/1130164 to your computer and use it in GitHub Desktop.
Enabling the internet sharing
#!/bin/zsh
# Bring up the wlan0 interface
ifconfig wlan0 up
# Put the interface in Ad-hoc mode
iwconfig wlan0 mode Ad-Hoc
# Set the essid for the access point
iwconfig wlan0 essid copyninja
# Set auto channel
iwconfig wlan0 channel auto
# Set the security (WEP)
# Set Key
iwconfig wlan0 key restricted 1234-5678-90
# Set encryption
iwconfig wlan0 key on
# bring up the lan and assign IP address
ifconfig wlan0 up 192.168.1.1 netmask 255.255.255.0
# Restart the dnsmasq
/etc/init.d/dnsmasq restart
# Set nat rules in iptables
iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
# Replace accordingly usb0 with ppp0 for 3G
iptables --table nat --append POSTROUTING --out-interface usb0 -j MASQUERADE
iptables --append FORWARD --in-interface wlan1 -j ACCEPT
# Enable IP forwarding in Kernel
sysctl -w net.ipv4.ip_forward=1
@b1
Copy link

b1 commented Sep 27, 2012

I think this
iptables --append FORWARD --in-interface wlan1 -j ACCEPT

have to be
iptables --append FORWARD --in-interface wlan0 -j ACCEPT

Anyway thank you for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment