We will be using isc-dhcp-server, hostapd and Sakis3G. 

isc-dhcp-server is the Internet Systems Consortium’s implementation of a DHCP server. A DHCP server is responsible for assigning addresses to computers and devices connection to the WiFi access point.

hostapd  (host access point daemon) is a user space daemon software enabling a network interface card to act as an access point and authentication server.

Sakis3G is a set of scripts to easily identify your 3G/4G modem and connect to a Broadband Mobile Network. It can be execute from command line, during boot and automatically enter sim password.

 

Installing Sakis3G

wget "http://raspberry-at-home.com/files/sakis3g.tar.gz"
sudo mkdir /usr/bin/modem3g
sudo chmod 777 /usr/bin/modem3g
sudo cp sakis3g.tar.gz /usr/bin/modem3g
cd /usr/bin/modem3g
sudo tar -zxvf sakis3g.tar.gz
sudo chmod +x sakis3g
 

Now you can test if it is connecting (from command line):  sudo /usr/bin/modem3g/sakis3g connect

if you are using a desktop kernel, an entry in the menu is inserted.You can disconnect, refresh or toggle a connection,  (run /usr/bin/modem3g/sakis3g  --help to see all commands). You may also pass the PIN number if sim card is locked with a pin and make it connect during boot:

sudo /usr/bin/modem3g/sakis3g connect APN="internet.vodafone.gr" SIM_PIN='1234'

if you have problem detecting your 3G modem run lsusb and install usb-modeswitch and usb-modeswitch-data (apt-get install....).

It can be the case that your box sees the modem as an usb storage device. in that case you must change its operation mode. In all recent linux distro modems are automatically detected. Just run lsusb to check.

 
Install the router software
 
sudo apt-get install usb-modeswitch usb-modeswitch-data hostapd isc-dhcp-server

 

Configure the ISC-DHCP-Server

Edit file  "/etc/default/isc-dhcp-server"  and specify on which interface/interfaces the DHCP Server should listen. For doing this, insert the interface in the “INTERFACES” section:

INTERFACESv4="wlan0"  (check your interface name with ifconfig)
INTERFACESv6="wlan0"

Edit the file "/etc/hostapd/hostapd.conf", adding/uncommenting the following

default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
authoritative;
 
log-facility local7;
# this is the subnet to assign an IP
subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option domain-name-servers 8.8.8.8, 8.8.4.4;
option domain-name "local";
option routers 192.168.42.1;
option broadcast-address 192.168.42.255;
default-lease-time 3600;
max-lease-time 7200;
}

Configure Wi-Fi AP

Create the file: touch /etc/hostapd/hostapd.conf.  Enter the following:

country_code=GR  ### Select country code  ###
interface=wlan0      ### Wireless network interface  your own inerface, check with ifconfig
#driver=nl80211     ### Driver not necessary, check your driver
ssid=myWIFI          ### Network name SSID enter the ssid name of the wifi network to be created
hw_mode=g           ### Set frequency to 2.4 Ghz ###
channel=6              ### Channel number ###
ieee80211n=1        ### Enable Wi-Fi N ###
wmm_enabled=0   ### Enable WMM ###
macaddr_acl=0      ### Allow all MAC Address ###
auth_algs=1           ### Use WPA Auth ###
wpa=2                     ### Use WPA2 ###
wpa_key_mgmt=WPA-PSK ### Enable Pre-Shared Key ###
wpa_passphrase=1234qwer ### password for wifi clients ###
#rsn_pairwise=CCMP
wpa_pairwise=TKIP ### Use AES/CCMP ###
ignore_broadcast_ssid=0  ### Require clients to know the network name ###
#ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] ### Enable 40 Mhz channels ###
 

 

Edit the file "/etc/default/hostapd" and add the following:

DAEMON_CONF=/etc/hostapd/hostapd.conf

 

Configure the network interface
 
Edit "file /etc/networks/interfaces" as follows
 
allow-hotplug wlan0
iface wlan0 inet static
        address 192.168.42.1
        netmask 255.255.255.0
        network 192.168.42.0
        broadcast 192.168.42.255

Configure Firewall (iptables) rules

## All packets leaving the subnet should be masqueraded, ppp0 is the mobile broadband interface, check with ifconfig

sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE  

## Forward packets arriving at ppp0 interface to wlan0 interface and vice versa

sudo iptables -A FORWARD -i ppp0 -o wlan0 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o ppp0 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
 

Enable forwarding

echo 1 > /proc/sys/net/ipv4/ip_forward or for permanent forwarding after each boot

Edit the file “/etc/sysctl.conf”  and set net.ipv4.ip_forward=1

 

Start all services

/etc/init.d/networking restart

/etc/init.d/isc-dhcp-server restart

/etc/init.d/hostapd restart

Start the daemon services

sudo update-rc.d hostapd enable

sudo update-rc.d isc-dhcp-server enable

reboot and enjoy!!