Monday, August 20, 2012

Message center number setting in Android?


I found it very strange when I didn't find any setting to set the sms center number in the default android sms app. For most of the providers it usually obtain the SMSC setting from the operator and set it internally. But it would be great to provide an option to change it in the setting, in case I want to use a different message center number. 

If you facing issues in sending or receiving sms, your message center number might be empty or wrong! Like my case, it sometime happens because of the poor service providers like bsnl. 

You can follow the following steps to check and update it. 
1. Dial *#*#4636#*#*.
2. Select Phone Information from the Menu. 
3. Scroll down to the "SMSC" setting. There are two options refresh and update. Try refresh to check if it gets the message center number from your operator. If not, then you can call your operator to get it, and then update it.

Happy Messaging on Android!!

Sunday, June 10, 2012

Android Reverse USB Tethering


Android usb tethering is a great feature provided in my android but sometime I feel the need to have reverse tethering. Using reverse tethering I can use my system internet on android phone via usb while my phone getting charged. It certainly helps in situations where there is a restricted access available on wifi and you don't have enough data usage or mobile network coverage on your phone like in my office. I did it on my Centos Linux box with Galaxy S but this should work with any other linux os and android phone having firmware with usb tether option.

Note: This can only be done if your phone is rooted, which may also cause to void your manufacturer warranty. Please don't follow if you don't know what you are doing.

Procedure:
 1. First of all enable the tethering on your phone. Settings > Wireless and network > more >Tethering & Portable > Check USB Tethering option. There should be USB0 interface appear on your system as soon as do this. 

root  ~ : ifconfig -a usb0
usb0      Link encap:Ethernet  HWaddr 02:07:30:34:35:3D 
          inet addr:192.168.42.118  Bcast:192.168.42.255  Mask:255.255.255.0
          inet6 addr: fe80::7:30ff:fe34:353d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13 errors:0 dropped:0 overruns:0 frame:0
          TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1200 (1.1 KiB)  TX bytes:7095 (6.9 KiB)

2. Note the IP address (192.168.42.118) of the device interface usb0 from the system using above command.

3. Now get the IP address from the device. Login to device using android adb tool(provided with android sdk).

Note: You may have to enable the root access to adb from the developer option settings. 

root  ~ : adb shell
shell@android:/ $ su
shell@android:/ # netcfg
lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:00:00:00
svnet0   UP                                     0.0.0.0/0   0x000000d1 a0:00:00:00:00:00
ifb0     DOWN                                   0.0.0.0/0   0x00000082 c6:cd:01:c2:8f:40
ifb1     DOWN                                   0.0.0.0/0   0x00000082 aa:37:52:c1:b9:ad
sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
ip6tnl0  DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
wlan0    DOWN                                   0.0.0.0/0   0x00001002 b4:07:f9:73:46:d1
rndis0   UP                              192.168.42.129/24  0x00001043 4a:35:0f:bc:01:19

Note down the IP address of the device (192.168.42.129).

4. Check the connectivity of both the interfaces. Ping from device to system and system to device. 

shell@android:/ # ping 192.168.42.118
PING 192.168.42.118 (192.168.42.118) 56(84) bytes of data.
64 bytes from 192.168.42.118: icmp_seq=1 ttl=64 time=1.36 ms
64 bytes from 192.168.42.118: icmp_seq=2 ttl=64 time=0.779 ms
64 bytes from 192.168.42.118: icmp_seq=3 ttl=64 time=0.705 ms

root  ~ : ping 192.168.42.129
PING 192.168.42.129 (192.168.42.129) 56(84) bytes of data.
64 bytes from 192.168.42.129: icmp_seq=1 ttl=64 time=1.16 ms
64 bytes from 192.168.42.129: icmp_seq=2 ttl=64 time=0.812 ms
64 bytes from 192.168.42.129: icmp_seq=3 ttl=64 time=0.791 ms

5. Add system as the default gateway for the android.
shell@android:/ # route add default gw 192.168.42.118 dev rndis0

6. Add the dns server setting to the device.
shell@android:/data # setprop net.dns1 8.8.8.8
shell@android:/data # setprop net.dns1 4.2.2.2

7. Enable the port forwarding on the system. 
root  ~ : echo 1 > /proc/sys/net/ipv4/ip_forward

8. Add the masquerade setting in the system firewall and map this with system's lan interface eth0 or em1( what ever the name that are using in your system. )

root  ~ : iptables --flush -t nat
root  ~ : iptables --table nat --append POSTROUTING --out-interface em1 -j MASQUERADE
root  ~ : iptables --append FORWARD --in-interface usb0 -j ACCEPT 
9. Check the net connectivity from the device using ping and other applications. 
shell@android:/data # ping google.com                                         
PING google.com (74.125.228.37) 56(84) bytes of data.
64 bytes from iad23s06-in-f5.1e100.net (74.125.228.37): icmp_seq=1 ttl=42 time=321 ms
64 bytes from iad23s06-in-f5.1e100.net (74.125.228.37): icmp_seq=2 ttl=42 time=333 ms
64 bytes from iad23s06-in-f5.1e100.net (74.125.228.37): icmp_seq=3 ttl=42 time=315 ms

Note: 
1. It will not show any tethering connection icon in notification bar like 3G or wifi.

2. The routing done on the device is not permanently saved on the device. Once disconnected from the system, you'll have to repeat the steps on the device to enable it again.


Tuesday, June 5, 2012

MySQL Database Incremental Backup Implementation


It is the most common requirement for those who use big mysql databases in their production. Most of the people generally take the full dump of the mysql db once a week or daily. But the disadvantage of taking full dump is it may take long time to backup and restore. Also if the backups are incremental and compressed then it takes small amount of data to be transferred to backup site.

The best backup strategy is to use the full and incremental backups. The incremental backups should have short time backup frequency ( eg. 5 or 6 hours ) and once a week is enough for the full backup. It can be done with the help of mysql utility program which works for either of the mysql database engines ( eg. MYISAM and innodb ). 


Working

The key to implement the incremental backup is to use the mysql 'binary logs'. We can configure the the mysql to generate the binary log files which contains the mysql db statements needed to update the db since the last incremental or the full backup.
The full db backup can taken with the help of mysqldump utility.

Utilities used

* mysqladmin & mysqldump comes with mysql-client package.
* mysqlbinlog comes with mysql-server package.
* Any command line FTP client program to copy the backup logs to ftp server. 

Backup Plan

1. Firstly generate the complete backup of the dbs with utility mysqldump. Compress this full backup and store this on a remote ftp storage.
2. Enable the binary logging and start storing the current binary logs which contains every mysql statement which modifies the db after the full backup.
3. Configure the binary logs in such a way that every (5 or 6 hour) the current binary log file is closed and ftp'd to the backup storage and a new binary log file is created to record the changes in the db.
4. Automate the step 3. once a week, create full backup and cleanup the previous full backup and now-obsolete binary logs from the FTP storage server.

Restore Plan

1. Copy the full backup and all the binary log files to the db server. Restore the full backup after creating the db if the db do not exists.
2. Restore the incremental binary files consecutively using the utility programs "mysqladmin" and "mysqlbinlog". The db is now uptodate to the moment of last incremental backup.
3. After complete restoration, once again take the full backup of the entire db.



Implementation

1. Binary logging is configured in the mysql server.

vim /etc/mysql/my.cnf
add the folling line:
log-bin=mybinlog

"binlog_do_db" can be used to specify the dbs for which we want to enable the binary logging. If we use this statement alone then it means all rest of the dbs which are not specified will have binary logging turned off. We can specify the multiple dbs using this statement by adding repeated enties, like:

binlog_do_db = db1
binlog_do_db = db2

"binlog_ignore_db" can also be alternatively used to specify the dbs, for which we do not want to turn on the binary logging. We can specify the multiple dbs using multiple statements like previous example.

Note: We should use the above statements very carefully because they can dangerous in certain situations. The working these statements will be explained in next post.

Restart the mysql:
/etc/init.d/mysqld restart


Saturday, July 30, 2011

Sharing internet connection(3g or ethernet) over Wifi on Fedora

Here are the steps, that I used to share my Reliance Netconnect connection over the wifi, so that I can use it on my android phone.

Fist of all, connect to Reliance Netconnect on your linux system. You can use wvdial or network Manager for that. You can see this connection on ppp0 interface(could be different from system to system).

Reliance Connection:      ppp0
Wifi ad-hoc connection:  eth1

*interface name(eth1/ppp0) could be different from system to system. So please change it accordingly

Prepare WIFI interface(eth1):

# ifconfig eth1 up

Change the wifi on Ad-hoc mode
# iwconfig eth1 mode Ad-Hoc

Set the essid for shared network
# iwconfig eth1 essid hotspot

Set the key for the ad-hoc wifi
# iwconfig eth1 key 123456789

Set ip address to this interface
# ifconfig eth1 up 192.168.2.1 netmask 255.255.255.0



Set IP forwarding at kernel level:

# vim /etc/sysctl.conf
change entry "net.ipv4.ip_forward=0" to "net.ipv4.ip_forward=1"
# sysctl -p



Adding NAT ip rule in iptables:

# service iptables start
# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
# service iptables save
# service iptables restart
# chkconfig iptables on


That is it. Your Linux system is sharing ppp0 internet connection over the wifi eth1 using essid "hotspot".


Connecting your phone with wifi:


1. Set the static IP configuration on your phone as follows:

    IP Address :       192.168.2.2
    Netmask    :        255.255.255.0
    Gateway    :        192.168.2.1
    DNS           :         192.168.2.1( if you are using dnsmasq or local dns on linux system else use your pppo  connection dns )

Note: skip the above part if you are using dhcp on the linux system.

2. Scan for the ad-hoc wifi network with essid "hotspot" and connect to it.

Now you can start surfing on your phone. :)

Note:

1. Your Android phone need to be rooted for connecting to Ad-hoc Network.

2. You can share your ethernet Lan connection over wifi using this method. Just need to replace ppp0 interface with eth0.

3. You can add the wifi preparation steps to a script file. You can use this script to start this next time.

Tuesday, April 5, 2011

Creating a PXE boot kickstart server Centos

Packages required: tftp, dhcp & syslinux

1. Install the required packages on the server. Syslinux is usually by default installed on the server.

#yum install tftp-server dhcp syslinux

2. Edit /etc/xinet.d/tftp file to run the tftp service under xinetd daemon. Modify the following lines in the conf file as follows:

disable                 = no
server_args             = -s /tftpboot

Make sure the both the lines should be exactly like this, because we are going to use the /tftpboot dir as default root-pxe dir. If the path given here in server-args is different from our pxe root dir, then we'll normally get "PXE-T01: File not found." error. Save the above file after making the changes.

3. Restart the xinetd services to start the tftp service and make it executable on startup.

#service xinetd start
#chkconfig xinetd on

4. Copy the required files from the Syslinux dir to /tftpboot dir.

#cp /usr/lib/syslinux/{pxelinux.0,menu.c32,mboot.c32,memdisk,chain.c32} /tftpboot/

5. Create PXE Menu directory.

# mkdir /tftpboot/pxelinux.cfg

6. Create dir for centos image in tftpboot dir. Suppose you  have centos 5.5 i386 and centos 5.5 x86_64 linux iamges, then create dir as follows.

# mkdir -p /tftpboot/images/centos/i386/5.5
# mkdir -p /tftpboot/images/centos/x86_64/5.5

7. mount the linux iso image that you have to /mnt and copy initrd.img and vmlinuz files from the /mnt/images/pxeboot dir to the respective tftpboot image paths that you have created.

# mount -o loop /home/centos-5.5.i386.iso /mnt
# cp /mnt/images/pxeboot/{ initrd.img, vmlinuz} /tftpboot/images/centos/i386/5.5
# umount /mnt
# mount -o loop /home/centos-5.5.x86_64.iso /mnt
# cp /mnt/images/pxeboot/{ initrd.img, vmlinuz} /tftpboot/images/centos/x86_64/5.5
# umount /mnt

8. Edit dhcpd.conf file and add the following lines to the configuration. Use your pxe server ip in place of the 000.000.000.000.

allow bootp;
allow booting;
filename "pxelinux.0";
next-server 000.000.000.000;
option option-128 code 128 = string;
option option-129 code 129 = text;



9. Create a file /tftpboot/pxelinux.cfg/default for default menu and add the following.

default menu.c32
prompt 0
timeout 300
ONTIMEOUT local

MENU TITLE PXE MENU

LABEL Centos 5.5 x86
          MENU LABEL Centos 5.5 x86
          KERNEL images/centos/i386/5.5/vmlinuz
          APPEND ks initrd=image/centos/i386/5.5/initrd.img ramdisk_size=100000 ksdevice=eth0 ip=dhcp url --url http://path to ks file

 LABEL Centos 5.5 x86_64
          MENU LABEL Centos 5.5 x86_64
          KERNEL images/centos/x86_64/5.5/vmlinuz
          APPEND ks initrd=image/centos/x86_64/5.5/initrd.img ramdisk_size=100000 ksdevice=eth0 ip=dhcp url --url http://path to ks file


10.  Restart the dhcpd server and restart the xinetd service.

#service dhcpd restart
#service xinetd restart

You can add more images to your pxe configuration later on in the similar way.