Archive

For the Ubuntu 11.04 category

How to Install libnfc for PN532 NFC Readers on Linux

2 Comments

Installing libnfc for PN532 based NFC reader is not exactly as described in the documentation. Some information is scattered in the documentation. This installation guide has been tested with the GO2NFC GO2NFC141U NFC Reader and the Adafruit PN532 NFC/RFID controller breakout board.

1) Install the dependencies:

sudo apt-get install libusb-0.1-4 libusb-dev libpcsclite1 libpcsclite-dev libccid pcscd

2) Create the configuration directory

sudo mkdir -p /etc/nfc/devices.d/

3) Create the file /etc/nfc/devices.d/pn532_uart.conf containing

name = "PN532 board via UART"
connstring = pn532_uart:/dev/ttyACM0
allow_intrusive_scan = true

Replace ttyACM0 with ttyUSB0 if you are using the Adafruit reader.

5) Create the file /etc/nfc/libnfc.conf containing

allow_autoscan = true

6) Download the libnfc library at https://bintray.com/nfc-tools/sources/libnfc. Decompress the archive somewhere. Go into the libnfc-x.x.x directory.

7) Build the library

sudo ./configure --sysconfdir=/etc --prefix=/usr --with-drivers=pn532_uart
sudo make
sudo make install

8) Test your installation. Execute the command utils/nfc-scan-device. You should get an output similar to this one:

nfc-scan-device uses libnfc 1.7.1
1 NFC device(s) found:
- pn532_uart:/dev/ttyACM0:
pn532_uart:/dev/ttyACM0

How To Setup an Internet Gateway using Ubuntu

No Comments

Setting up an Internet Gateway using Ubuntu is pretty straight forward. In order to do so, you will need:

  1. A computer with two network interfaces. One hooked to your WAN connection, the other one to your LAN.
  2. The computer needs Ubuntu installed with a minimum of software installed.
  3. Copy the script below to your gateway machine in /etc/network/if-up.d/00-my-gateway. Make sure that the script has the execute permission.
  4. Update the LAN and WAN variables in the script. For example, if eth0 is your WAN interface and eth1 is your LAN interface, then set WAN=eth0 and LAN=eth1.
  5. Reboot.

This script configures the Ubuntu Firewall to forward LAN traffic to the Internet but drops all unsolicited incoming traffic from the Internet. Your network will be stealth. You can use the online tool ShiedlsUP! at https://www.grc.com to test it.


#!/bin/bash

PATH=/usr/sbin:/sbin:/bin:/usr/bin

# Interfaces
LAN=lan
WAN=wan

#
# Delete all existing rules.
#
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

# Enable routing.
echo 1 > /proc/sys/net/ipv4/ip_forward

# Loopback traffic.
iptables -A INPUT -i lo -j ACCEPT

# Allow established connections.
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -i $LAN -j ACCEPT
iptables -A FORWARD -i $WAN -o $LAN -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow connections from the $LAN to the $WAN.
iptables -A FORWARD -i $LAN -o $WAN -j ACCEPT

# Enable masquerading.
iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE

# No forwarding from the $WAN to the $LAN.
iptables -A FORWARD -i $WAN -o $WAN -j DROP

# Drop everything else from the WAN ... Stealth mode.
iptables -A INPUT -i $WAN -j DROP

Installing memcached to use it with php

No Comments

Installing Memcached with php support in Ubuntu is a matter of a few steps:

sudo apt-get install memcached php5-memcached
sudo service apache2 restart

You can test if memcached is active by running this command:
echo "stats settings" | nc localhost 11211
You will end up with a response like this one:

STAT maxbytes 67108864
STAT maxconns 1024
STAT tcpport 11211
STAT udpport 11211
STAT inter 127.0.0.1

STAT item_size_max 1048576
STAT maxconns_fast no
STAT hashpower_init 0
STAT slab_reassign no
STAT slab_automove 0
END

How to rename a user in Linux

No Comments

Simply issue this command:

usermod -m -d /home/new-account-name -l new-account-name old-account-name

It creates the home directory if it does not exists. It also copy the stuff of the old user into the new user account.

How to display the version of Ubuntu you are running

No Comments

From a terminal window, type in:

lsb_release -a

How to use the command line to make the internal speaker beep

No Comments

Two simple steps:

Install the beep utility. Executing beep on the command line will make the internal speaker beep.

apt-get install beep

Add pcspkr to /etc/modules to load it at boot time. You can load it manually by executing

modprobe pcspkr

How to prevent SSHD to listen on an address family

No Comments

It is possible to control on which address family sshd will listen to. In /etc/ssh/sshd_config, simply add

AddressFamily any

to listen to IPv4 and IPv6 addresses. This is the default. Alternatively, add one of these to listen only to IPv4 (inet) or IPv6 (inet6) respectively.


AddressFamily inet
AddressFamily inet6

How to assign a static IP address in Ubuntu

No Comments

Setting a static IP address in Ubuntu involves editing /etc/network/interfaces. If the interface is currently using DHCP, you will find these lines in the file.

auto lan
iface lan inet dhcp

You will have to replace the above lines with a section that looks like:

auto lan
iface lan inet static
address 192.168.1.80
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.200
dns-nameservers 8.8.8.8

Make the changes effective by either rebooting or by issuing this command:

sudo /etc/init.d/networking restart

How to find duplicate files on Linux?

No Comments

It is pretty straight forward in Linux, install fdupes.

sudo apt-get install fdupes

Type the following command to display the documentation

man fdupes

Accessing a serial port from a web server

No Comments

On most Linux distribution, it is impossible to access a serial port (ex. /dev/ttyS0) from a web server such as Apache or lighttpd using a cgi. Simply add the user under which the web server runs (www-data for example) to the group dialout. To do so, use vigr from the command line and add the user on the dialout group line. Such a line will typically look like:

dialout:x:20:myuser,www-data

Script listing all the keys on a memcache server

No Comments

This script lists all the keys on a memcache server.

#!/bin/bash
nc localhost 11211 > /tmp/$$.1 <<EOF
stats items
EOF
cut -d: -f2 /tmp/$$.1 | grep -v END | uniq  | sed 's/^/stats cachedump /' \ 
   | sed 's/$/ 1000/' > /tmp/$$.2
nc localhost 11211 < /tmp/$$.2 | grep -v '^END' | sort 
rm /tmp/$$.[12]

Ralink RT5572 based WiFi Usb Dongle setup on Ubuntu 12.04

44 Comments

The WiFi USB dongles based on the newest RT5572 chip set do not work out of the box on Ubuntu.  Unex DNUR-V72, D-Link DWA-160 Rev B and TP-Link TL-WDN3200 dongles are based on this chipset.

You will need to compile the source code of the driver to make it work.  Do not leave this page!  This involves only a few easy steps.

1. Save this page’s link.  You will have to reboot and come back to it.

2. Un-plug the WiFi USB dongle from your computer.

3. Reboot your computer.

4. Download the driver’s source code from the manufacturer website. Alternatively, you can download a version of this file from this site. Files have been already edited. Steps 9, 10 and 11 are then unnecessary. Note that the filename is slightly different (DPO_RT5572_LinuxSTA_2.6.0.1_20120629_EDITED.tar.bz2.bz2).

5. Open a terminal window.

6. Change to the directory that contains the driver’s source code downloaded previously.  For example,

cd /home/myuser/Downloads

7. Extract the source code.  You might need the modify the file name since Mediatek may publish newer source code.  For example (there is two bz2 extensions!),

tar xvf DPO_RT5572_LinuxSTA_2.6.0.1_20120629.tar.bz2.bz2

8. Change to the source code directory

cd DPO_RT5572_LinuxSTA_2.6.0.1_20120629

9. Edit the file os/linux/config.mk.  Set to y the two variables HAS_WPA_SUPPLICANT and HAS_NATIVE_WPA_SUPPLICANT_SUPPORT.  Your file shall shows

# Support Wpa_Supplicant
# i.e. wpa_supplicant -Dralink
HAS_WPA_SUPPLICANT=y
# Support Native WpaSupplicant for Network Manager
# i.e. wpa_supplicant -Dwext
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y

10. Edit the file os/linux/usb_main_dev.c. Add a line containing MODULE_LICENSE(“GPL”);. This line is important. The position of the line is important. Your file shall shows

MODULE_DESCRIPTION("RT2870 Wireless Lan Linux Driver");
MODULE_LICENSE("GPL");
#ifdef CONFIG_STA_SUPPORT
#ifdef MODULE_VERSION

11. Edit the file common/cmm_mac_usb.c and add the lines “#define usb_buffer_alloc(a, b, c, d) usb_alloc_coherent(a, b, c, d)” and “#define usb_buffer_free(a, b, c, d) usb_free_coherent(a, b, c, d)“. The position of the lines is important. Your file shall shows

#ifdef RTMP_MAC_USB

#define usb_buffer_alloc(a, b, c, d) usb_alloc_coherent(a, b, c, d)
#define usb_buffer_free(a, b, c, d) usb_free_coherent(a, b, c, d)

#include        "rt_config.h"

12. In the same directory as step #8, compile the driver’s source code. Type the following command:

sudo make

13. Install the driver. Type the following command:

sudo make install

14. Plug your WiFi USB dongle.
15. After a few seconds, you should see an interface called ra0 if you type the following command:

sudo ifconfig

16. Configure your connection as you would normally do.

Recording a terminal session under Linux

No Comments

It is possible to record a terminal session under Linux with ttyrec. It also records vi, emacs, etc. sessions.

Fisrt, install ttyrec

sudo apt-get install ttyrec

To start recording a session:

ttyrec

To replay a session recording:

ttyplay ttyrecord

Masquerading or replacing outgoing SMTP email address with Postfix

No Comments

Postfix can replace an outgoing email address by another one. To do so, you must perform these steps:

Add in /etc/postfix/main.cf the following line

smtp_generic_maps = hash:/etc/postfix/generic_maps

Add in hash:/etc/postfix/generic_maps a line for each email address you want to replaced.  The line shall contain the email address to replace followed by the new email address separated by a space.  For example:

user@machine-name emailaddress@domain.tld

Generate or update the map by issuing the following command

postmap /etc/postfix/generic_maps

Restart postfix by issuing the following command

service postfix restart

Create an ext3 or an ext4 partition without a journal

No Comments

Most of the time, having a journal for ext3 and ext4 partitions is pretty useful. Nevertheless, you can prevent creating a journal by adding the option ^has_journal. For example:

mkfs -t ext4 -O ^has_journal /dev/sdXn

Initializing a brand new disk with “parted”

No Comments

“parted” is a replacement for “fdisk” of Linux.  It can handle disks larger than 2 TB.  Issue this command to launch “parted” where /dev/sdL is the disk you want to initialize.

parted /dev/sdL

Create a partition table if it does not exists. For disks larger than 2 TB, you should use the gpt type. You can create such a partition table by issuing this command within “parted”. msdos is the legacy partition table type.

mktable gpt

To create a new partition, mkpart is used to do so. This parted command creates a primary ext4 partition, starting at the first cylinder to the last sector of the disk. You should align your partitions. You can use the parted command align-check to do so.

mkpart primary ext4 1 -1

Quit parted and create your partition using mkfs. For example,

mkfs -t ext4 -m 0 -O dir_index,filetype,sparse_super /dev/sdLX

You can type help to display the list of commands. You can type help followed by a command to display specific help related to this command.

How to use the loop device on Unix?

No Comments

The loop device on Unix lets access a file as a block device.  Disks are block devices.  So, it is possible to use a file as a disk.  The first step, create a file that will be used as a disk.

dd if=/dev/zero bs=1M count=100 of=/tmp/mydiskfile

Format your file as a file system.  If /dev/loop0 is already used, use /dev/loop1.

losetup /dev/loop0 /tmp/mydiskfile
mkfs.ext4 /dev/loop0
losetup -d /dev/loop0

losetup -d /dev/loop0 deletes the loop device

mount -o loop /tmp/mydiskfile /mnt

The file /tmp/mydiskfile  can now be used as a disk with /mnt as the mount point!

How to control the brightness of the display from command line?

No Comments

You can set the brightness of the display by issuing this command within a shell

echo 3 > /sys/class/backlight/acpi_video0/brightness

where 3 is the brightness level. Its value is from 0 up to the value in the file /sys/class/backlight/acpi_video0/max_brightness.

How to restore the normal scroll bars in Ubuntu 11?

No Comments

Simply create a file named /etc/X11/Xsession.d/80overlayscrollbars and put into it the following line:

export LIBOVERLAY_SCROLLBAR=0

or simply execute the following command

echo "export LIBOVERLAY_SCROLLBAR=0" > /etc/X11/Xsession.d/80overlayscrollbars

You need to do the above as root.  This fix also resolve the Eclipse scroll bars issues.

SSH login without password

No Comments

It is possible to securely connect to a SSH server without a password. To do so, you must perform the following steps. It assumes that both machine are running a flavor of Unix.

On the client machine, open a shell window and execute the following command to create your private and your public key.

ssh-keygen -t rsa

Login on the server using the account you want to setup and perform these steps:

mkdir ~/.ssh
chmod 700 ~/.ssh

The file id_rsa.pub can be found on your client machine in the ~/.ssh directory

Copy the content of the file id_rsa.pub into the file ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

You can also use ssh-copy-id to copy your public key to a remote host. A typical command is

ssh-copy-id youruser@example.com

From now on, no password will be asked when you will ssh to this server.

Blue Taste Theme created by Jabox