Droping cache
[info]neelesh_gurjar

Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.

To free pagecache:

  • echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:

  • echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:

  • echo 3 > /proc/sys/vm/drop_caches

As this is a non-destructive operation, and dirty objects are not freeable, the user should run "sync" first in order to make sure all cached objects are freed.

 


Recovering deleted data from ext3 filesystem on linux
[info]neelesh_gurjar
Scenario:

Linux machine with/home having ext3 type of filesystem.
You have welcome.jpg file in /home/test. And you have deleted it by "rm -f " command.
Now we will recover that welcome.jpg

Step 1. --> Check which Filesystem /home is.

linux-remo:~ # df -h
Filesystem    Size     Used     Avail     Use%      Mounted on
/dev/sda       2 7.8G   5.3G     2.2G      71%          /
udev              122M    168K    121M       1%         /dev
/dev/sda3      12G       158M    11G         2%         /home
 

So we got Filesystem no - /dev/sda3


Step 2. -->  Debugfs to get necessary information

The debugfs program is an interactive file system debugger that is installed by default with most common Linux distributions. This program is used to manually examine and change the state of a filesystem. In our situation, we're going to use this program to determine the inode which stored information about the deleted file and to what block group the deleted file belonged.

linux-remo:~ # debugfs /dev/sda3
debugfs 1.41.1 (01-Sep-2008)

debugfs:  cd test

debugfs:  ls -d
32769  (12) .    2  (4084) ..   <32770> (4072) welcome.jpg    ---> Here we got Inode number which is in RED


The next command we want to run is imap, giving it the inode number above so we can determine to which block group the file belonged. We see by the output that it belonged to block group 4.

debugfs:  imap <32770>
Inode 32770 is part of block group 4    -----------> Here we got block group no. ---> BG
located at block 131074, offset 0x0100



Running the stats command will generate a lot of output. The only data we are interested in from this list, however, is the number of blocks per group. In this case, and most cases, it’s 32768. Now we have enough data to be able to determine the specific set of blocks in which the data resided. We're done with debugfs now, so we type q to quit.

debugfs: stats
<< lots of content>>
Blocks per group:         32768   ---> BPG
<<lots of content>>

debufs: q    -------> To quit debugfs


Step 3.  --> Recovering data in dat format.

The next thing we need to do is pull all unallocated blocks from block group 56 so we can examine their content. The blkls program, from The Sleuth Kit (TSK), allows us to do just that. We simply need to know the device file, a range of blocks, and have enough space in the appropriate place to output this data. Using the information above, we can calculate the block range by multiplying the block group number and the block group size and then multiplying the block group number plus one by the blocks per group minus one. In this case, the formula would look like this:

(BG * BPG) through ((BG + 1) * BPG -1)

In above example, it will look like: 
BPG --> 32768
BG --> 4
(4 * 32768) through ((4+1) * 32768 -1)
131072 through 163839

So now need to give following command:

linux-remo:~ # blkls /dev/sda3 131072-163839 > /root/block.dat


Step 4. -->  Recovering file from dat file using "Foremost" tool..

Create output directory first.
linux-remo:~ # mkdir /root/output   

linux-remo:~ # foremost -dv -t jpg -o /root/output/ -i /root/block.dat
Foremost version 1.5.6 by Jesse Kornblum, Kris Kendall, and Nick Mikus
Audit File
 
Foremost started at Sat Sep 26 12:11:59 2009
Invocation: foremost -dv -t jpg -o /root/output/ -i /root/block.dat 
Output directory: /root/output
Configuration file: /usr/local/etc/foremost.conf
Processing: /root/block.dat
|------------------------------------------------------------------
File: /root/block.dat
Start: Sat Sep 26 12:11:59 2009
Length: 125 MB (132108288 bytes)
 
Num Name (bs=512)       Size File Offset Comment 
 
0: 00012272.jpg      65 KB    6283264  (IND BLK bs:=4096)
**|
Finish: Sat Sep 26 12:12:03 2009
 
1 FILES EXTRACTED
jpg:= 1
------------------------------------------------------------------
 
Foremost finished at Sat Sep 26 12:12:03 2009

And here we got the jpg file in /root/output directory. Filename will be different that original. But content will be same.

Comparing size only works, of course, if you "know your data". Integrity checking programs such as Tripwire play a big role in a recovery operation as you can identify the recovered data without ever inspecting the content, as well as verify its integrity. This becomes quite useful if the information you're attempting to recover is confidential and you are not authorized to view the data.

File formats supported by Foremosts are jpg, gif, png, bmp, avi, exe, mpg, wav, riff, wmv, mov, pdf, ole, doc, zip, rar, htm, and cpp. If you need to recover data beyond these built-in data types, you will need to define custom types in Foremost's configuration file  foremost.conf.
 




 
 




Authentication issue for Accessing Samba server from Windows 98
[info]neelesh_gurjar
I was getting below error in samba log for accessing Samba from Windows 98

ntlm_password_check: LM password, NT MD4 password in LM field and LMv2 failed for user

Solution --> In smb.conf insert following lines under global section.

ntlm auth = Yes
client ntlmv2 auth = Yes

And restart samba.

Autologin with getty on linux console
[info]neelesh_gurjar
1. Create autologin.c and put following code in it.

int main()
{
execlp( "login", "login", "-f", "andrew", 0);
}

2. Compile it with following command:

cc autologin.c -o autologin

3. Do following changes in /etc/inittab
Please add "-n -l /usr/sbin/autologin" immidiate after "/sbin/getty"
Your line will be like this:

c1:12345:respawn:/sbin/agetty -n -l /usr/sbin/autologin 38400 tty1 linux


4. Reboot

Creating link with mount --bind
[info]neelesh_gurjar
In linux users home folders are in /home. Many times we need it in /var/www/html but we do not want to change default setting. Then there is a simple workaround for this.

Step 1. : Just create directory home under /var/www/html
Step 2. : mount --bind /home /var/www/html/home
Step 3. : Put above command in init script. For eg. If you are using CentOS then put it in /etc/rc.local

And your link is ready. :)

(no subject)
[info]neelesh_gurjar
Bid on GetAFreelancer projects
 

Compiling Apache, mysql and PHP
[info]neelesh_gurjar
Compiling Apache for fully dynamic web server
1. Download Apache sourcecode from http://apache.org
2. Extract it and enter into the extracted directory
3. ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all

make ; make install
4. Dowload PHP from php.net. Then extract it and enter the extracted directory
5. ./configure --with-apxs2=/usr/local/apache2/bin/apxs
--with-mysql --prefix=/usr/local/apache2/php
--with-config-file-path=/usr/local/apache2/php
--enable-force-cgi-redirect --with-zlib --with-gettext
--with-gdbm --enable-mbstring=all

make ; make install
6. cp -p .php.ini-recomanded /usr/local/apache2/php/php.ini
7. Go to /usr/local/apache2/bin
8. start apache with following cmd
./apachectl start

Setting up Samba PDC for Multiple domains
[info]neelesh_gurjar
We will setup 2 domains mydomain1 & mydomain2 on 1 linux machine with samba.

1. Create 2 samba config files in /etc/samba/
     a. smb.conf_mydomain1
     b. smb.conf_mydomain2

2. Your smb.conf_mydomain1 will look like below:

[global]
        workgroup = mydomain1
        netbios name =server1
        time server = Yes
        domain logons = Yes
        os level = 65
        preferred master = Yes
        domain master = Yes
        encrypt passwords = yes
        smb passwd file = /etc/samba/smbpasswd
        security = user
        mangling method = hash
        add machine script = /usr/sbin/useradd -d /dev/null -g trust -s /bin/false -M %u
        log file = /var/log/samba/log.%m
        log level = 3 passdb:5 auth:10 winbind:2
        logon path = \\%L\profiles\%U
        logon drive = H:
        logon home = \\%L\%U\.profile
        logon script = logon.cmd
        interfaces = 192.168.2.249/24
        bind interfaces only = yes
        lock directory = /var/lib/samba/locks/server1
 
[homes]
        read only = No
        browseable = Yes
        create mask = 0644
        directory mask = 0755
 
 
[netlogon]
        path=/var/lib/samba/netlogon
        guest ok = yes
 
[profiles]
        path=/var/lib/samba/profiles
        browseable = yes
        read only = No
        create mask = 0600
        directory mask = 0700
        root preexec = PROFILE=/var/lib/samba/profiles/%u; if [ ! -e $PROFILE ]; \
then mkdir -pm700 $PROFILE; chown %u:%g $PROFILE;fi

3. Following lines will get change in smb.conf_mydomain2 remaining will be same like above:

workgroup = mydomain2
netbios name =server2
lock directory = /var/lib/samba/locks/server2

4. Then create below directories:
     /var/lib/samba/locks/server1
     /var/lib/samba/locks/server2

5.  Start samba using below commands:
      
      smbd -s /etc/samba/smb.con_mydomain1
      nmbd -s /etc/samba/smb.con_mydomain1
      smbd -s /etc/samba/smb.con_mydomain2
      nmbd -s /etc/samba/smb.con_mydomain2

6. Check smb started or not.
     ps -ef|grep smb

7. Add trust account (for NT machines only)
    groupadd trust
    useradd -g trust -d /dev/null -s /bin/false <machine name>$
    passwd -l <machine name>$
          ====> NOTE: PLEASE DONT FORGET TO GIVE '$' IN ABOVE 2 COMMANDS
    smbpasswd -l <machine name>
If you want to add group of machines. Please download my script from sites.google.com/site/techbirdin/knowledge-base/addmachine.sh

8. Adding administrator account
    smbpasswd -a root
    (GIVE Samba Passwd for root)

9. FOR WIN XP PROF users NOT for WIN98 ot XP HOME

login to that windows machine (machine name) with administrator.
Right click to "My Computer" and click on "Properties"
Click on "Computer Name" Tab
Click on "Change"
Put Domain - "mydomain1" OR "mydomain2"
Click OK
It will ask for Domain admin username & passwd. Give username: root and smbpasswd of root
If everything is good then it will show you "Welcome to mydomain1 or 2"


   
 


Plain Authentication for sendmail with SASL
[info]neelesh_gurjar
1. Test your sendmail is compiled with SASL or not
sendmail -d0.1 -bv root | grep SASL  make sure SASL should come in Output.  If not then you need to compile sendmail with SASL

2. Changes in /etc/mail/sendmail.mc -->

define(`confAUTH_OPTIONS', `A')dnl
TRUST_AUTH_MECH(`LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `LOGIN PLAIN')dnl


2. In /usr/lib/sasl2/Sendmail.conf

pwcheck_method: saslauthd

And start saslauthd with following command:

saslauthd -a shadow

Restart sendmail

3. Test sendmail
telnet <server ip> 25
ehlo localhost

It should show 250-AUTH in the output.



Virtual Hosting in Sendmail
[info]neelesh_gurjar
Sendmail 8.13..
CentOS 5.1



1. Check following line should be there in /etc/mail/sendmail.mc

FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl

2./etc/mail/virtusertable, which will look something like this:

abc@domain1.com    abc

xyz@domain2.com  xyz

abc@domain2.com    abc2

3. makemap hash /etc/mail/virtusertable < /etc/mail/virtusertable


4. Put host alliases in /etc/mail/local-host-names.

domain1.com

domain2.com

Port forwarding in Linux with Iptables
[info]neelesh_gurjar

I have one Linux Machine. It has 2 interfaces. eth0 will have Live IP and which will be accessible across the internet. eth1 will have internal IP and can only be connected across LAN.
Here I want to forward all request which come to my internetIP should get forwarded to my internal web server. To do this need to give following commands on linux machine:


#iptables -t nat -A PREROUTING -p tcp -i eth0 -d <Live IP / IP of outside interface of firewall> --dport 80 -j DNAT --to <Internal server's IP / IP of the server where the request will forward to>:80
 
#iptables -A FORWARD -p tcp -i eth0 -d <Internal server's IP / IP of the server where the request will forward to> --dport 80 -j ACCEPT
 

Linux Addiction !!!
[info]neelesh_gurjar
Today When I ask in one department in company that "Can we switch over to Windows? As some body is donating Licensing cost for those PCs" All users said "No, We can't work on Windows now. We need only Linux"...

I got pleasent surprised by their reply. I thought that they will switch to Windows.

Three years back when I was pushing these users to work on Linux. I had to explain them advantages of Linux. They faced lots of issues in their daily work. Some of them I could resolved, In some cases they had to change their working style, some of them took a loing time also. But now when they are using it for last 2 years without any issue, they dont want to go back to Windows. They said that they forgot how to work on Windows. .... They got addicted to Linux now.....

People say that Linux is not user friendly and cannot be used for Desktops for general users.
Now I can surely say, if users, admins, management plans to use Linux, works hard on it without having windows in mind then they can switch to Linux. Offcourse proffessional companies like Adobe, Corel, Font making companies should make applications for Linux also.

Installing Atheros AR242x 802.11abg Wireless on Linux PAE kernel
[info]neelesh_gurjar
1.  echo "blacklist ath5k" >> /etc/modprobe.d/blacklist
2. Download latest madwifi-hal   from http://snapshots.madwifi.org/madwifi-hal-0.10.5.6/
3. Extract the tarball & go to extracted directory and install it with following commands:
  
     install
     modprobe ath_pci
     modprobe ath_hal

4. Create or open a file named  in the /etc/pm/config.d/config
   Add following line:   SUSPEND_MODULES="ath_pci"

5. Reboot it and then configure wireless interface in Yast2.

Sharing Printer for Windows from Linux with Samba
[info]neelesh_gurjar
Sharing Printer for Windows from Linux -->

smb.conf will be =============>

[global]
        dos charset = ASCII
        display charset = UTF-8
        workgroup = WORKGROUP
        netbios name = PRINT
        security = SHARE
        max xmit = 65535
        deadtime = 15
        socket options = IPTOS_LOWDELAY TCP_NODELAY SO_SNDBUF=16384 SO_RCVBUF=16384
        printcap name = cups
        printing = cups
        log file = /var/log/samba/%m.log

[printers]
        comment = All Printers
        path = /var/tmp
        guest ok = Yes
        printable = Yes
        browseable = yes

[print$]
        comment = Printer Drivers
        path = /var/lib/samba/drivers
        guest ok = Yes

[Test]
        comment = Test
        path = /var/lib/samba
        read only = No
        guest ok = Yes
        printable = Yes
        printer name = Test
        use client driver = Yes
        oplocks = No

===========================

/etc/cups/cupsd.conf ===================>


LogLevel debug
SystemGroup sys root
Port 631
Listen /var/run/cups/cups.sock
Browsing Off
DefaultAuthType Basic

<Location />
  Order allow,deny
   Allow from All
</Location>

<Location /admin>
  Order allow,deny
  Allow from All
</Location>

<Location /admin/conf>
  Order allow,deny
   Allow from All
</Location>

Note: If permissions are not proper then you may get "client-error-not-authorized" this error in Samba log.

================================

Please uncomment below line from /etc/cups/mime.convs

application/octet-stream        application/vnd.cups-raw        0       -

Note : If it is commented then you may get "client-error-document-format-not-supported" this error in samba log.

================================

Now restart cups and add printer in Windows.

Good Luck !!! :)

Resolution for Wine error in CentOS linux
[info]neelesh_gurjar
I am using CentOS 5.1 with Wine-0.9.57. While executin Program "Write.exe" with wine I was getting following error:

[neel_g@test drive_c]$ wine write.exe
preloader: Warning: failed to reserve range 00000000-60000000
preloader: Warning: failed to reserve range 00000000-60000000
preloader: Warning: failed to reserve range 00000000-60000000
err:dosmem:setup_dos_mem Cannot use first megabyte for DOS address space, please report
preloader: Warning: failed to reserve range 00000000-60000000
err:dosmem:setup_dos_mem Cannot use first megabyte for DOS address space, please report
err:dosmem:setup_dos_mem Cannot use first megabyte for DOS address space, please report
err:dosmem:load_winedos Could not load winedos.dll, DOS subsystem unavailable
winevdm: unable to exec '--app-name': 16-bit support missing


To resovle this issue:

1.  # cat /proc/sys/vm/mmap_min_add
        65536
2.  I added following line to /etc/sysctl.conf
        vm.mmap_min_addr = 0
3. # wineboot
4. The issue got resolved. The program is working fine.  :-)


       

How to get detail info of TCP or UDP packets
[info]neelesh_gurjar
[root@example root]# netstat -u -s
Udp:
    95043801 packets received
    2059 packets to unknown port received.
    12041 packet receive errors
    81665255 packets sent

[root@exampleroot]# netstat -t -s
Tcp:
    2119 active connections openings
    14472 passive connection openings
    0 failed connection attempts
    10 connection resets received
    1372 connections established
    101805453 segments received
    190009367 segments send out
    18675 segments retransmited
    0 bad segments received.
    31811 resets sent
TcpExt:
    ArpFilter: 0
    4892 TCP sockets finished time wait in fast timer
    774734 delayed acks sent
    3375 delayed acks further delayed because of locked socket
    Quick ack mode was activated 58 times
    2792 packets directly queued to recvmsg prequeue.
    1662 packets directly received from backlog
    681773 packets directly received from prequeue
    6711642 packets header predicted
    2594 packets header predicted and directly queued to user
    TCPPureAcks: 87512391
    TCPHPAcks: 8652457
    TCPRenoRecovery: 0
    TCPSackRecovery: 9225
    TCPSACKReneging: 0
    TCPFACKReorder: 0
    TCPSACKReorder: 0
    TCPRenoReorder: 0
    TCPTSReorder: 0
    TCPFullUndo: 0
    TCPPartialUndo: 0
    TCPDSACKUndo: 0
    TCPLossUndo: 2
    TCPLoss: 1069
    TCPLostRetransmit: 0
    TCPRenoFailures: 0
    TCPSackFailures: 817
    TCPLossFailures: 1
    TCPFastRetrans: 9691
    TCPForwardRetrans: 52
    TCPSlowStartRetrans: 122
    TCPTimeouts: 6017
    TCPRenoRecoveryFail: 0
    TCPSackRecoveryFail: 24
    TCPSchedulerFailed: 0
    TCPRcvCollapsed: 0
    TCPDSACKOldSent: 61
    TCPDSACKOfoSent: 0
    TCPDSACKRecv: 2
    TCPDSACKOfoRecv: 0
    TCPAbortOnSyn: 0
    TCPAbortOnData: 17
    TCPAbortOnClose: 1
    TCPAbortOnMemory: 0
    TCPAbortOnTimeout: 256
    TCPAbortOnLinger: 0
    TCPAbortFailed: 0

Resolved Issue of ORA:01110 File needs media recovery
[info]neelesh_gurjar
I have setup Oracle7.3 on SCO Openserver 5.0.

While starting Oracle I was getting error "ORA:01110 File 30 needs media recovery.

I resolved this by following way:

1. Logged in as oracle user.
2. Gave below commands:


# svrmgrl
SVRMGR>connect internal

SVRMGR>startup
THen it gave same error. So DB got mounted but not opened.

SVRMGR>RECOVER

Media Recovery Done.

THen I restarted Oracle and it worked. This time it didnt show the error.
This means it recovered data from "redo.log". I was lucky.

Cheers

Starting Oracle Enterprise Manager Web console in Linux
[info]neelesh_gurjar
Login as Oracle user
# emctl start dbconsole

Oracle installation errors and solutions
[info]neelesh_gurjar
While Installing Oracle I got following Error:


[oracle@neelesh ORACLE]$ ./runInstaller
Starting Oracle Universal Installer...

Checking installer requirements...

Checking operating system version: must be redhat-3, SuSE-9, redhat-4, UnitedLinux-1.0, asianux-1 or asianux-2
Passed


All installer requirements met.

Preparing to launch Oracle Universal Installer from /tmp/OraInstall2008-07-06_12-26-00PM. Please wait ...[oracle@neelesh ORACLE]$ No protocol specified
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvir onment(Unknown Source)
at java.awt.Window.init(Unknown Source)
at java.awt.Window.<init>(Unknown Source)
at java.awt.Frame.<init>(Unknown Source)
at oracle.ewt.popup.PopupFrame.<init>(Unknown Source)
at oracle.ewt.lwAWT.BufferedFrame.<init>(Unknown Source)
at oracle.sysman.oio.oioc.OiocOneClickInstaller.<init >(OiocOneClickInstaller.java:378)
at oracle.sysman.oio.oioc.OiocOneClickInstaller.main( OiocOneClickInstaller.java:2091)


SOLUTION: --

1. login as root
2. # xhost +
3. Login as oracle
4. # xhost +

Now try ./runInstaller.

Adding "tmpspace" in Linux
[info]neelesh_gurjar
Give below commands as root user:

mkdir /<different filesys>/tmp
chown root.root /<
different filesys>/tmp
chmod 1777 /<
different filesys>/tmp
export TEMP=/<
different filesys>
export TMPDIR=/<
different filesys>

For removing added "tmpspace" give below commands as root user:

rmdir /<
different filesys>/tmp
unset TEMP
unset TMPDIR


Home