Share internet Soft-AP hostapd via NAT

Follow up on my earlier blog Run your wifi-dongle as Access Point (Soft-AP) 8188eu on Linux, about using your Wifi dongle as a Wireless Access Point.

We got the WIFI AP started. Next step is to share the Internet connection on the box (enabled via ethernet cable – interface eth0)
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
To set this up automatically on boot, edit the file /etc/sysctl.conf and add the following line to the bottom of the file:
net.ipv4.ip_forward=1

Enable NAT in the kernel & rules to use ethernet interface via wifi interface.

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlx00e04c0876f5 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlx00e04c0876f5 -o eth0 -j ACCEPT

Finally persist the iptables configuration and restore it on reboot.

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Now edit the file /etc/network/interfaces and add the following line to the bottom of the file:
up iptables-restore < /etc/iptables.ipv4.nat

and….!
sudo reboot

That’s all folks!

 

VPN

Similarly, if you have a VPN running on the box. And you want to expose the VPN connection via the Wireless Access Point:

(replace eth0 by tun0 in the iptables above)

Test

curl --interface tun0 freegeoip.net/json/

Or just hit the url freegeoip.net/json/ on your browser.

Source: http://elinux.org/RPI-Wireless-Hotspot

Advertisements

Run your wifi-dongle as Access Point (Soft-AP) 8188eu on Linux

I have got the Soft AP to work in Windows (using the supplied CD) and Linux by following these steps. I was able to connect/get dhcp ip from my Android.

Will update this post with //TODO

1) internet sharing with ethernet or built in wifi interface

2) Start openvpn tunnel and essentially this Access Point will be VPN protected

(think: Netflix; after connecting my Chromecast and Android to this mountpoint)

3) do this on my Raspberry Pi 2 so that my Laptop can get some sleep 🙂

 

A. Get the latest driver. Blacklist the staging one

sudo lshw -C network

will show your driver as r8188eu

modinfo r8188eu

is in staging directory.

 

1.

git clone https://github.com/lwfinger/rtl8188eu

make all

sudo make install

2.

sudo vi /etc/modprobe.d/50-blacklist-8188eu.conf

blacklist r8188eu

3.

sudo reboot

lsmod | grep 8188

should show you ‘8188eu’

sudo lshw -C networkwill still show r8188eu – but that’s OK.

 

B. Find the wifi interface name

ifconfig

wlx00e04c0876f5 Link encap:Ethernet  HWaddr 

 

C. Remove existing hostapd and install the patched version

1.

sudo apt-get autoremove hostapd

2.
git clone https://github.com/jenssegers/RTL8188-hostapd

3.

cd RTL8188-hostapd/hostapd

sudo make

sudo make install

4. (Optionally)

cd RTL8188-hostapd/wpa_supplicant

sudo make

sudo make install

5.

sudo vi /etc/hostapd/hostapd.conf

# Basic configuration

interface=wlx00e04c0876f5

ssid=AntMan

channel=6

#bridge=br0

# WPA and WPA2 configuration

macaddr_acl=0

auth_algs=1

ignore_broadcast_ssid=0

wpa=3

wpa_passphrase=ChangePassPhrase

wpa_key_mgmt=WPA-PSK

wpa_pairwise=TKIP

rsn_pairwise=CCMP

# Hardware configuration

driver=rtl871xdrv

ieee80211n=1

hw_mode=g

device_name=RTL8188EU

manufacturer=Realtek

6.

sudo vi /etc/default/hostapd

DAEMON_CONF="/etc/hostapd/hostapd.conf"

 

 

D. Adding dhcp capabilities

1.

sudo apt-get install udhcpd

2.

sudo vi /etc/udhcpd.conf

start           192.168.42.2    #default: 192.168.0.20

end             192.168.42.24   #default: 192.168.0.254

interface       wlx00e04c0876f5         #default: eth0

remaining       yes             #default: yes

opt     dns     8.8.8.8 8.8.4.4

option  subnet  255.255.255.0

opt     router  192.168.42.1

option  lease   864000          # 10 days of seconds

3.

sudo vi /etc/default/udhcpd

#DHCPD_ENABLED="no"

E. Setting up the wifi router on static ip and hooking udhcpd start

sudo vi /etc/network/interfaces

auto lo

iface lo inet loopback

auto wlx00e04c0876f5

iface wlx00e04c0876f5 inet static

        address 192.168.42.1

        netmask 255.255.255.0

post-up service udhcpd start

F. Finally restart the services and reboot. You will see Access Point ‘AntMan‘ upon reboot.

sudo service hostapd start

sudo update-rc.d hostapd defaults

sudo reboot

Happy hacking!

Source: https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=54946

Wifi Dongle: http://www.snapdeal.com/product/leoxsys-150-mbps-nano-wifi/1179610 

Create local streaming server on Linux 

I have got this cool raspberry pi 2 setup which is hooked to my TV as a Media Center (osmc/kodi) and have got SickRage and CouchPotato installed to fetch my subscribed shows from the internet. Which later OSMC picks up and indexes with all meta and subs. 

openvpn creates a VPN tunnel for all outgoing connections. So I can still use my mobile to ssh to and as a remote for the media center (Yatse). 

Yatse doesn’t let me play videos I have on Rpi on my Phone (even when I am on the same network) under the free app.

So I resorted to dlna/upnp. One option was to switch on dlna /upnp on Kodi/osmc but that would have listed so much data. I wanted more control on what files to expose. So, I started a dlna server on rpi and accessed via VLC on my phone. 

Here’s how!! 

$ sudo apt-get install minidlna

$ sudo vi /etc/minidlna.conf
inotify=yes

media_dir=/path/to/folder
 $ sudo service minidlna force-reload

 $ sudo service minidlna restart

VLC automatically detects the server running on the same network. 

All good! Seeking works great too.