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

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 

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 http://hg.openjdk.java.net/jdk9/dev 9dev
$ cd 9dev/
# Next execute the get_source.sh script to download everything in the forest
$ chmod u+x ./get_source.sh
$ sh ./get_source.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)

Quickly create a bootable USB in Linux

Yes – Everything I do – I do it for you (more like IN you; Ahem! You = Linux BTW)!

Alright without wasting any time lets quickly get on with it.

This post is about saving your DVD and DVD tray; This post is about installing the OS at a superior speed; This post is about saving time.

What we want to achieve:

We want to install an OS using a bootable USB drive instead of a DVD (it has a lot of hassles – you need to buy one – you need to sit and wait for burning to complete – it may fail – you need to go to the shop and buy another one – as it runs from a DVD the installation will be slower – BLAH BLAH BLAH!)

How we are doing it?

For Ubuntu and other more recognized Operating Systems, we already have Ubuntu Startup Disk Creator, or that.

But it requires software installation and doesn’t work with all the Operating Systems.

So we are going to use the tools which come bundled with all the Linux distros and we are going to make our USB disk imitate a DVD.

What to do:

Make sure you have the ISO of the operating system downloaded already. Lets put it in the $HOME directory and let’s call it OS.iso


$ sudo dd if=$HOME/OS.iso of=/dev/sdx oflag=direct  bs=1048576

Where:

bs stands for bytes. 1048576 = 1024 * 1024 bytes = 1Mb.

‘/dev/sdx‘ is the target USB drive. If your system doesn’t support ‘oflag=direct’, you can just leave it out as it is simply intended to speed up the process a bit.

If you don’t know about the target USB drive path, run this command and figure out your destination drive.


$ sudo fdisk -l

Warning: Please make sure you have the correct value for x – or it can be catastrophic for you running environment.

Remember, don’t include an integer for the USB drive, e.g. ‘/dev/sdx1’, as it would refer to the existing partition on that drive and not the drive itself.
When the USB has been properly created by ‘dd’, there should be an output similar to this:

706+1 records in
706+1 records out
740601856 bytes (741 MB) copied, 91.7024 s, 8.1 MB/s

Happy Hacking!

Source: http://community.linuxmint.com/tutorial/view/744

 

Switch to Colemak/Dvorak

Its true! I can touch type without even looking at the monitor, with an average WPM of 60+ (most people can! Are you most people?), but then sometimes LOVE is not enough.

 

#1 Why?

QWERTY wasn’t designed with the user in mind (typewriter wins). More info: here & here

User productivity increases. Less fatigue – don’t have to worry about http://en.wikipedia.org/wiki/Repetitive_strain_injury

Colemak etc are less prone to typos.

& for the sheer thrill in doing something new & rare (btw eight years ago I moved to Linux. No analogy! *Wink*)

 

#2 How?

Ideally all you need is an OS that understands the layout. All modern operating systems do.

That’s how you can switch layouts in Windows Ubuntu etc (just google).

 

Optionally, if you are like me – feedback is vital.

  • Let’s buy that keyboard?
  • Maybe those glowing stickers?
  • Ah! Just get me a screw driver X(

Pop the keys out and rearrange!

image

The red “i” has landed on the home row. Good stuff. Please don’t do that to your laptop. USB keyboard is pretty easy to acquire.

Downside: F & J have moved (if you know what I mean). #anchor #bump #ridges

 

#3 Next Steps

Learn

 

Q. All said and done – Why is QWERTY still in production?

A. I don’t have to answer that as we all know what will happen if you go to your manager/boss and ask him to sponsor this migration. For him all that’s expected out of you is that you ‘deliver’ – which you are already capable of.

 

Happy hacking!

 

PS: WPM has significantly gone down. But do not worry. #FreshStart

PPS: Yes! I used Colemak to write this post.

more stuff:

http://en.wikipedia.org/wiki/Latin-script_non-QWERTY_keyboards

 

Update (20130812):

Q. How to Switch in Android?

A. Google Keyboard is the answer. Get the app.

Settings — Language & Input — Google Keyboard — Advanced settings — Custom Input Styles — Add style (Currently it supports 6 layouts)

This is definitely cool. Gesture typing is fun.

Android-Colemak

Android-Colemak

Citrix Receiver on Linux x86_64

Of late I have been on an OS installation spree; For some reason I didn’t like 12.10 too much.

To WFH and that too from some derivative of Linux, I had to each time make sure that Citrix worked. I have successfully installed it on Ubuntu, Slackware and Linux Mint (few minutes back).

#Step 1

Go to Citrix.com and download Receiver for Linux in .deb

The package:

Even though we have downloaded it from the 64-bit section, as the name suggests it still is a 32-bit package.

#Step 2

To make sure that the 32-bit binaries work on your 64-bit machine please install:

$ sudo apt-get install ia32-libs

#Step 3

Installation is as simple as a double click (for Debian and derivatives). For others please convert it to the required format using the tools available on your current system.

#Step 4

Open web browser (Chrome works best). Login etc.

And when the browser downloads the .ICA file then advise the Browser to use

/opt/Citrix/ICAClient/wfica

Known Issues:

Installation Fails:

You are happily waiting for the installation to complete but it fails at the final post-install steps, even after getting successfully installed.

Now each time you try to install a new software this post-install will be retried and would leave your machines in a mess.

The work around is pretty simple. The script is looking for x86 as the desired architecture when it actually is x86_64 (you can validate that by typing `uname -m` in the terminal)

#StepA Open the postinstall file
$ sudo gedit /var/lib/dpkg/info/icaclient.postinst

#StepB
# replace
# echo $Arch|grep "i[0-9]86" >/dev/null
# with
# echo $Arch|grep -E "i[0-9]86|x86_64" > /dev/null

#StepC tell dpkg to configure icaclient
$ sudo dpkg --configure icaclient

If it still doesn’t work for you then open the terminal and try this:

/opt/Citrix/ICAClient/wfica PATH_TO_ICA_FILE

This way you can find out details and try to troubleshoot.

Additionally you may check this https://help.ubuntu.com/community/CitrixICAClientHowTo.

Happy Hacking.

VirtualBox vboxdrv problem on Ubuntu

Problem Statement:

#1

Kernel driver not installed (rc=-1908)

The VirtualBox Linux kernel driver (vboxdrv) is either not loaded or there is a permission problem with /dev/vboxdrv. Please reinstall the kernel module by executing


/etc/init.d/vboxdrv setup

as root. If it is available in your distribution, you should install the DKMS package first. This package keeps track of Linux kernel changes and recompiles the vboxdrv kernel module if necessary.

#2

Failed to open a session for the virtual machine “Windows XP”.

The virtual machine ‘Windows XP’ has terminated unexpectedly during startup with exit code 1.

(Running a virtual machine on VirtualBox the two dialogues would say that)

The cause — as the VirtualBox page states it:

Ubuntu/Debian users might want to install the dkms package to ensure that the VirtualBox host kernel modules (vboxdrv, vboxnetflt and vboxnetadp) are properly updated if the linux kernel version changes during the next apt-get upgrade.

The Fix:

The dkms package can be installed through the Synaptic Package manager or through the following command:

sudo apt-get install dkms

Running `virtualbox` in the terminal says almost the same thing…

$ virtualbox
WARNING: The vboxdrv kernel module is not loaded. Either there is no module
available for the current kernel (3.5.0-18-generic) or it failed to
load. Please recompile the kernel module and install it by

sudo /etc/init.d/vboxdrv setup

You will not be able to start VMs until this problem is fixed.
# You have heard the man!
$ sudo /etc/init.d/vboxdrv setup
* Stopping VirtualBox kernel modules [ OK ]
* Uninstalling old VirtualBox DKMS kernel modules [ OK ]
* Trying to register the VirtualBox kernel modules using DKMS
Error! Your kernel headers for kernel 3.5.0-18-generic cannot be found.
Please install the linux-headers-3.5.0-18-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located

* Failed, trying without DKMS
* Recompiling VirtualBox kernel modules
* Look at /var/log/vbox-install.log to find out what went wrong
# Downloading the Linux Headers now
# sudo apt-get install linux-headers-3.5.0-18-generic
$ sudo apt-get install linux-headers-`uname -r`
# Running it again
$ sudo /etc/init.d/vboxdrv setup
* Stopping VirtualBox kernel modules                          [ OK ]
* Uninstalling old VirtualBox DKMS kernel modules             [ OK ]
* Trying to register the VirtualBox kernel modules using DKMS [ OK ]
* Starting VirtualBox kernel modules                          [ OK ]

All good!

Missing “Safely Remove” in Ubuntu 12.10

Strange isn’t it?

There was a time when all you had to do was “Safely Remove” and see the progress bar dance for a few seconds — and you were golden.

Those were the days! Anyway it turns out unmount/eject/safely remove are all meant to do different things.

Yes we are talking about our near and dear external hard-disks. (think: WD, Segate, FreeAgent Blah Blah)

 

Now with Ubuntu 12.10, only “unmount” is available on “Nautilus”! Even “Thunar” is no good.

(*these are lets say pretty awesome “Windows Explorer” in the world of Linux)

Well people have even reported it [bug]. Please feel free to mark it “The Bug affects You”.

 

Why?

What do you mean “why”? Its a BUG. The beauty of opensource is that someone will fix it. Sit back and relax. Its not urgent anyway.

So why this post?

Well who would not want to make sure that their Hard Drive is doing well and not in an inconsistent state — unable to do the most important thing that they are supposed to do — SAVE DATA! You wouldn’t want a lossy storage. Anyway, the point is — to make sure that all the data was written to the harddisk before you unplugged it — you’d need to UNMOUNT it. You always should. And if there are more than one partitions on the Hard Drive then you need to unmount each and everyone separately (which was earlier taken care by “SAFELY REMOVE”).

But?

Still the Harddisk keeps spinning. You can feel it. You can even hear it. And the LED would just keep glowing.

So until they fixed it, we have a work around.

Spin down the harddisk

I found answers to my queries here:

I created a quick shell script


#!/bin/bash
echo "Unmounting disks..."
udisks --unmount /dev/sdb1
udisks --unmount /dev/sdb2

#udisks --unmount /dev/sdb3
#depending on the number of partitions you have on your drive edit above
#please make sure all the partitions are unmounted before you detach

echo "Spinning down!"
udisks --detach /dev/sdb
echo "All done!"

Execute it …


$ chmod u+x safelyremove.sh
$ ./safelyremove.sh
Unmounting disks...
Spinning down!
All done!

Or even better — Save it on Desktop

Just double click; “Run” and you are almost “GOLDEN” again!

 

Happy Hackin’

Enable Hibernation on Ubuntu

One of those note-to-self posts!

Why does Ubuntu come with Hibernation disabled by default?

Ubuntu had to resort to such measures as users experienced a lot of issues like:

  • No resume after suspending the PC — in a limbo
  • Open files and folders gone — Shutdown instead of hibernation
  • Wifi etc devices not working after waking up — the worst nightmare

And that happened because there wasn’t enough Hardware support. Even in Ubuntu derivatives like Linux Mint it came disabled.

What is hibernation?

Seriously? Forget it. I am not even going to look at you.

Alright Alright suit yourself: https://help.ubuntu.com/community/PowerManagement/Hibernate

Advantages of Hibernation:

  • You have an edge over “suspending”. It saves power.
  • The exact state of the computer is resumed.
  • Major use case for the people who leave their  PCs unattended (think: http://Torrentz.in)

How to enable it in Ubuntu:

Step#1 Check if hibernate works on your hardware.

  • Open Terminal (CTRL + ALT + T)
  • Save your work first and then type
 $ sudo pm-hibernate 
  • If everything goes smoothly, start your laptop and continue iff things look good.
  • If you see anything unexpected then please make sure that the size of SWAP is at least as large as the RAM or just 
     System.exit(1) 

Step#2 You can continue to use that command safely or make it permanent by enabling it on the menu (do it only if Step#1 above works)

Open terminal and type:

 $ sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla 

Enter the password

(instead of `gedit` you can use `vi` its awesome)

hit “i”; paste; hit “ESC”; hit “:”; hit “x”

Step#3 Paste the following lines in the blank file you created just now.

[Re-enable hibernate by default]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

Hit Save and Quit.

Step#4 Reboot for the changes to take effect.

If upon restart you still cannot see the “Hibernate” item in the menu, then you need to Tweak the Grub but mostly it would not come to that.

And we’re back …

Also check http://nikunjlahoti.com/2012/04/29/ubuntu-12-04-fix-fn-brightness-keys/

Sources:

https://help.ubuntu.com/12.04/ubuntu-help/power-hibernate.html

https://help.ubuntu.com/12.04/ubuntu-help/power-suspendfail.html

Ubuntu fix Fn Brightness keys

So my Acer Aspire 5738 encountered the oh-the-Brightness-Function-keys-are-not-working-yet-again issue after the installation of Ubuntu 12.04. There is a simple fix and some related caveats. So here we go …..

#1 (open the file in gedit or vi)

$ sudo vi /etc/default/grub
[sudo] password for nikunj:

#2 (find an insert the arguments in gray)

GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash acpi_osi=Linux acpi_backlight=vendor

#3 (update the grub configuration)

$ sudo update-grub
Generating grub.cfg …
Found linux image: /boot/vmlinuz-3.2.0-24-generic
Found initrd image: /boot/initrd.img-3.2.0-24-generic
Found linux image: /boot/vmlinuz-3.2.0-23-generic
Found initrd image: /boot/initrd.img-3.2.0-23-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 7 (loader) on /dev/sda1
Found Ubuntu 11.10 (11.10) on /dev/sda2
done

Just reboot the machine.

Caveats:

At times the screen would go entirely dark. Or would not apparently resume from a blank screen or when the screensaver gets active.

For such cases, all you need to do is press “Fn + Brightness UP button” and screen will GLOW. Simple!!

(This post is more like a NOTE TO SELF. But if it helps you in someway then its even better … AWESOME!! :D)

Update:

Works for Ubuntu 12.10 perfectly 🙂

Update (2013/01/08):

You can use “sudo gedit /etc/default/grub” if you are not very familiar with vi editor! 🙂

Update (2013/05/12):

For Ubuntu 13.04 do the following:

GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash acpi_osi=Linux acpi_backlight=vendor

Update (2014/05/25):

Works on Ubuntu 14.04.