Changing MAC address of USB LAN adapter permamently

It’s been long time since the last post… But time came that I’ve faced serious problem when trying to change MAC address of my USB LAN adapter.

As recommended by numerous pages found by googling change MAC address Linux, I’ve tried ifconfig eth0 hw ether NEWMAC and macchanger. It changed MAC of my devices (as seen in ifconfig output), yet after plugging the LAN cable, the MAC was automatically restored to permanent one.

At first, I thought it’s the fault of NetworkManager, so I’ve stopped it. But the problem still persisted. After some tinkering, I’ve realised, the MAC can be specified also in NetworkManager alone by adding to /etc/NetworkManager/NetworkManager.conf two lines:


and restarting NetworkManager

sudo service network-manager restart

Note, when I’ve changed MAC in NetworkManager using GUI, the permanent MAC was also restored upon LAN cable connection.

Hope this helps someone having similar problem with USB LAN adapter.

Kindle touch with ssh to wi-fi enabled

Lately, I’ve spent quite a lot of time playing with my Kindle. The motivation was mostly its sloppiness – after having it for 1.5 year, my Kindle became very slow and unresponsive… I decided to factory reset it. And while doing it, I’ve checked if I maybe the jailbreak of newer firmware is possible (last time I’ve checked over a year ago it wasn’t).
To my big joy, I found these days it’s fairly easy to jailbreak any kindle by downgrading it’s firmware.
But this isn’t the focus of this post. Here I would like to share my experience with enabling ssh access to my Kindle. Why anyone would do that? Kindle is ARM-processor powered computer with Linux installed. So having SSH access, you can setup your Kindle to do lots of useful stuff. But about that, I’ll write in the next posts 😉
Here is how to proceed:

  1. Jailbreak your Kindle
  2. Install KUAL & Mobileread Package Installer (MrPI)
  3. Install USBNetwork Hack
  4. Create new user account in Kindle for SSH access
  5. [bash]
    # get dev name from udev
    dmesg | grep usb0

    # bind
    sudo ifconfig enp0s20u8

    # telnet

    # mount root with write access
    mntroot rw

    # create new user
    mkdir -p /home
    adduser USER

    # make it root by changing USERID to 0 in <code>/etc/passwd</code> ie.


  6. Start sshd and enable port 22 for SSH temporarily
  7. This is only to check if SSH is possible. So far we didn’t make any serious changes 😉
    /mnt/us/usbnet/sbin/sshd -f /mnt/us/usbnet/etc/sshd_config
    iptables -A INPUT -p tcp –dport 22 -j ACCEPT
    Now try to login to your Kindle by SSH. You can find its IP by executing ifconfig. Proceed only if SSH works for you.

  8. Enable port 22 for SSH
  9. [bash]
    # add below line to <code>/etc/sysconfig/iptables</code> to enable SSH access
    -A INPUT -p tcp –dport 22 -j ACCEPT

  10. Add sshd to upstart
  11. Create new file /etc/upstart/sshd.conf
    # ssh – OpenBSD Secure Shell server
    # The OpenSSH server provides secure shell access to the system.

    env LOGFILE=/tmp/ssh.log

    description "OpenSSH server"

    start on dbus_ready
    stop on stopping dbus

    respawn limit 2 5
    umask 022

    pre-start script
    test -x /usr/sbin/sshd || { stop; exit 0; }
    test -e /etc/ssh/sshd_not_to_be_run && { stop; exit 0; }
    test -c /dev/null || { stop; exit 0; }
    end script

    # if you used to set SSHD_OPTS in /etc/default/ssh, you can change the
    # ‘exec’ line here instead
    echo `date` "Starting sshd…" >> $LOGFILE 2>&1
    /mnt/us/usbnet/sbin/sshd -f /mnt/us/usbnet/etc/sshd_config >> $LOGFILE 2>&1
    end script

  12. Disable auto updates
  13. [bash]
    mv /etc/uks /etc/uks.disabled

Now SSH should work after Kindle reboot 🙂


Stream audio & video from webcam using VLC

Yesterday, I’ve posted about streaming webcam image to www using motion. This solution, although very simple, has many limitations, lack of sound, usage of high bandwidth and low image quality, just to mention a few. In a way, motion stream is just a set of jpeg files.
In order to solve all of these, I have spend quite some time playing with VLC, an open source cross-platform multimedia player, that is able to transcode and stream audio & video.
Streaming can be started from graphical interface, just go to:

Media >> Stream… >> Capture Device, select your devices, Add HTML destination (ie. :8080/webcam.ogg), select Video-Theora + Vorbis (OGG) profile & press Stream.

You stream will be available at: http://localhost:8081/webcam.ogg

But normally, using command line is preferred under Linux:
vlc v4l2:// :input-slave=alsa:// :v4l2-standard=1 :v4l2-dev=/dev/video0 :v4l2-width=1280 :v4l2-height=720 :sout="#transcode{vcodec=theo,vb=2000,acodec=vorb,ab=128,channels=2,samplerate=44100}:http{dst=:8081/webcam.ogg}" -I dummy

Initially, I had problem with streaming sound along with video. Adding, `:input-slave=alsa:// :v4l2-standard=1` solved this. You can try another values for `:v4l2-standard` ie. 0, 1 or 2, depending which microphone you want to use.

Above command will stream HD video (1280×720) in .ogg format (natively suported by most browsers) @ ~2Mbps (2000kbps). If you have slower connection, you can change `vb=2000` to `vb=1000` (~1Mbps) and play with lower resolutions. You can check available resolutions of your camera by:
lsusb -v | egrep -B10 ‘Width|Height’

This stream, however, is available to everyone. To limit it only to localhost, you can use iptables:
sudo iptables -A INPUT -p tcp -s localhost –dport 8081 -j ACCEPT && sudo iptables -A INPUT -p tcp –dport 8081 -j DROP && vlc v4l2:// :input-slave=alsa:// :v4l2-standard=1 :v4l2-dev=/dev/video0 :v4l2-width=1280 :v4l2-height=720 :sout="#transcode{vcodec=theo,vb=2000,acodec=vorb,ab=128,channels=2,samplerate=44100}:http{dst=:8081/webcam.ogg}" -I dummy

Now, you can create apache2 proxy, similarly to previous post:
# install apache2-utils
sudo apt install apache2-utils

# setup new user & passwd
sudo htpasswd -c /etc/apache2/.htpasswd webcam

# configure apache2 – add to your VirtualHost config
# webcam
<Location "/webcam.ogg">
ProxyPass http://localhost:8081/webcam.ogg
ProxyPassReverse http://localhost:8081/webcam.ogg
# htpasswd
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user

Streaming image from webcam through www

Willing to stream image from your webcam through Internet? Nothing easier with Ubuntu!

# install
sudo apt-get install motion

# create config file
mkdir ~/.motion && gedit ~/.motion/motion.conf

# define the port and motion settings
webcam_port 8081
webcam_localhost on
# increase maxrate & quality
webcam_maxrate 30
webcam_quality 90
# slow down the stream to 1 frame per second if no motion
webcam_motion on

# run motion

You can find the stream at http://localhost:8081/.

If you wish to stream it publicly, I recommend at least basic HTTP based authentication.
# install apache2-utils
sudo apt install apache2-utils

# setup new user & passwd
sudo htpasswd -c /etc/apache2/.htpasswd webcam

# configure apache2 – add to your VirtualHost config
# webcam
<Location "/cam">
# proxy
ProxyPass http://localhost:8081/
ProxyPassReverse http://localhost:8081/
# htpasswd
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
Now, image from your webcam will be accessible at http://YOURDOMAIN.COM/cam

Finally, you can configure motion to run only when you are away.

Inspired by gist.

Is LTE solving Internet access problem in rural regions?

In the rural regions there is limited choice for Internet service providers (ISP). In my region, there is only one choice for cable connection… Therefore, I have decided to try widely advertised LTE. I have chosen one of the providers based on the closest LTE stations.

The real speed (20Mbps / 4Mbps) is far from the advertised 150Mbps, but it’s way better than my current cable connection (10Mbps / 1Mbps). Unfortunately, the station is some 3km away. I have obtained 30Mbps / 4.3Mbps by placing the modem outdoor, but this seems to be max in my region.

But still, the problem with data transfer limit remains… Hopefully, the competition between LTE providers will withdraw those limits as it happened in the early years with ADSL providers.

Limit rsync bandwitdh

Especially useful if you share Internet connection with devoted gamers and you prefer to stay safe when they play CS;)
# limit rsync bandwith to 500 KB/s
rsync -avz –bwlimit=500 remoteHost:remoteDir ~/localDir
I have noticed rsync is using double --bwlimit (in this case 1000 KB/s), so if you truly want to limit the bandwidth to 500 KB/s, use --bwlimit=250.

Inspired by HowToGeek.

Testing connection speed between two computers

I’ve expanded my home network with new switch and I wanted to test the connection speed between different computers. At first, I ran rsync, but I’ve quickly realised it’s limited by source/destination read/write speeds.
I found better way of measuring connection speed using netcat:

[code lang=”bash”]# start listening on one computer ie
nc -vvlnp 12345 < /dev/null

# start broadcasting ~100MB from another computer
dd if=/dev/zero bs=1M count=100 | nc -vvn 12345
## 104857600 bytes (105 MB) copied, 8.89602 s, 11.8 MB/s

You can use more sophisticated tools for the same purpose ie. iperf:
[code lang=”bash”]# install on both boxes
sudo apt-get install iperf

# start server in one computer
iperf -s

# measure connection speed from client(s)
iperf -c server_IP
##[ 5] 0.0-10.0 sec 112 MBytes 94.1 Mbits/sec

Inspired by AskUbuntu.