26.2.14

Choosing the fastest DNS by benchmarking

Today I used Google's public DNS servers with a WiFi hotspot, never used it so I read about it and came acrooss https://code.google.com/p/namebench/
I tried it with the ISPs DNS servers and got the following result (suggestions for improving) http://namebench.appspot.com/id/71560011 for 100 queries and http://namebench.appspot.com/id/73540001 for 200 queries.

22.2.14

Kali Linux install fail

I tried to install Kali in VBox with 4GB and for the second time on 8GB which wasn't enough, according to /var/log/syslog

So I checked the install docs and there was the answer how much should I use. So it's good to go throught the install docs before installing at http://docs.kali.org/installation/kali-linux-hard-disk-install and check the requirements.

After installing the system takes 9.7GB

21.2.14

Filesystem Hierarchy Standard

I just came across of Filesystem Hierarchy Standard (FHS). It is a standard that consists of a set of requirements and guidelines for file and directory placement under UNIX-like operating systems.
The guidelines are intended to support interoperability of applications, system administration tools, development tools, and scripts as well as greater uniformity of documentation for these systems.

The following directories, or symbolic links to directories, are required in /.


Directory Description
/bin Essential command binaries
/boot Static files of the boot loader
/dev Device files
/etc Host-specific system configuration
/lib Essential shared libraries and kernel modules
/media Mount point for removeable media
/mnt Mount point for mounting a filesystem temporarily
/opt Add-on application software packages
/sbin Essential system binaries
/srv Data for services provided by this system
/tmp Temporary files
/usr Secondary hierarchy
/var Variable data

Official site http://www.pathname.com/fhs/

REPLACE instead of SELECT and then INSERT or UPDATE

It's nice that MySQL has the replace query so instead SELECTing to check if the data exists in the DB and than INSERTing or UPDATEing I just need to write one query.

So instead this:
$q = "SELECT id FROM table WHERE name = 'value' AND name2 = 'value2' LIMIT 1;";
$id = $database->get_one($q);
if ($id > 0) {
    $q = "UPDATE table SET name = 'value', name2 = 'value2' WHERE id = $id LIMIT 1;";
}
else {
    $q = "INSERT INTO table (name, name2) VALUES ('value', 'value2');";
}
$database->query($q);

I just query once
$q = "REPLACE INTO table (name, name2) VALUES ('value', 'value2');";
$database->query($q);


More info at
http://blogs.coldbuffer.com/inserting-or-updating-records-using-mysql-replace
https://dev.mysql.com/doc/refman/5.0/en/replace.html

Great description and examples of Linux commands

Found a great description of some Linux commands at http://www.linfo.org/command_index.html which I definitely recommend for newbies. Some of my favourits:
mike@jarvis:/media/sdb1/www$ find . -type d -exec sudo chmod 0775 {} \;
mike@jarvis:/media/sdb1/www$ find . -type f -exec sudo chmod 0664 {} \;

mike@mikembp:~$ tail -f /var/log/apache2/error_log
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/imagick.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/imagick.so, 9): Library not loaded: /opt/local/lib/libpng15.15.dylib\n  Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20090626/imagick.so\n  Reason: image not found in Unknown on line 0
[Fri Feb 21 05:03:12 2014] [notice] Digest: generating secret for digest authentication ...
[Fri Feb 21 05:03:12 2014] [notice] Digest: done
[Fri Feb 21 05:03:12 2014] [info] Init: Seeding PRNG with 144 bytes of entropy
[Fri Feb 21 05:03:12 2014] [info] Init: Generating temporary RSA private keys (512/1024 bits)
[Fri Feb 21 05:03:13 2014] [info] Init: Generating temporary DH parameters (512/1024 bits)
[Fri Feb 21 05:03:13 2014] [info] Init: Initializing (virtual) servers for SSL
[Fri Feb 21 05:03:13 2014] [info] mod_ssl/2.2.24 compiled against Server: Apache/2.2.24, Library: OpenSSL/0.9.8y
[Fri Feb 21 05:03:13 2014] [notice] Apache/2.2.24 (Unix) DAV/2 PHP/5.3.26 mod_ssl/2.2.24 OpenSSL/0.9.8y configured -- resuming normal operations
[Fri Feb 21 05:03:13 2014] [info] Server built: Jul  7 2013 18:05:17

mike@mikembp:~$ id
uid=501(mike) gid=20(staff) groups=20(staff),401(com.apple.access_screensharing),503(access_bpf),0(wheel),12(everyone),33(_appstore),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),100(_lpoperator),204(_developer)

mike@mikembp:~$ du -sh /Users/mike/Movies/movie/
 29G    /Users/mike/Movies/movie/

mike@mikembp:~$ ps -ef |grep -i little
    0   112     1   0  5:03AM ??         0:20.64 /Library/Little Snitch/Little Snitch Daemon.bundle/Contents/MacOS/Little Snitch Daemon
  501   675   662   0  5:03AM ??         2:22.88 /Library/Little Snitch/Little Snitch Agent.app/Contents/MacOS/Little Snitch Agent
  501   686   662   0  5:03AM ??         0:54.07 /Library/Little Snitch/Little Snitch Network Monitor.app/Contents/MacOS/Little Snitch Network Monitor -psn_0_49164
  501 17552   782   0  7:59AM ttys004    0:00.00 grep --colour=auto --exclude-dir=.svn -i little

mike@mikembp:~/Sites$ sudo chown -R mike:_www *

mike@mikembp:~$ rsync -zva --progress Dropbox/bookmarks-firefox.json mike@jarvis:.
building file list ...
1 file to consider
bookmarks-firefox.json
      156268 100%   14.72MB/s    0:00:00 (xfer#1, to-check=0/1)

sent 36818 bytes  received 42 bytes  4336.47 bytes/sec
total size is 156268  speedup is 4.24

Learning about inodes

Yesterday I watched again Antitrust, but now in HD 720p to better see the commands he used :) He was playing with inodes to restore removed data and I became curious, because I heard and saw inodes, but never knew what are they.
For me useful info was at http://www.linfo.org/inode.html and http://www.cyberciti.biz/tips/understanding-unixlinux-filesystem-inodes.html I didn't know about the command stat:
mike@mikembp:~$ stat -x /etc/php.ini
  File: "/etc/php.ini"
  Size: 70183        FileType: Regular File
  Mode: (0644/-rw-r--r--)         Uid: (    0/    root)  Gid: (    0/   wheel)
Device: 1,2   Inode: 26362462    Links: 1
Access: Mon Feb  3 14:44:46 2014
Modify: Mon Feb  3 14:44:46 2014
Change: Mon Feb  3 14:44:46 2014

mike@mikembp:~$ stat -x /Users/mike/
  File: "/Users/mike/"
  Size: 2958         FileType: Directory
  Mode: (0755/drwxr-xr-x)         Uid: (  501/    mike)  Gid: (   20/   staff)
Device: 1,2   Inode: 326834    Links: 87
Access: Sat May 18 08:22:51 2013
Modify: Fri Feb 21 07:40:46 2014
Change: Fri Feb 21 07:40:46 2014

20.2.14

Network and bandwidth monitoring with darkstat

I was searching for a networking monitor solution and found http://hints.macworld.com/article.php?story=20020521011343792

Darkstat's source code is available at http://unix4lyfe.org/darkstat/ After starting it runs as a daemon in the background.
mike@mikembp:~$ sudo darkstat -i en0
It binds itself to the TCP port 667 which can be changed and also other things:
mike@mikembp:~$ darkstat --help
darkstat 3.0.718 (using libpcap version 1.1.1)

usage: darkstat [ -i interface ]
                [ -f filter ]
                [ -r capfile ]
                [ -p port ]
                [ -b bindaddr ]
                [ -l network/netmask ]
                [ --base path ]
                [ --local-only ]
                [ --snaplen bytes ]
                [ --pppoe ]
                [ --syslog ]
                [ --verbose ]
                [ --no-daemon ]
                [ --no-promisc ]
                [ --no-dns ]
                [ --no-macs ]
                [ --no-lastseen ]
                [ --chroot dir ]
                [ --user username ]
                [ --daylog filename ]
                [ --import filename ]
                [ --export filename ]
                [ --pidfile filename ]
                [ --hosts-max count ]
                [ --hosts-keep count ]
                [ --ports-max count ]
                [ --ports-keep count ]
                [ --highest-port port ]
                [ --wait secs ]
                [ --hexdump ]
                [ --version ]
                [ --help ]


Additional resources, info:
https://thejimmahknows.com/network-monitoring-ntop-vs-darkstat/ http://slackblogs.blogspot.com/2011/06/monitor-traffic-usage-using-darkstat.html