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

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...