Thursday, June 11, 2009

Linux Command To Check System Profile

Linux system administrator and experienced users might interested in getting a Linux server profile in order to understand how the Linux system being setup, what is the server hardware specification, what are the software packages or drivers being installed, does it need to be patched or upgraded, etc.

  • less /etc/sysconfig/hwconf to get installed hardware information.
  • less /proc/cpuinfo to get installed CPUs specification.
  • less /var/log/dmesg or dmesg to get the Linux boot up information.
  • less /proc/interrupts to list the IRQ used by system devices.
  • less /proc/ioports to list I/O ports used by system.
  • less /proc/dma to list DMA channels and device used by system.
  • less /proc/version or uname -a or less /etc/redhat-release or lsb_release -a to show the Linux version.
  • kudzu -p to show the probe information about hardware detected
  • /usr/bin/lsdev to list devices and information on system hardware.
  • /sbin/lspci to list detected PCI devices.
  • /sbin/lsmod to list loadable modules.
  • /sbin/lsraid to list raid device.
  • /sbin/lsusb to list USB device.
  • /sbin/usbmodules to list kernel driver modules available for USB devices.
  • hdparm -I /dev/hda to get installed harddisk details.

Thursday, July 17, 2008

To find the IP address of the sender in Gmail, Yahoo! mail

When you receive an email, you receive more than just the message. The email comes with headers that carry important information that can tell where the email was sent from and possibly who sent it. For that, you would need to find the IP address of the sender. The tutorial below can help you find the IP address of the sender. Note that this will not work if the sender uses anonymous proxy servers.

First of all, the IP address is generally found in the headers enclosed beween square brackets, for instance, [129.130.1.1]

Finding IP address in Gmail

  1. Log into your Gmail account with your username and password.
  2. Open the mail.
  3. To display the email headers,
    • Click on the inverted triangle beside Reply. Select Show Orginal.
  4. You may copy the headers and use my IP address detection script to ease the process. Or if you want to manually find the IP address, proceed to 5.
  5. Look for Received: from followed by the IP address between square brackets [ ].
    Received: from [69.138.30.1] by web31804.mail.mud.yahoo.com
  6. If you find more than one Received: from patterns, select the last one.
  7. Track the IP address of the sender

Finding IP address in Yahoo! Mail

  1. Log into your Yahoo! mail with your username and password.
  2. Click on Inbox or whichever folder you have stored your mail.
  3. Open the mail.
  4. If you do not see the headers above the mail message, your headers are not displayed. To display the headers,
    • Click on Options on the top-right corner
    • In the Mail Options page, click on General Preferences
    • Scroll down to Messages where you have the Headers option
    • Make sure that Show all headers on incoming messages is selected
    • Click on the Save button
    • Go back to the mails and open that mail
  5. You should see similar headers like this:
    Yahoo! headers : Arul John
  6. You may copy the headers and use my IP address detection script to ease the process. Or if you want to manually find the IP address, proceed to 7.
  7. Look for Received: from followed by the IP address between square brackets [ ]. Here, it is 202.65.138.109.
    That is be the IP address of the sender.
    If there are many instances of Received: from with the IP address, select the IP address in the last pattern. If there are no instances of Received: from with the IP address, select the first IP address in X-Originating-IP.
  8. Track the IP address of the sender

Thursday, March 27, 2008

SED (Stream EDitor)

SED


Find and Replace:

Sed is often used as a find-and-replace tool.

     sed 's/Glenn/Harold/g' oldfile >newfile

will replace every occurrence of "Glenn" with the word "Harold", wherever it occurs in the file. The "find" portion is a regular expression ("RE"), which can be a simple word or may contain special characters to allow greater flexibility (for example, to prevent "Glenn" from also matching "Glennon").

SED Leaving Space:

My very first use of sed was to add 8 spaces to the left side of a file, so when I printed it, the printing wouldn't begin at the absolute left edge of a piece of paper.

     sed 's/^/        /' myfile >newfile   # my first sed script
sed 's/^/ /' myfile | lp # my next sed script

SED display one paragraph of a file:

sed could display only one paragraph of a file, beginning at the phrase "and where it came" and ending at the phrase "for all people". My script looked like this:

     sed -n '/and where it came/,/for all people/p' myfile

SED Display 12 to 18 lines:

found that sed could show me only (say) lines 12-18 of a file and not show me the rest. This was very handy when I needed to review only part of a long file and I didn't want to alter it.

     # the 'p' stands for print
sed -n 12,18p myfile

SED Display everything but of those 12, 18:

sed could show me everything else BUT those particular lines, without physically changing the file on the disk:

     # the 'd' stands for delete
sed 12,18d myfile

SED double-space my single-spaced file when it came time to print it:

double-space my single-spaced file when it came time to print it:

     sed G myfile >newfile


Iptables rules for Outlook Express

A Squid proxy can share a Internet Service.
But it will not download the mails in Outlook Express.
In this case IPtables can be used to retrieve mails.

A model Network setup:
Eth0 : Public N/W

Eth1 : Private N/W
IP : 192.168.10.40
IP Range : 192.168.10.0/24

So hence the Iptables rules for forwarding the packets ,

# iptables --table nat --append POSTROUTING -s 192.168.10.0/24 --out-interface eth0 -j MASQUERADE

# iptables --append FORWARD -s 192.168.10.0/24 --in-interface eth1 -j ACCEPT

# iptables -A INPUT -s 192.168.10.0/24 -j ACCEPT

Insert the above rules
Save and restart the service .

#service iptables save
# service iptables restart

Now you can download your mails in the Outlook express.

Client Side Configuration:
1. Set the Gateway address as Eth1 IP.
2. Open Outlook Express – Tools – Accounts – mail –add new
3. Configure your mail account.

Linux - Memory Leakage

In Linux the valgrind tool help us to detect the memory leakage in our coding.

For Example
if your application exec is named as myexec, then run the command as below
valgrind --tool=memcheck --leak-check=yes --num-callers=25 ./myexec

Note :- when your running the exec with valgrind tool run the exec with ./ (dot slash).

when your application needs to pass arguments with the exec run tool with argument

valgrind --tool=memcheck --leak-check=yes --num-callers=25 ./myexec -ORBInitRef
NameServic=corbaloc:iiop:localhost/NameService

Memcheck performs a range of memory-checking functions,including detecting accesses to uninitialized memory, misuse of allocated memory (double frees, access after free, etc.) and detecting memory leaks.

Linux Disk Copy

HardDisk Copy In Linux
(Disk to Disk Copy)

Connect two hard disk in the mother board.
Boot the system with the data hard disk.
Run the following command to view the hard disk name,
# fdisk -l (shows booted H/D)
# ls /dev/ (shows the other H/D)
Let the data containing hardisk be HDA and the data in which to be copied be HDB.
Now execute the below command to copy the hard disk.

# dd if=/dev/hda of=/dev/hdb bs=1024k

Now the data's with start to copy.

Internet Sharing in linux (Squid)

Squid’s main configuration file is in /etc/squid/squid.conf.
Edit the file
Open /etc/squid/squid.conf
You will need to either find and uncomment entries, or modify existing uncommented lines in the squid configuration file. Use text editor or a text find to locate these lines:

visible_hostname machine-name or IP
http_port 3128
cache_dir ufs /var/spool/squid 1000 16 256
cache_access_log /var/log/squid/access.log

In the acl section near the bottom add:
acl intranet 192.168.10.0/24 -> Allow all the machines to access.
http_access allow lcsintranet.com (lcsintranet.com – hostname)
visible_hostname - Create this entry and set this to the hostname of the machine. To find the hostname, use the command hostname. Not entering a value may cause squid to fail as it may not be able to automatically determine the fully qualified hostname of your machine.

http_port 3128 - Uncomment this line but there is no need to edit it unless you want to change the default port for http connections.
cache_dir ufs /var/spool/squid 1000 15 256 - Uncomment this line. You may want to append a zero to the value 100 which will make the cache size 1000MB instead of 100MB. The last two values stand for the default folder depth the cache will create on the top and subdirectories respectively. They do not need modification.
cache_access_log - Uncomment this line. This is where all requests to the proxy server will get logged.
acl intranet 192.168.10.0/24 - This entry needs to be added. It should correspond to whatever your local network range is.
http_access allow lcsintranet - This allows the acl named intranet to use the proxy server. Make sure to put allow directives above the last ‘http_access deny all’ entry, as it will overide any allow directives below it.

To allow a single address to access a specific URL
This example allows only the special_client to access the special_url. Any other client that tries to access the special_url is denied.

acl special_client src 192.168.10.3
acl special_url url_regex ^http://www.squid-cache.org/Doc/FAQ/$
http_access allow special_client special_url
http_access deny special_url

To allow a particular address to access a list of URL
acl special_client src 192.168.10.3
acl special_client src “/etc/squid/ip.txt”->(Make a file ip.txt and add IP to access the particular URL)
acl lcssite url_regex –i “/etc/squid/site.txt” -> (Make a file site.txt add the URL)

Turning on squid
Start the service:

service squid start
Verify that squid is running :

service squid status

Configuring the clients
If you are using Firefox or Mozilla you will need to add the proxy server as follows:
Go to Preferences>Network>Settings
Add the name of your new proxy server and port 3128 to the http proxy field.