Thursday, 23 September 2010

Virtualization

Vmware Server uses two ports: 8333/TCP(HTTPS) for web administration and 902/TCP for console.


To fix error when trying to install VMWare Server 2.0 on Windows:
Start > Control Panel
Open Administrative Tools
Open Local Security Settings
Click Software Restriction Policies a. If no software restrictions are defined, right click the Software Restriction Policies node and select New Software Restriction Policy
Double click Enforcement
Select “All users except local administrators”
Click OK
Reboot the machine or run gpupdate /force

Resize virtual hard disk. 
You can do this using vmware-vdiskmanager program. For example to set new size to 20 GB:
vmware-vdiskmanager -r 20GB disk.vmdk

Show running virtual machines in Vmware server:
vmrun -T server -h http://127.0.0.1:8222/sdk -u root -p password list

Tuesday, 21 September 2010

Printing tips in Linux


  • lpr sends print jobs to specified queue

  • Usually queue is a directory /var/spool/cups

  • CUPS daemon monitors queues and connections from network

  • Old printer daemon is LPD

  • CUPS sends print queues to printers

  • Ghost script translates from Postscript to specific printer language

  • Ghost sript is injected into the print queue via smartfilter

  • CUPS has it's own collection of smartfilters

  • CUPS is available via http://localhost:631

  • U can print some pages on one sheet using mpage command

  • lpq command is used to display print queues

  • lprm command is used to delete jobs from print queue

  • lpc command and CUPS web panel are used to manage print queues

  • Enable, disable queue: cupsenable, cupsdisable

  • lpmove command moves jobs from one queue to another

Friday, 17 September 2010

DPKG & APT

In order not to always read mans, I have collected these short tips.

dpkg database: /var/lib/dpkg
Apt cache, that stores packages: /var/cache/apt/archives
To clean this cache:
aptitude clean

Only download package, without installing:
aptitude download package_name

List all installed packages:
dpkg -l
or
apt-cache pkgnames

List all files of the package:
dpkg -L package

What package contains a file?
dpkg -S path_to_file

Print information about package:
dpkg -p package

What packeges are upgradeable?
apt-show-versions -u

Shows what packages are installed partially and suggests, how to correct this situation
dpkg -C

Verify package, showing what files(including configuration) are changed:
debsums -ac package_name

Backup and restore list of installed soft:
dpkg --get-selections > /backup/installed-software.log
dpkg --set-selections < /backup/installed-software.log

Remove package with configuration files:
dpkg -P package

Reinstall package:
aptitude reinstall package

Add CD-ROm to source file
apt-cdrom add

Upgrade the whole distro:


  • Backup everything important

  • Do everything using “screen” command, if you control server via SSH.

  • dpkg --audit

  • Change sources in /etc/apt/sources.list

  • aptitude update

  • aptitude install aptitude

  • aptitude safe-upgrade

  • aptitude full-upgrade




Configure update servers
# apt-setup

Missing key for updates
gpg --keyserver pgpkeys.mit.edu --recv-key  010908312D230C5F
gpg -a --export key_ID |  apt-key add -

Before installing Vmware tools
apt-get install build-essential linux-headers-`uname -r` psmisc

RPM

Main RPM configuration file is /usr/lib/rpm/rpmrc. This file sets a variety of options, mostly related to the CPU optimizations used when compiling source packages. You shouldn’t edit this file, though; instead, you should create and edit /etc/rpmrc (to make global changes) or ~/.rpmrc (to make changes on a per-user basis). The main reason to create such a file is to implement architecture optimizations—for instance, to optimize your code for your CPU model by passing appropriate compiler options when you build a source RPM into a binary RPM.

What package contains file?
rpm -qf /sbin/iptables

Show information about the packege:
rpm -qi package

List all installed packages
rpm -qa

List files in package
rpm -ql package

List configuration files of the package:
rpm -qc package

View changelog of the package:
rpm -q --changelog package

Upgrade or install package:
rpm -U packagename

Upgrade package only if it exists:
rpm -F packagename

Install package older than existing one:
rpm -i --oldpackage

Yum


Update package:
yum update or upgrade package

Check updates:
yum check-update

Remove package with yum:
yum remove or erase package

Information about package:
yum list package

Discovery alive hosts using nmap

This script searches alive hosts, using ping, tcp and udp scanning. Nmap input syntax is accepted, for example 192.168.1.0/24.
Two files are generated at the end:
network_number_alive_hosts - results of script, list of alive ip addresses
network_number_log - log of the scan

#!/bin/bash
#variables
name=$(echo $1 | tr '/' '_')_alive_hosts
log=$(echo $1 | tr '/' '_')_log
tcp_ports=21,22,23,25,53,80,88,110,135,137,148,139,443,445,990,8080,3128
udp_ports=53,88,123,137,138,161,500,514
echo -e "$(date)\nDiscovery of network $1 started" > $name

#ping scan
nmap -sP -oG ping.txt $1 > $log
cat ping.txt | grep Up | cut -d" " -f2 >> $name
cat ping.txt | grep Down | cut -d" " -f2 > nmap.txt
#tcp&udp scan
nmap -PN -T4 -sT -sU -p T:$tcp_ports,U:$udp_ports -iL nmap.txt -oG ports.txt >> $lcat ports.txt | egrep "open/|closed" | cut -d" " -f2 >> $name
echo "Finish of discovery: $(date)" >> $name
#delete temp files
rm nmap.txt ping.txt ports.txt
Search alive hosts from network list and compares with list of existed addresses

#!/bin/bash
folder=$(date +%d-%m-%g)
mkdir $folder
while read line
do
#variables:
name=$(echo $line | tr '/' '_')_alive_hosts
log=$(echo $line | tr '/' '_')_log
tcp_ports=21,22,23,25,53,80,88,110,135,137,148,139,443,445,990,8080,3128
udp_ports=53,88,123,137,138,161,500,514
echo -e "$(date) - Discovery of network $1 started" > $folder/$name
#ping scan
nmap -sP -oG ping.txt $line > $folder/$log
cat ping.txt | grep Up | cut -d" " -f2 >> $folder/$name
cat ping.txt | grep Down | cut -d" " -f2 > nmap.txt

#tcp&udp scan
nmap -PN -T4 -sT -sU -p T:$tcp_ports,U:$udp_ports -iL nmap.txt -oG ports.txt >> $folder/$log
cat ports.txt | egrep "open/|closed" | cut -d" " -f2 >> $folder/$name
echo "Finish of discovery: $(date)" >> $folder/$name
cat $folder/$name | egrep -iv "discovery" >> $folder/final

#delete temp files
rm nmap.txt ping.txt ports.txt

done

sort ips > ips2\
sort $folder/final > final
comm -23 final ips2 > newhosts

rm final ips2

Friday, 10 September 2010

Linux backup

Backup files and databases to Linux box via scp with encryption and email notification

#!/bin/sh.
#Backup server options
server=11.11.11.111
user=user
key=/path/key.key
port=22222
backup_dir=/path/


#Archive options
date=`date +%F`
arc_name=arc_$date
tar_dir=/path
data="/var/www/ /etc"
days=22
logfile=/var/log/backup.log
admin=admin@domain.com



#Database options
mysql_u=user
mysql_p=password
databases=database




#Encryption options
gpg_key=email 



mysqldump --add-drop-table -u $mysql_u -p$mysql_p $databases > $tar_dir/$date.db 2>>$logfile &&

tar czf - --exclude={*.tar.gz,*.sql} --ignore-failed-read $tar_dir/$date.db $data > $tar_dir/$arc_name.tar.gz  | gpg -e -r $gpg_key > $arc_name-$date.tar.gz.gpg 2>>$logfile


 /usr/bin/scp -P $port -i $key $tar_dir/$arc_name.tar.gz.gpg $user@$server:$backup_dir 2>>$logfile &&
find $tar_dir -mtime +$days -exec rm {} \; 2>>$logfile &&
echo "$date - Backup successfull" >> $logfile ||
echo "There are some problems with backup on $arc_name" | mail -s "Backup: $arc_name problems" $admin

Backup data and databases to windows share folder

This small script encrypts and backups data and mysql databases to windows share using CIFS protocol. It also logs it's operations and sends notifications to administrator in case of problems.


#!/bin/sh 



#CIFS server options 

server= 

folder= 

user= 

pass= 

domain=DOMAIN 



#Logs and notifications options 

admin=Administrator e-mail 

logfile=/var/log/backup.log 



#Encryption options 

key=GPG public key ID

#Archive options 

arc_name=The name of archive 

backup_dir=where to store database copies 

data="what files and directories to backup" 

mountpoint=/mnt/backup days=10 - how many days to store archives 

date=`date +%d-%m-%Y` - date format 



#Mysql options 

databases="database1 database2" 

mysql_user=root 

mysql_pass=root 



mount.cifs //$server/$folder $mountpoint -ouser=$user,pass=$pass domain=$domain 2>>$logfile &&
/usr/bin/mysqlhotcopy --addtodest --user=$mysql_user --password=$mysql_pass $databases $backup_dir/db 2>>$logfile && 

tar czf - $data $backup_dir/db | gpg -e -r $key > $mountpoint/$arc_name-$date.tar.gz.gpg 2>>$logfile &&
find $mountpoint -mtime +$days -exec rm {} \; 2>>$logfile &&

umount -f $mountpoint 2>>$logfile || 

echo "There are some problems with backup on $arc_name" | mail -s "$arc_name backup problems" $admin

Ping does not work

Today I would like to discuss a banal situation: host A is directly connected to host B, ping from host A to host B does not work. What are...