Friday, January 13, 2012

Linux Commands


From windows machine you connect to linux PC using telnet or ssh via putty.
You must login using your credentials.

Create Directory:
mkdir <dir name>

Change Directory Path
cd <dir name>

Create a File
Reach the particular directory under which you want to create a file and then issue this command
vi <file name>

While coming our of the file isuue :wq to save the changes and come out
Issue :q! to come out without saving the changes

Delete File
rm <file name>

Delete Directory
rmdir <dir name>
Note that there should be no files under the directory for it to be deleted using this command

List
ls -lrt

Search
To search for a pattern of a file name, issue this command under the required directory

ls *<pattern>*

To search for a file containing a particular content pattern issue this command under the required directory

grep <pattern> *

To search for a file containing a pattern recursively from a directory (if you dont know in which directory the file would be present

find . | xargs grep "pattern"

Other useful linux commands:-
~~~~~~~~~~~~~~~~~~~~~~

To kill a process:-

ps -ef  | grep <process name>
process id will be displayed.
Then kill the process using the command
kill <pid>

We can also kill  the process in a single line:-
pkill <processName>


To Enable different services for different protocols
~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1. FTP - vsftpd
service vsftpd start

2. TELNET - xinetd


service xinetd start

3. SMTP - send mail
4. HTTP - httpd

service httpd start

5. RADIUS - radiusd

service radiusd start

6. DNS - named
service named start

7. IMAP4 - xinetd
service xinetd start

8. MMS -
9. LDAP - ldap
service ldap start

10. RTSP

Ports and Port Numbers
~~~~~~~~~~~~~~~~~~~~
 1. FTP - 21
2. TELNET - 23
3. SMTP - 25
4. HTTP - 80
5. RADIUS - 1812
6. DNS - 53
7. IMAP4 - 143
8. MMS - 1755
9. LDAP - 389
10. RTSP - 554

Command to send fragmented icmp traffic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ping 172.26.64.213 -c 3 -s 2000


-c - count
-s - size

Command to drop SYN packets in the lnux PC using ip tables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

iptables -A INPUT --protocol tcp --tcp-flags ALL SYN -j DROP

To flush the iptables
~~~~~~~~~~~~~~
iptables -F

Command to test with tethereal

tethereal -i eth1 tcp &

Command to unconfigure or flush an Ethernet interface ip in linux

ip addr flush eth1


ip addr del eth1 <ip>

Thursday, January 12, 2012

Testing SNMP Traps

If you are testing the snmp traps from a DUT to the linux PC then the following steps can be followed.

STEP 1 : Configure the snmp server in the DUT with the ip of the linux PC

eg:
snmp-server host 10.24.134.55 version v1

STEP 2 : Start the SNMP service in the linux PC

eg:
/etc/rc.d/init.d/snmpd start

STEP 3 : Issue "snmptrapd -f -Le" command to capture the traps in PC. If you are automating the
steps then log the traps in a file

eg: snmptrapd -f -Lf /var/log/trap.log

STEP 4 : Disable and then enable eth1 or any interface of your DUT to generate traps

eg: (config)#interface eth 1
(config-if-e1000-1)#enable
(config-if-e1000-1)#disable
(config-if-e1000-1)#enable

STEP 5 : Verify if the traps are logged

eg: tail -l /var/log/trap.log
STEP 6: Stop the snmp service

eg: /etc/rc.d/init.d/snmpd stop

Problems you might encounter:

1. If you get the following message in the PC

Warning: no access control information configured.^M
This receiver will *NOT* accept any incoming notifications.^M
NET-SNMP version 5.4.2.1

then you will have to change the file called /etc/snmp/snmptrapd.conf
Add this line to the snmptrapd.conf file

disableAuthorization yes
For details see the link:

http://forums.fedoraforum.org/archive/index.php/t-159234.html

2. If you get an error :-

couldn't open udp:162 -- errno 98 ("Address already in use")

then you will have to kill the snmptrapd process that is running.

ps -ef | grep snmptrapd
kill <pid>

or

pkill snmptrapd

How To Check If 2 IP Addresses Fall On The Same Subnet

This can be explained with an example :

137.157.7.65 - 1st ip
137.157.10.3 - 2nd ip
 255.255.252.0 - subnet mask

STEP 1 : Convert 1st ip to binary
137.157.7.65     10001001.10011101.00000111.01000001
255.255.252.0   11111111.11111111.11111100.00000000

STEP 2: Find the network address by copying all the binary digits as is if the mask is 1 and 0 if the mask is 0
10001001.10011101.00000100.00000000
137.157.4.0 - Net address

STEP 3: Convert the second address to binary
137.157.10.3     10001001.10011101.00001010.00000011
255.255.252.0   11111111.11111111.11111100.00000000

STEP 4 : Find network address of the second ip
10001001.10011101.00001000.00000000
137.157.8.0 - Net address

STEP 5: Compare the 2 network addresses
137.157.4.0 ====137.157.8.0 ----> They are not equal. Therefore they are in different subnet

Sunday, January 8, 2012

CVS

1. Command to add a directory or file

mkdir <newdir>
cvs add <newdir>
 
To add a file

cvs add newfile
cvs commit newfile

2. Command to check the status of the files - (Locally modified or up to date)
cvs status <filename/Directory name>

3. Command to incorporate your changes into the repository
 cvs commit.

4. Editing files is easy - once you have local copies, just edit them. None of your changes will be visible to other users until after you've committed them.
If you mess up a local copy of a file, starting over is easy. Delete the file using

rm <filename>, and use

 cvs update to get a fresh copy from the repository.



5. If you want all your files to be updated without considering your locally modified changes then grep for locally modified files and then delete them and then do a cvs update to get the latest files from the stream.

Command to find the list of locally modified files


cvs -q status <folder name> | grep -i locally

Command to refresh local copies
cvs checkout and cvs update -d are more or less equivalent.

Other Usefule Commands

cvs diff filenameShows differences between your local copy of filename and the repository version that filename was based on.
cvs diff -r 1.2 filenameShows differences between your local copy of filename and version 1.2 of filename.
cvs diff -r 1.2 -r 1.3 filenameShows differences between versions 1.2 and 1.3. (regardless of what version your local copy is).
cvs log filenameShow the commit log for filename (like rlog does with rcs).
cvs annotate filenameShows each line of filename, prefixed with the version number where the line was added, and the name of the person who added it. Useful for seeing who made a particular set of changes.