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:

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

sudo reboot

That’s all folks!



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)


curl --interface tun0

Or just hit the url on your browser.


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.



git clone

make all

sudo make install


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

blacklist r8188eu


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


wlx00e04c0876f5 Link encap:Ethernet  HWaddr 


C. Remove existing hostapd and install the patched version


sudo apt-get autoremove hostapd

git clone


cd RTL8188-hostapd/hostapd

sudo make

sudo make install

4. (Optionally)

cd RTL8188-hostapd/wpa_supplicant

sudo make

sudo make install


sudo vi /etc/hostapd/hostapd.conf

# Basic configuration





# WPA and WPA2 configuration









# Hardware configuration







sudo vi /etc/default/hostapd




D. Adding dhcp capabilities


sudo apt-get install udhcpd


sudo vi /etc/udhcpd.conf

start     #default:

end      #default:

interface       wlx00e04c0876f5         #default: eth0

remaining       yes             #default: yes

opt     dns

option  subnet

opt     router

option  lease   864000          # 10 days of seconds


sudo vi /etc/default/udhcpd


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



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!


Wifi Dongle: 

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

 $ 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. 

Add 1600×900 (16:9) resolution to Ubuntu

$ xrandr

# look at the name of your device
# eDP1 connected primary 1440x900+0+0 (normal left inverted right x axis y axis) 344mm x 193mm
# HDMI1 disconnected (normal left inverted right x axis y axis)
# VGA1 disconnected (normal left inverted right x axis y axis)
# VIRTUAL1 disconnected (normal left inverted right x axis y axis)

$ xrandr --newmode "1600x900_60.00" 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync
$ xrandr --addmode eDP1 "1600x900_60.00"
$ xrandr --output eDP1 --mode "1600x900_60.00"



update: Add it to your dm startup script

Find out what’s your default dm:

$ cat /etc/X11/default-display-manager

Eg. try adding pre-start or post-start scripts to /etc/init/lightdm.conf

How to install deluge bit-torrent client on OSMC Raspberry Pi

My RPi runs OSMC with SickRage, CouchPotato and Transmission-daemon.

I have been using transmission-daemon for sometime and it works great. Recently I had some I/O trouble with a big torrent and decided to install another BitTorrent client on the box – just in case.
I tried to look around but couldn’t get any other known torrent clients installed on the ARM box (absence of the binaries you can say). There are ways to get x86 utorrent binary installed on RPi but I didn’t want to go that far.


#Install the required packages

sudo apt-get install deluged deluge-web

#Set your auth credentials

sudo echo "osmc:osmc:10" &gt;&gt; /var/lib/deluged/config/auth

#Change various settings, seed-ratio; download directory etc

sudo vi /var/lib/deluged/config/core.conf

#restart the service to take effect

sudo service deluged restart

#check out if the service started OK

stty cols 2000

sudo service deluged status -l

#Create the web ui service

sudo vi /etc/systemd/system/deluge-web.service

Description=Deluge Bittorrent Client Web Interface






#Set the service to start upon system startup

sudo systemctl enable deluge-web.service

#Now start the service for the first time.

sudo service deluge-web restart

sudo systemctl start deluge-web

#Go to URL

http://<<RPi URL>>:8112/

#Enter the default password:


#Set a new password.

#Connection Manager:






That’s all folks!

This is how you compile the jdk

Yeah – download the sources, install the required libraries, compile. Simple!

WHY would anyone want to do that?
Not entirely for the kicks, I must tell you. Or for the fact that it is open source and you can get your hands on the sources. Or for running your cpu at 150% and making it impossibly hot? Well if you are in search for drama – we can exchange laptops (Though I may be forced to get a replacement soon😛 )!

I recently was on an ‘Advanced Concurrency’ training (No! I wasn’t the instructor) and that’s where I picked this idea of compiling the JDK (Wouldn’t it make a very good friend once you get to know him?). You can make some low level changes (Think: Go Deep! The JVM level?). Our instructor did something very cool. He was trying to show us how modern JVMs, on runtime, do dynamic compilation and give massive performance boost. To show us that and for even much more (to look under the hood), he added his own code to the debug-jdk and from that marriage, something beautiful was born. He could map his source-code with the jvm-optimized-one.

JDK8 is required for the compilation process to begin so please get that first.

We’d be compiling JDK9 (which is still in Development).

# scm is done using hg - mercurial
$ sudo apt-get install mercurial
# tell hg your name
$ echo "[ui]" >> ~/.hgrc
$ echo "username=nikunjlahoti" >> ~/.hgrc

# clone the dev branch of jdk9 to a folder called 9dev
$ hg clone 9dev
$ cd 9dev/
# Next execute the script to download everything in the forest
$ chmod u+x ./
$ sh ./
# this may take some time & bandwidth

# Reading the README would make things more clear. Do open the README-builds.html
$ cat README
# Configure the environment
$ bash ./configure
# Configure may fail when a particular dev library would not be present.
# It would tell you what to install to fix that issue. And run Configure again.
# Below is a list of libraries which were missing from my Ubuntu 14.04
$ sudo apt-get install libX11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev libcups2-dev libfreetype6-dev libasound2-dev

# Begin the compilation
$ make all

Build Statistics:
On my machine Linux 3.13.0-35-generic x86_64 x86_64 GNU/Linux it took around 40 minutes.

## Starting verify-modules
Checking dependencies across JDK modules
Access verification succeeded.
## Finished verify-modules (build time 00:00:59)

----- Build times -------
Start 2014-09-18 00:06:26
End   2014-09-18 00:46:02
00:00:59 verify-modules
00:39:36 TOTAL

Finished building OpenJDK for target ‘all’
Thu Sep 18 00:46:02 IST 2014

How to execute

$ cd 9dev/build/linux-x86_64-normal-server-release/jdk/bin
$ ./java -version
# openjdk version '1.9.0-internal'
# OpenJDK Runtime Environment (build 1.9.0-internal-nikunj_2014_09_18_00_01-b00)
# OpenJDK 64-Bit Server VM (build 1.9.0-internal-nikunj_2014_09_18_00_01-b00, mixed mode)

git: sparsecheckout: Partially pull a repo

So I got this Firefox Device (called Intex Cloud Fx) a couple of weeks back but still couldn’t switch to it (the cold turkey way) as the keyboard application is still in its infancy and I can barely type on QWERTY anymore (long sentence?)!

I decided to dive right into it. I spent my weekend trying to understand the OS better and managed to push some test applications to the device (and they worked! And I could even debug them from my browser! Cool stuff!).

The end game (more like the next goal) is to get/create a keyboard app which has the placement of keys that my mind would understand. (Think: Colemak)

To do that, I started looking around for examples and that’s when I found something and forked it immediately :)  test-keyboard-app

To pull that repository on my laptop was truly intimidating (it’s a full blown Operating System after all). That’s when I found out what magic git sparsecheckout could do.

$ git init repo

$ cd repo/

$ git remote add -f origin

# Updating origin
# remote: Counting objects: 356086, done.
# remote: Compressing objects: 100% (105268/105268), done.
# remote: Total 356086 (delta 245156), reused 356086 (delta 245156)
# Receiving objects: 100% (356086/356086), 817.56 MiB | 892.00 KiB/s, done.
# Resolving deltas: 100% (245156/245156), done.

$ git config core.sparsecheckout true
# Specifying the intention now

$ echo "dev_apps/test-keyboard-app/" >> .git/info/sparse-checkout
# list of directories to be included

$ git pull origin master
# From
# * branch master -> FETCH_HEAD

$ ls -a
dev_apps .git

# voila

#NoteToSelf #LetTheFunBegin