Sunday 10 June 2012

NAT and PAT


Frame Relay


Point to Point and Multipoint Frame-Relay Configuration Example






■FRS

Frame Relay Switch

conf t
frame-relay switching
!
int s0/0
description PVC_R1
encapsulation frame-relay
frame-relay intf-type dce
frame-relay route 102 interface Serial0/1 201
frame-relay route 103 interface Serial0/2 301
frame-relay route 104 interface Serial0/3 401
no shut
!
interface Serial0/1
description PVC_R2
encapsulation frame-relay

frame-relay intf-type dce
frame-relay route 201 interface Serial0/0 102
frame-relay route 203 interface Serial0/2 302
no shut
!
interface Serial0/2
description PVC_R3
encapsulation frame-relay
frame-relay intf-type dce
frame-relay route 301 interface Serial0/0 103
frame-relay route 302 interface Serial0/1 203
no shut
!
interface Serial0/3
description PVC_R4
encapsulation frame-relay
frame-relay intf-type dce
frame-relay route 401 interface Serial0/0 104
no shut
-----------------------------------------------

■ R1
-----------------------------------------------
conf t
int s0/0
encap frame-relay
no shut
!
int s0/0.14 point-to-point
ip address 202.84.14.1 255.255.255.252
frame-relay interface-dlci 104
!
interface Serial0/0.123 multipoint
ip address 192.168.100.1 255.255.255.0
frame-relay map ip 192.168.100.2 102 broadcast
frame-relay map ip 192.168.100.3 103 broadcast
end
----------------------------------------------- 

■R2
conf t
int s0/0
encap frame-relay
no shut
!
interface Serial0/0.123 multipoint
ip address 192.168.100.2 255.255.255.0
frame-relay map ip 192.168.100.1 201 broadcast
frame-relay map ip 192.168.100.3 203 broadcast
end
------------------------------------------------ 
 
■R3
conf t
hostname R3
int s0/0
no shut
encap frame-relay
!
interface Serial0/0.123 multipoint
ip address 192.168.100.3 255.255.255.0
frame-relay map ip 192.168.100.1 301 broadcast
frame-relay map ip 192.168.100.2 302 broadcast
end
--------------------------------------

■R4
conf t
int s0/0
encap frame-relay
no shut
!
int s0/0.14 point-to-point
ip address 202.84.14.2 255.255.255.252
frame-relay interface-dlci 401


Saturday 9 June 2012

Sharing files from Virtualbox Linux VM to Windows and Vice Versa

Let's say you have a windows OS on which you are running Virtualbox with a redhat guest OS and you want share files from windows to your VM and vice-versa.

1. Create a share file on windows(called mine WINDOWSSHAREFOLDER)

2. Create a share file on your VM(called mine VMSHAREFOLDER)

3. Install VboxLinuxAdditions on your VM by mounting the iso for VboxLinuxAdditions(it is found in the directorectory where you installed virtualbox: Program Files\Oracle\VirtualBox\) on your VM



   a. on your VM this is how you proceed to the installation
[root@RHEL5-Serv01 ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@RHEL5-Serv01 ~]# ls /mnt/cdrom/
32Bit        autorun.sh                VBoxWindowsAdditions-amd64.exe
64Bit        VBoxLinuxAdditions.run    VBoxWindowsAdditions.exe
AUTORUN.INF  VBoxSolarisAdditions.pkg  VBoxWindowsAdditions-x86.exe
[root@RHEL5-Serv01 ~]# /mnt/cdrom/VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.0.4 Guest Additions for Linux.........
VirtualBox Guest Additions installer
Removing installed version 4.0.4 of VirtualBox Guest Additions...
Removing existing VirtualBox DKMS kernel modules            [  OK  ]
Removing existing VirtualBox non-DKMS kernel modules      [  OK  ]
Building the VirtualBox Guest Additions kernel modules
Your guest system does not seem to have sufficient OpenGL support to enable
accelerated 3D effects (this requires Linux 2.6.27 or later in the guest
system).  This Guest Additions feature will be disabled.


Building the main Guest Additions module                   [  OK  ]
Building the shared folder support module                  [  OK  ]
Doing non-kernel setup of the Guest Additions              [  OK  ]
You should restart your guest to make sure the new modules are actually used

Installing the Window System drivers
Installing X.Org 7.1 modules                               [  OK  ]
Setting up the Window System to use the Guest Additions    [  OK  ]
You may need to restart the hal service and the Window System (or just restart
the guest system) to enable the Guest Additions.

Installing graphics libraries and desktop services componen[  OK  ]

   b. from  VirtualBox Device menu click on "shared folder" and choose your windows shared folder






   c. lets first see what is on your WINDOWSSHAREFOLDER before mounting to the redhat VM

   d. Now mount your windows shared folder to your redhat VM and view the folder

 [root@RHEL5-Serv01 ~]# mount -t vboxsf WINDOWSSHAREFOLDER /home/doumbia/Desktop/VMSHAREFOLDER
[root@RHEL5-Serv01 ~]# ls /home/doumbia/Desktop/VMSHAREFOLDER/
IMG_0148.JPG
[root@RHEL5-Serv01 ~]#

   e. You can also send files from your redhat VM to Windows just by dragging them into to the VM sharefolder


     NOTE: to write from linux VM you have to be out of the shared directory ,
              create a file and move it to the sare directory or it won't work.

 f. Now lets see the files you sent from your redhat VM to windows
  

done

FIND



SED command examples


PURPOSE
Learn SED command by examples

ENVIRONMENT
LINUX: shell/bash
WINDOWS:cygwin

EXAMPLES


  • we are going to work with the following file

$ cat file2
1. one
2. two
3. three
4. four
5. five
  • replacing "one" by "OOO"...instead of "OOO" if you put "" it deletes "one"

$ sed s/one/OOO/ file2
1. OOO
2. two
3. three
4. four
5. five

  • same as above multiple replace ( "one" by "OOONE" and "two" by "TWOOO")

$ sed -e s/one/OOONE/ -e s/two/TWOOO/ file2
1. OOONE
2. TWOOO
3. three
4. four
5. five
  • replace character by character(here "o" by "O" and "t" by "T")

$ sed 'y/ot/OT/' file2
1. One
2. TwO
3. Three
4. fOur
5. five
  • putting matches in a file and then running sed
$ cat matches
s/one/1111/
s/two/TTTT/


$ sed -f matches file2
1. 1111
2. TTTT
3. three
4. four
5. five








Finding pattern by line number or word
  • syntax: (in the following syntaxes X、Y are numbers and <word> is a word)


    • ①sed -n Xp filename  : prints line X of file
    • ②sed -n /<word>/p filename: prints line where <word>
    • ③sed -n 'X , Yp' filename : prints file from line N to line Y 
    • ④sed -n 'X ~ Y'p filename  : prints every Y number of line after line X
    • ⑤sed -n 'X , /<word>/p'  filename : prints file from line X to <word>
    • ⑥sed -n '/<word>/, Yp' filename : prints file from <word> to line Y
    • ⑦sed -n '/<word>/, +Yp' filename : prints from <word> and adds Y lines number
    • ⑧sed -n '/<wordA>/ , /<wordB>/p' filename : prints file from <wordA> to <wordB>
※ without the single quotes it mostly works,just try it yourself
  • ①  prints line 3
$ sed -n 3p file2
3. three


  • ② prints line containing the word "two"
$ sed -n /two/p file2
2. two
  • ③ prints line 3 to 4
$ sed -n 3,4p file2
3. three
4. four
  • ④ prints every 2 lines after the 1st line
$ sed -n '1~2'p file2
1. one
3. three
5. five

  • ⑤ prints line 3 to the line where "four" is found
$ sed -n '3,/four/p' file2
3. three
4. four


  • ⑥ prints the line where "two" is found up until the 4th line
$ sed -n '/two/,4p' file2
2. two
3. three
4. four

  • ⑦ prints 3lines after the matching the searched word "one"
$ sed -n '/one/,+3p' file2
1. one
2. two
3. three
4. four

  • ⑧ prints everything between line where "two" is found to line where "four" is found
$ sed -n /two/,/four/p file2
2. two
3. three
4. four


WE can use regex with SED too

  • erase "four" and delete line containing the word "six"
$ sed -e 's/four//;/six/d' file2 ( same as sed -e s/four// -e s/six// file2)
1. one
2. two
3. three
4.
5. five
  • find a word which start with "o" and ends with "e" and replace by 3 times the match
$ sed 's/o\(.*\)e/\1\1\1/g' file2
1. nnn
2. two
3. three
4. four
5. five
  • & represents the match of sed so lets replace "one" by "<one-one-one>"
$ sed 's/one/<&-&-&>/' file2
1. <one-one-one>
2. two
3. three
4. four
5. five
/div>
  • using other delimes than "/"
$ echo "http://www.google.com/" | sed @http://www.google.com/@http://www.youtube.com/@
http://www.youtube.comsomelinks/


  • writing changes directly to file(replacing "one" by "1111" directly in the target file)

$cp file2 file3    ( lets copy file2 into another file to not loose the original)
$sed -i s/one/1111/ file3
$ cat file3
1. 1111
2. two
3. three
4. four

5. five

  • replacing options "g" and "i"

  • the following replaces only the 1st match
$ echo "oneONEone" | sed s/one/111/
111ONEone

  • by adding the "g" option it replaces the match "Globally"
$ echo "oneONEone" | sed s/one/111/g
111ONE111

  • by adding the "i" option it replaces the match "Ignoring " the case
$ echo "oneONEone" | sed s/one/111/gi
111111111



GREP


  • let's view the content of the file we are going to work with
[root@RHEL5-Serv01 work]# cat grepfile2
first line
second line
third line
fourth line
fifth line
seventh line
eighth line
nineth line
tenth line
ten lines in total contain the word line
  • let's grep the word "ten"
[root@RHEL5-Serv01 work]# grep ten grepfile2
tenth line
ten lines in total containing the word line
  • let's count the number of match
[root@RHEL5-Serv01 work]# grep -c ten grepfile2
2
  •  ignoring case of the word
[root@RHEL5-Serv01 work]# grep TEN grepfile2
[root@RHEL5-Serv01 work]# 
※ NO MATCH BUT WHEN IGNORING CASE AS FOLLOWS
[root@RHEL5-Serv01 work]# grep -i TEN grepfile2

tenth line
ten lines in total containing the word line
  • lets reduce the above result to an exact match
[root@RHEL5-Serv01 work]# grep -w ten grepfile2
ten lines in total containing the word line
  • matching multiple words
[root@RHEL5-Serv01 work]# grep -e "first" -e "second" grepfile2
first line
second line
※ the following gives the same result as the command above
[root@RHEL5-Serv01 work]# grep -E 'first|second' grepfile2
first line
second line
  • matching two lines after the matching word
[root@RHEL5-Serv01 work]# grep -A 2 first grepfile2
first line
second line
third line
  • matching two lines before the matching word
[root@RHEL5-Serv01 work]# grep -B 2 third grepfile2
first line
second line
third line
  • matching two lines before and after the matching word
[root@RHEL5-Serv01 work]# grep -C 2 third grepfile2
first line
second line
third line
fourth line
fifth line
  • showing lines that do not match the search word
[root@RHEL5-Serv01 work]# grep -v line grepfile2
[root@RHEL5-Serv01 work]#

  • let's find the file containing our search word
[root@RHEL5-Serv01 work]# ls
grepfile  grepfile1  grepfile2
[root@RHEL5-Serv01 work]# grep -l line grepfile*
grepfile2
  •  let's find the line number that containts the search word
[root@RHEL5-Serv01 work]# grep -n line grepfile2
1:first line
2:second line
3:third line
4:fourth line
5:fifth line
6:seventh line
7:eighth line
8:nineth line
9:tenth line
10:ten lines in total contain the word line

GREP USING REGULAR EXPRESSIONS




$ cat file
i am
you are
he is
she is
we are
you are
they are
so what do we do?!
080-9876-9999
ab2354cF


$ grep 'a.e' file
you are
we are
you are
they are

$ grep 'w[a-z]\{2\}t' file(same as "grep w..t file")
so what do we do?!

$grep '[0-9]\{3\}-[0-9]\{4\}-[0-9]\{4\}' file
080-9876-9999 

HOME

   Welcome to my page . This is my first post and my intention here is to share every little knowledge that I have gathered from different sources and experience . I hope these tutorials will be helpful and If you find any errors in the post ,let me know.

One Note:

Since a picture is worth a thousand words,my tutorials will be more pictorial.

Thanks!