Sierra Aircard 320U auto connect

I needed to setup my AirCard to be able to automatically connect to the internet. 1. Connecting to modem Open a Linux terminal window connect to modem using command
minicom –s
AT command port uses standard settings 115200 bps and 8 bits none parity, 1 stop bit (115200-8N1) Then, go to Serial port Setup and use : /dev/ttyUSB2 or /dev/ttyUSB3 ** depending of modem and firmware. To verify modem is responding type ati5. It shows modem IMEI and Firmware.
Manufacturer: Sierra Wireless, Incorporated
Model: AirCard 320U
Revision: X1_4_5_0AP R5267 CNSZXD00000140 2012/07/02 13:48:56
IMEI: 357272044870768
IMEI SV: 3
FSN: CC40993248910
3GPP Release 8
+GCAP: +CGSM,+DS,+ES
2. Setup the APN Verify if there is a profile created using command at+cgdcont?
+CGDCONT: 1,"IP","telstra.datapack","0.0.0.0",0,0
+CGDCONT: 15,"IP","telstra.internet","0.0.0.0",0,0
Most Branding cards have already a profile 1 created with standard APN. If there is not profile or SIM account uses a different APN. It is possible to modify or create a new profile using command
at+cgdcont =,"IP","APN".
Where “PID” is the profile id that identifies the profile, typically profile 1 The modem should respond with "OK" Examples:
Telstra: at+cgdcont=1,”IP”,”Telstra.datapack”
Telstra: at+cgdcont=15,”IP”,”Telstra.internet”
Optional step: To change the Authentication method with the Carrier you can use the following commands: AT$QCPDPP=1,1,"password","username" 3. Set Radio On When using the modem in different computers it could inadvertently have set the Radio off. To enable the Radio use command: at+cfun =1. After that, it should have power light on solid and Data light flashing. On CDMA modems use at!pcstate=1 Note: To set the radio off use command at+cfun=0 as a result the two lights will be off. 4. Establishing a manual connection The following commands can be used to connect or disconnect on direct IP modems To manual connect: at!scact=1,<pid> To manual disconnect: at!scact=0,<pid> Example at!scact=1,1 Optional : Setting Auto connect in default profile. Modem can auto connect after powering up or resets using the default profile. To set a default profile use the following command: at!scdftprof=<pid> You can enable Auto connect in default profile using command: at!scprof=,"",1,0,0,0. 5. IP address obtained by carrier To check the IP address obtained by modem from the network use: at!scpaddr=<pid> For Example to Check IP address on profile 1 use command: at!scpaddr=1 6. Passing the IP on the computer Depending of the modem, it may not have the DHCP enabled by firmware.
ifconfig wwan0 up **
ifup wwan0
ifconfig
It will show wwan0 interface with same IP address s as shown in step 5. ** if it shows error "interface wwan0 not configured". We suggest adding the following lines in the interface file located: /etc/network/interfaces using any text editor
auto wwan0
iface wwan0 inet dhcp
7. Summary Summary of command s to create a Profile and make a manual connection using profile 3
at+cfun=1 
at+cgdcont=3,"IP","CustomAPN"
at!scdftprof=3
at!scprof=3,"",0,0,0,0
at!scact=1,3
at!scpaddr=3
Summary of commands to create a Profile 3 and using Auto connect feature
at+cfun=1 
at+cgdcont=3,"IP","CustomAPN"
at!scdftprof=3
at!scprof=3," ",1,0,0,0
8. Command to check modem status: at!gstatus?


Raspberry Pi Router + 4G Uplink

I wanted to setup my Raspberry Pi as a 4G router for my small home office. My internet connection is provided by a Telstra 4G Sierra Aircard 320U USB modem. I run Raspbian which is Debian wheezy, optimized for the Raspberry Pi. Once you Pi is up and running you will need install some packages.

sudo apt-get install isc-dhcp-server

My setup has eth0 connected to my internal network. The beauty of the Sierra card when plugged in should automatically be detected and will appear as wwlan0. The first step is to edit /etc/network/interfaces.

sudo vi /etc/network/interfaces

We want the internet facing NIC to get an address from our ISP via DHCP and our internal NIC to have a static address. I am using 10.0.10.0/24 as my internal subnet but you can use any subnet you like as long as it is RFC 1918 compliant. Keep in mind a /24 (255 addresses) is most always big enough for a home network. Here is what my /etc/network/interfaces file looks like. If you decide to change the internal subnet, you'll need to edit my addresses to suit your setup.

auto lo
iface lo inet loopback
 
auto eth0
iface eth0 inet static
        address 10.0.10.1
        netmask 255.255.255.0
 
auto wlan0
iface wlan0 inet static
        address 192.168.10.1
        netmask 255.255.255.0
 
auto wwan0
iface wwan0 inet dhcp

Save the file and restart networking (or reboot)

sudo /etc/init.d/networking restart

Next I setup the DHCP server. Edit the DHCP server configuration file.

sudo vi /etc/dhcp/dhcpd.conf

Edit your DHCP configuration to suit your needs here is mine.

ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
 
subnet 10.0.10.0 netmask 255.255.255.0 {
  range 10.0.10.90 10.0.10.100;
  option broadcast-address 10.0.10.255;
  option routers 10.0.10.1;
  default-lease-time 600;
  max-lease-time 7200;
  option domain-name "genisx";
  option domain-name-servers 8.8.8.8;
  interface eth0;
}
 
subnet 192.168.10.0 netmask 255.255.255.0 {
  range 192.168.10.90 192.168.10.100;
  option domain-name-servers 8.8.8.8;
  option routers 192.168.10.1;
  interface wlan0;
}

I have 2 subnets setup, 1 to handle my internal network via eth0, and another for my wireless clients (I have my Raspberry Pi setup as a WiFi Access Point). Save the file and restart the DHCP service.

sudo /etc/init.d/isc-dhcp-server restart

You should recieve two ok messages.

[ ok ] Stopping ISC DHCP server: dhcpd.
[ ok ] Starting ISC DHCP server: dhcpd.

At this point you should be able to access your pi and receive an IP address via dhcp for any devices on your internal network. However, you won't be able to get any further on the network than your Pi itself. To solve this, we need to enable IP forwarding.

sudo echo 1 &gt; /proc/sys/net/ipv4/ip_forward

Next edit /etc/sysctl.conf and uncomment out the line that says net.ipv4.ip_forward = 1.

sudo nano /etc/sysctl.conf

# Uncomment the next line to enable packet forwarding for IPv4

net.ipv4.ip_forward=1

Save the file. The final step is to insert an iptables rule to allow NAT.

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

The iptables rules for nat we inserted above are not persistent and if you reboot they will be overridden by the default configuration (nothing). We can fix this by saving the rules and creating a little script to restore them as the network interfaces come up during boot. First, save your iptables rules to a file.

sudo iptables-save &gt; /etc/iptables.up.rules

Next create a script in /etc/network/if-pre-up.d/ with the following contents:

sudo vi /etc/network/if-pre-up.d/iptables
#!/bin/sh
#This script restores iptables upon reboot
iptables-restore &lt; /etc/iptables.up.rules
exit 0

Change ownership and permissions of the script so it will run at boot.

sudo chown root:root /etc/network/if-pre-up.d/iptables \
&& sudo chmod +x /etc/network/if-pre-up.d/iptables \
&& sudo chmod 755 /etc/network/if-pre-up.d/iptables

Voila. You can now reboot and your iptables rules will stay persistent.


Creating a bootable USB stick

If you ever need to run a DOS utility (eg. to flash a BIOS or a firmware), and want to painlessly create a bootable DOS USB key from Windows, this is for you. Grab yourself a copy of Rufus from here http://rufus.akeo.ie/ Rufus is an utility that helps format and create bootable USB flash drives, such as USB keys/pendrives, memory sticks, etc. It can be especially useful for cases where: you need to create USB installation media from bootable ISOs (Windows, Linux, UEFI, etc.) you need to work on a system that doesn't have an OS installed you need to flash a BIOS or other firmware from DOS you want to run a low-level utility Despite its small size, Rufus provides everything you need!


Creating Raspberry Pi SD Card

Fairly easy process on windows. Grab yourself SD Formatter from https://www.sdcard.org/downloads/formatter_4/ and install it. Plugin your SD card and run SD Formatter. Make sure you pick the correct drive letter in SD Formatter and hit the Option button. Format Type: Quick Format Size Adjustment: On Click OK and then click Format. You can download the latest NOOBS from here http://downloads.raspberrypi.org/NOOBS_latest Unpack it onto your SD card and your pretty much done. Pop the card into your Pi and turn it on, you can follow the prompts from there depending on what you would like to install.


apt-get fails with bzip2: (stdin) is not a bzip2 file.

Just remove the content of /var/lib/apt/lists directory:
sudo rm -fR /var/lib/apt/lists/*
then run:
sudo apt-get update


Raspberry Pi as a PXE, TFTP, NFS, proxy DHCP server

apt-get install syslinux-common #This is for pxe booting files.
apt-get install dnsmasq #Since I already have a router providing DHCP we need to use a proxy dhcp. dnsmasq is a great set of tools providing us with both tftp and proxy dhcp.
mkdir /srv/tftpboot #root folder for pxe server.
cp /usr/lib/syslinux/pxelinux.0 /srv/tftpboot/ #copy necessary files for pxe boot.
cp /usr/lib/syslinux/menu.c32 /srv/tftpboot/
mkdir /srv/tftpboot/pxelinux.cfg #folder for boot menu
vi /srv/tftpboot/pxelinux.cfg/default #Menu file
Add following info for /srv/tftboot/pxelinux.cfg/default
DEFAULT menu.c32
PROMPT 0
 
MENU TITLE PXE Boot
 
LABEL Test
MENU LABEL Test
Edit dnsmasq settings.
vi /etc/dnsmasq.conf
Just add following lines at the end of the file.
# Don't function as a DNS server:
port=0
 
# Log lots of extra information about DHCP transactions.
log-dhcp
 
# Dnsmasq can also function as a TFTP server. You may uninstall
# tftpd-hpa if you like, and uncomment the next line:
enable-tftp
 
# Set the root directory for files available via FTP.
tftp-root=/srv/tftpboot
 
# The boot filename.
dhcp-boot=/srv/tftpboot/pxelinux.0
 
# rootpath option, for NFS
#dhcp-option=17,/opt/ltsp/i386
 
# kill multicast
dhcp-option=vendor:PXEClient,6,2b
 
# Disable re-use of the DHCP servername and filename fields as extra
# option space. That's to avoid confusing some old or broken DHCP clients.
dhcp-no-override
 
# PXE menu
#pxe-prompt="Press F8 for boot menu", 3
 
# The known types are x86PC, PC98, IA64_EFI, Alpha, Arc_x86,
# Intel_Lean_Client, IA32_EFI, BC_EFI, Xscale_EFI and X86-64_EFI
pxe-service=X86PC, "Boot from network...", /srv/tftpboot/pxelinux
 
# A boot service type of 0 is special, and will abort the
# net boot procedure and continue booting from local media.
pxe-service=X86PC, "Boot from local hard disk", 0
 
# If an integer boot service type, rather than a basename is given, then the
# PXE client will search for a suitable boot service for that type on the
# network. This search may be done by multicast or broadcast, or direct to a
# server if its IP address is provided.
#pxe-service=x86PC, "Install windows from RIS server", 1
 
# This range(s) is for the public interface, where dnsmasq functions
# as a proxy DHCP server providing boot information but no IP leases.
# Any ip in the subnet will do, so you may just put your server NIC ip here.
dhcp-range=10.0.10.200,proxy,255.255.255.0
Restart dnsmasq to load config
root@pi:/srv/tftpboot#service dnsmasq restart
Try to boot a machine with pxe booting. Just to verify that's working. Next we need to install nfs support for sharing the mounted iso files.
root@pi:/srv/tftpboot#apt-get install nfs-kernel-server
root@pi:/srv/tftpboot#mkdir /tftpboot/iso #this is where we put distro iso files
root@pi:/srv/tftpboot#mkdir /tftpboot/nfs #this is where we share nfs files
root@pi:/srv/tftpboot#mkdir /tftpboot/nfs/ubuntu #folder for ubuntu dist
Edit nfs shares
root@pi:/srv/tftpboot/#vim.tiny /etc/exports
Add following line:
/srv/tftpboot/nfs/ubuntu/ *(ro,sync,no_subtree_check)
root@pi:/srv/tftpboot# mount -o loop iso/ubuntu-13.04.iso nfs/ubuntu/ #mount iso file to nfs folder
mount: warning: nfs/ubuntu/ seems to be mounted read-only.
Then we need to enable rpcbind and restart nfs
root@pi:/srv/tftpboot#update-rc.d rpcbind enable && update-rc.d nfs-common enable
root@pi:/srv/tftpboot#service rpcbind start
root@pi:/srv/tftpboot#service nfs-kernel-server restart
Add following entry to the /srv/tftpboot/pxelinux.cfg/default
DEFAULT menu.c32
PROMPT 0
 
MENU TITLE PXE Boot
 
LABEL Test
MENU LABEL Test
 
LABEL Ubuntu
        MENU LABEL ^Ubuntu 13.04
        KERNEL nfs/ubuntu/casper/vmlinuz
        APPEND initrd=nfs/ubuntu/casper/initrd.lz boot=casper netboot=nfs
 nfsroot=192.168.0.180:/srv/tftpboot/nfs/ubuntu
Change IP to your server IP in default config file


Setting the query_cache_size in MySQL

So what size do you set the mysql query_cache_size variable to? The MySQL query cache is an in memory cache that stores the complete result sets of frequent SELECT queries. Instead of issuing the query again to the database engine, MySQL retrieves the result set from the cache and returns that to the client. The query cache is global, in that, all MySQL clients use the same query cache. The query caching functionality is very useful to websites that have a relatively static database and the pages are just a rendering of the data in the database. But query caching can also be useful, to some extent, to websites that have a high number of frequent SELECT statements from tables that change often. Increasing your query_cache_size will definitely have an impact on performance of a few high frequency queries. The decision on whether to increase the size of the variable query_cache_size can be easily made using the following mysql command. First login to mysql using the mysql command line client. Run the following command:
mysql> SHOW STATUS LIKE "qcache%";
+-------------------------+----------+
| Variable_name           | Value    |
+-------------------------+----------+
| Qcache_free_blocks      | 13525    |
| Qcache_free_memory      | 58761352 |
| Qcache_hits             | 70886035 |
| Qcache_inserts          | 2178358  |
| Qcache_lowmem_prunes    | 126387   |
| Qcache_not_cached       | 276082   |
| Qcache_queries_in_cache | 60985    |
| Qcache_total_blocks     | 136687   |
+-------------------------+----------+
8 rows in set
The Qcache_free_memory shows that currently there is about 58 MB of free memory from the available 256 MB. However, note that there is another variable called Qcache_lowmem_prunes which indicates how many times MySQL had to prune the query cache (remove some data) to make space for the outputs of other queries. This clearly indicates that increasing your query_cache_size will have a positive impact on performance. Try to increase the size of the cache till you get a very low value of Qcache_lowmem_prunes. To increase the query_cache_size you will have to adjust your my.cnf/ini. Add/adjust the following
query_cache_size = 536870912 or query_cache_size = 512MB
Then issue this command (setting the cache via cli you will have to use values in multiples of 1024). 512MB = 536870912 bytes.
SET GLOBAL query_cache_size = 536870912;
There shouldn't be a need to restart MySQL.


Purge BINARY logs on windows

If your like me and find that your windows MySQL server is filling up disk space with it's binary logs in a Master-Master replication setup, you will have to setup a script/routine to run the following each night. First, set expire_logs_days to be 10 in my.cnf/ini (10 or 4 or whatever days you wish to keep you binary logs for) [mysqld] expire_logs_days=10 Next, log in to mysql and run this
PURGE BINARY LOGS BEFORE (date(now()) + interval 0 second - interval 10 day);
Note the query's date and time
mysql> select date(now()) + interval 0 second - interval 10 day;
+---------------------------------------------------+
| date(now()) + interval 0 second - interval 10 day |
+---------------------------------------------------+
| 2012-12-11 00:00:00                               |
+---------------------------------------------------+
1 row in set (0.00 sec)
 
mysql>
Thus, the PURGE BINARY LOGS command will delete all binlogs whose datetime stamp predates 2012-12-11 00:00:00. Finally, run this command
SET GLOBAL expire_logs_days = 10;
That's it. No restart needed for installing expire_logs_days.