30 May 2014

redhat-centos-fedora : manually set ip address


3 ways to manually set or change ip address via terminal


1) via command line:


---------------------------
ifconfig eth0 10.0.1.27 netmask 255.255.255.0 up
echo nameserver 10.0.1.1 > /etc/resolv.conf
route add default gw 10.0.1.1

----------------------------




2) via configuration file (using DHCP):

vi /etc/syscontrol/networking/ifeth0-cfg


-------------------
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

--------------------


once done, you need to restart the newtork service:
$ service networking restart



3) via configuration file (manual configuration w/o DHCP):

vi /etc/syscontrol/networking/ifeth0-cfg

--------------------
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes            <----- boot="" check="" enable="" eth="" on="" span="" this="" to="">
NETWORK=10.0.1.0
NETMASK=255.255.255.0
IPADDR=10.0.1.27
USERCTL=no
GATEWAY=10.0.1.1
HWADDR=??:??: ...

--------------------


once done, you need to restart the newtork service:

service networking restart



4) via "setup" menu ... simply run command -->  setup in a terminal ...

this is the most easy way but, if you installed the OS using the "minimal" distribution,
the "setup" suite may not be available.
 

There are the instructions to install it:

yum install setuptool.x86_64 
 -- or --
yum install setuptool.i686

yum install system-config-network-tui system-config-firewall-tui system-config-firewall-base system-config-date system-config-services system-config-users



29 May 2014

Linux & usb

Just a quick guite to mount usb drives via command line:

use fdisk to list all the drives your OS can see:
then simply mount the one you need.

$ sudo fdisk -l
$ sudo mount /dev/sdb1 /mnt/usb


in case you get the error: "special device does not exist"
it is most probably due to an error on the usb device, try formatting it may solve.


Tip: to format a usb drive, enter the followint command

$ mkfs.vfat -n "NEW_DRIVE_NAME" -I /dev/sdx1

(*) replace /dev/sdx1 with the device name of your pendrive (list all the drives using fdisk -l )



3 Mar 2014

Centos: Squid + Report + Webmin gui


1) to install WEBMIN administration gui , you first have to manually ad the repository for YUM:



$ vi /etc/yum.repos.d/webmin.repo

----- add ----
[Webmin]
name=Webmin Distribution Neutral
#baseurl=http://download.webmin.com/download/yum
mirrorlist=http://download.webmin.com/download/yum/mirrorlist
enabled=1
----- add ----



2) then you have to download & install the webmin GPG public key:



$ wget http://www.webmin.com/jcameron-key.asc
$ rpm --import jcameron-key.asc



3) install webmin with yum:


$ yum install webmin



4) at this point you should have you GUI already running on port 10000:

       open url:  http://servername:10000


5) now you can install SQUID and SARG (squid analysis report generator):


$ rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
$ yum install squid sarg
$ find / -name sarg.conf 


6) UPDATE:

due to some needs, i ended up using the latest SARG version instead of the one supplied via YUM which is quite old and lacking of some nice features!

So these are the steps i followed:

1) unistalled sarg via YUM --> yum unistall sarg
2) download latest SARG --> wget http://sourceforge.net/projects/sarg/files/latest/download
3) extract it to /usr/src --> tar xvzf sarg.latest.tgz
4) install it --> basically you have to follow the isntruction in the README file
  • $ cd /usr/src/sarg-2.3.8
  • $ ./configure
  • $ make
  • $ sudo make install
remember to update your /etc/sarg/sarg.conf for your needs, especially for the folder where you want to save your reports.

NOTE for WEBMIN --> be sure to have the same config parameters in your sarg.cong and in your webming interface.


5) i installed my own version of cronjob to create a report every 15 minutes:

  • */15 9-19 * * * /usr/local/bin/sarg -d day-0 -f /etc/sarg/sarg.conf -n

6) last but not least, i also added an "hostalias" file to summarize the logs coming from the same domains:

--- add this line in the /etc/sarg/sarg.conf ---
hostalias /etc/sarg/hostalias

--- and add a new file named /etc/sarg/hostalias containing something like that ---
*.googlevideo.com www.googlevideo.com
*.googlevideo.com:443 www.googlevideo.com











DOS Batch to backup virutalbox machines

This DOS script can be used to schedule backups of your virtuabox machines.

The backup consist in a simple copy of the VMs file into a backup folder.
But this script, in case of a RUNNING machine, will also change the state of the vm to SAVESTATE before proceding with the backup, and will bring it back to RUNNING after the copy is completed.

Requirements:
  • gnugrep must be installed (download it from here . PS: remember to dowload also the "Dependencies" package form here, which contains the required DLLs if you don't already have it);
  • change the 3 variabiles (highlithed in red) according to your needs (without trailing backslash):
  1. VBDIR --> the location of the virtualbox manager installation
  2. VMDIR  --> the base forder of your virtualmachines files
  3. BAKDIR --> the folder where you want to copy the VMs to
  • create as many SUBSCRIPT as you need, one per each VM you want to backup; 
  • in each SUBSCRIPT, update the MYVM (yellow) variable with the name of the virtual machine (the one you see in the virtual box manager);


Script:


@echo off

set VMDIR="c:\virtual_machines"
set VBDIR="C:\Program Files\Oracle\VirtualBox"
set BAKDIR="D:\Backup\VM"

date /t > %BAKDIR%\bak.log
time /t >> %BAKDIR%\bak.log
@echo using virtualbox bin folder: %VBDIR%
@echo using virtualbox machines folder: %VMDIR%
@echo using backup folder: %BAKDIR%
cd /d %VBDIR% >> %BAKDIR%\bak.log


REM xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
REM SUBSCRIPT: create one per each VM to backup
REM xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
set MYVM=machine1
REM xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

set MYSTATUS=0
for /f "delims=" %%A in ('VBoxManage list runningvms^|grep -c %MYVM%') do set "MYSTATUS=%%A"
@echo BACKUP for: %VMDIR%\%MYVM%   -  Current status: %MYSTATUS%
if "%MYSTATUS%"=="1" VBoxManage controlvm %MYVM% savestate >> %BAKDIR%\bak.log
xcopy /D/S/Y %VMDIR%\%MYVM%\*.* %BAKDIR%\%MYVM%\ >> %BAKDIR%\bak.log
if "%MYSTATUS%"=="1" VBoxManage startvm %MYVM% >> %BAKDIR%\bak.log
@echo BACKUP OK >> %BAKDIR%\bak.log


REM xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
REM SUBSCRIPT: create one per each VM to backup
REM xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
set MYVM=machine2
REM xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

set MYSTATUS=0
for /f "delims=" %%A in ('VBoxManage list runningvms^|grep -c %MYVM%') do set "MYSTATUS=%%A"
@echo BACKUP for: %VMDIR%\%MYVM%   -  Current status: %MYSTATUS%
if "%MYSTATUS%"=="1" VBoxManage controlvm %MYVM% savestate >> %BAKDIR%\bak.log
xcopy /D/S/Y %VMDIR%\%MYVM%\*.* %BAKDIR%\%MYVM%\ >> %BAKDIR%\bak.log
if "%MYSTATUS%"=="1" VBoxManage startvm %MYVM% >> %BAKDIR%\bak.log
@echo BACKUP OK >> %BAKDIR%\bak.log