Entering And Leaving VI File Manipulation
----------------------- -----------------
%vi name edit name at top :w write back changes
%vi +n name ... at line n :wq write and quit
%vi + name ... at end :q quit
%vi -r list saved files :q! quit, discard changes
%vi -r name recover file name :e name edit file name
%vi name ... edit first;rest via :n :e! reedit discard changes
%vi -t tag start at tag :e + name edit starting at end
%vi +/pat name search for pat :e +n name edit starting at line n
% view name read only mode :e # edit alternate file
ZZ save and exit from vi CTRl-^ synonym for :e #
CTRL-Z stop vi, don't exit :r(name) paste file name starting at
current position.
:w(name) write file name
The Display :w! name overwrite file name
----------- :sh run shell, then return
:!cmd run cmd, then return
Last line Error mesg, echoing input :n edit next file in arglist
to :/? and !, feedback :n args specify new arglist
about i/o and large changes :f show current file and line
@ lines On screen only, not in file CTRL-G synonym for :f
~lines Lines past end of file :ta tag to tag file entry tag
CTRL-x Control characters, DEL is CTRL-] :ta, following word tag
delete.
tabs Expand to spaces, cursor
at last.
Vi Modes Positioning within File
-------- -----------------------
Command Normal and initial state CTRL-F forward screenfull
Others return here. Esc CTRL-B backward screenfull
(escape) cancels partial CTRL-D scroll down half screen
command. CTRL-U scroll up half screen
Insert Entered by a i A I O G goto line (end default)
o c C s S R. Arbitrary /pattern next line matching pattern
test then terminates ?pattern prev line matching pattern
with ESC character, or n repeat last / or ?
abnormally with interrupt N reverse last / or ?
Last line Reading input for :/? or !; /pat/+n n'th line after pat
terminate with ESC or CR ?pat?-n n'th line befor pat
to execute. interrupt to ]] next section/function
m cancel. [[ previous section/function
% find matching () { or }
Counts Before Vi Commands Adjusting the Screen
------------------------- --------------------
line/column number z G | CTRL-L clear and redraw
scroLl half-page CTRL-D CTRL-U CTRL-R retype, eliminate @ lines
replicate insert a i A I z<CR> redraw, at window top
repeat effect most rest z- ... at bottom
z. ... at center
Simple Commands /pat/z- pat line at bottom
--------------- zn. use
CTRL-E scroll window down 1 line
dw delete word CTRL-Y scroll window up 1 line
de ... leave punct
dd delete a line Corrections during Insert Mode
3dd ... 3 lines ------------------------------
i(text) ESC insert text (return
to cmd mode)
cw(new) ESC change word to new CTRL-H erase last character
(return to cmd mode)
easESC pluralize word CTRL-W erases last word
xp transpose characters erase your erase, same as CTRL-H
(switch current char Kill erase input this line
w/ next)
Interrupting, Cancelling \ escapes CTRL-H, erase, kill
------------------------ ESC end insert, command mode
CTRL-C interrupt, terminate insert
ESC end insert or command CTRL-D backtab over autoindent
CTRL-C interrupt (or DEL) CTRL-^D kill auto, save for next
CTRL-L refresh screen 0CTRL-D ... but at margin next also
CTRL-V quote non-printing character
Marking and Returning Insert and Replace
--------------------- ------------------
`` previous context a append after cursor
'' ... at first non-white i insert before
in line A append at end of line
mx mark position with I insert before first non-white
`x to mark x o open line below
'x ... at first non-white O open above
in line rx replace single char with x
R replace characters
Line Positioning Operators (double to effect line)
---------------- ---------------------------------
H top window line dd delete line
L last window line cc cut line to paste with p.
M middle window line < left shift
+ next line at first > right shift
non-white ! filter through command
- previous line, at first = indent for LISP
CR return, same as + yy yank lines to buffer
down arrow
or j next line, same column Miscellaneous Operations
up arrow ------------------------
or k prev line, same column
C change rest of line
Character Positioning D delete rest of line
--------------------- s substitute chars
S substitute lines
^ beginning of Line. J join lines
$ end of line X ... before cursor
right arrow Y yank lines
or l forward x delete characters
left arrow Yank and Put
or h backwards ------------
CTRL-H same as left arrow
space same as right arrow p put back lines
(num)yy yank num lines
Undo,Redo,Retrieve
| to specified column ------------------
% find matching () or {}
u undo last change
Words, Sentences, Paragraphs U restore current line
---------------------------- . repeat last change
(num)yy yank num lines
w word forward
b back word (to first char) Commands for LISP
e to last character of W -----------------
) to next sentence
} to next paragraph ) Forward s-expression
( back sentence } ... but don't stop at atoms
{ back paragraph ( back s-expression
W word forward { ... but don't stop at
B back W (to first char)
E to last character of W
Saturday, April 19, 2014
Vi Vs Vim
Saturday, March 29, 2014
Linux kernel rp_filter settings
The main functionality of a router is to route packets from one place to another. Linux machine can be used as router on your network that will route substantial amount of traffic without any issues, if configured correctly.
Due to the increasing amount of malicious and attack traffic on the internet, it has become very much necessary to take some extra care while configuring routes on a Linux machine or physical router's.
One of the major problem that internet security people are dealing with today, is spoofing.
What is IP address spoofing?
IP spoofing is a method adopted by attacker's to send forged source address in their attack traffic.Which means they can send an IP packet with an IP address of their wish.
Most of the time's spoofing is used by an attacker mainly for the following reasons.
To conduct a DDOS attack ,and he does not want the response from the target machine to reach him
To compromise source based authentication
Spoofing can be controlled to a certain extent by using Reverse Path filtering(not fully although).
What is reverse path filtering?
Reverse path filtering is a mechanism adopted by the Linux kernel, as well as most of the networking devices out there to check whether a receiving packet source address is routable.
So in other words, when a machine with reverse path filtering enabled receives a packet, the machine will first check whether the source of the received packet is reachable through the interface it came in.
If it is routable through the interface which it came, then the machine will accept the packet
If it is not routable through the interface, which it came, then the machine will drop that packet.
Latest red hat machine's will give you one more option. This option is kind of liberal in terms of accepting traffic.
If the received packet's source address is routable through any of the interfaces on the machine, the machine will accept the packet.
Reverse Path Filter(rp_filter) settings in Red hat 5/Centos 5 machines
In Linux machine's Reverse Path filtering is handled by sysctl, like many other kernel settings.
The current value on your machine can be found from the following method.
[root@localhost ~]# cat /proc/sys/net/ipv4/conf/default/rp_filter
1
[root@localhost ~]#
Let's understand the boolean values for rp_filter first then go ahead with configuration.
1 indicates, that the kernel will do source validation by confirming reverse path.
0 indicates, no source validation.
The previously shown output of /proc/sys/net/ipv4/conf/default/rp_filter indicates the default value of Reverse path filtering for any new interface.
You can also enable reverse path filtering only on your desired interface, because each interface has got different rp_filter files.
[root@localhost ~]# cd /proc/sys/net/ipv4/conf/
[root@localhost conf]# ll
total 0
dr-xr-xr-x 2 root root 0 Feb 28 05:12 all
dr-xr-xr-x 2 root root 0 Feb 28 05:12 default
dr-xr-xr-x 2 root root 0 Feb 28 05:12 eth0
dr-xr-xr-x 2 root root 0 Feb 28 05:12 lo
All the folder's in the above shown output has the file rp_filter. I will recommend enabling it by modifying the file /proc/sys/net/ipv4/conf/all/rp_filter file, if you Reverse filtering very strictly. This can be done by simply redirecting your desired boolean value(1 or 0) to the desired file.
[root@localhost conf]# echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
[root@localhost conf]#
Now restart your network for the new configuration to take effect.
However editing file's inside /proc is not at all a good practice. So you can do this by editing sysctl.conf file
[root@localhost conf]# sysctl -w "net.ipv4.conf.all.rp_filter=1"
net.ipv4.conf.all.rp_filter = 1
Replace "all" with default,eth0,<or any interface name of your wish>
Reverse Path Filter(rp_filter) settings in Red hat 6/Centos 6 mahcines
Like previously mentioned there is one more option which is to do a source validation of the packet's recieved through all the interfaces on the machine.
In other words if the source address is routable with any of the routes on any of the interface, then packet is accepted. And this is called as a loose mode reverse filtering.
The numeric value to enable this mode of rp_filter in redhat-linux 6 is 2 .
For example you can simply set the value of 2 as shown below to enable this mode.
[root@localhost conf]# echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter
[root@localhost conf]#
Rest of the setting's related to rp_filter in Red Hat enterprise Linux 6 is same as in Red Hat 5.
Due to the increasing amount of malicious and attack traffic on the internet, it has become very much necessary to take some extra care while configuring routes on a Linux machine or physical router's.
One of the major problem that internet security people are dealing with today, is spoofing.
What is IP address spoofing?
IP spoofing is a method adopted by attacker's to send forged source address in their attack traffic.Which means they can send an IP packet with an IP address of their wish.
Most of the time's spoofing is used by an attacker mainly for the following reasons.
To conduct a DDOS attack ,and he does not want the response from the target machine to reach him
To compromise source based authentication
Spoofing can be controlled to a certain extent by using Reverse Path filtering(not fully although).
What is reverse path filtering?
Reverse path filtering is a mechanism adopted by the Linux kernel, as well as most of the networking devices out there to check whether a receiving packet source address is routable.
So in other words, when a machine with reverse path filtering enabled receives a packet, the machine will first check whether the source of the received packet is reachable through the interface it came in.
If it is routable through the interface which it came, then the machine will accept the packet
If it is not routable through the interface, which it came, then the machine will drop that packet.
Latest red hat machine's will give you one more option. This option is kind of liberal in terms of accepting traffic.
If the received packet's source address is routable through any of the interfaces on the machine, the machine will accept the packet.
Reverse Path Filter(rp_filter) settings in Red hat 5/Centos 5 machines
In Linux machine's Reverse Path filtering is handled by sysctl, like many other kernel settings.
The current value on your machine can be found from the following method.
[root@localhost ~]# cat /proc/sys/net/ipv4/conf/default/rp_filter
1
[root@localhost ~]#
Let's understand the boolean values for rp_filter first then go ahead with configuration.
1 indicates, that the kernel will do source validation by confirming reverse path.
0 indicates, no source validation.
The previously shown output of /proc/sys/net/ipv4/conf/default/rp_filter indicates the default value of Reverse path filtering for any new interface.
You can also enable reverse path filtering only on your desired interface, because each interface has got different rp_filter files.
[root@localhost ~]# cd /proc/sys/net/ipv4/conf/
[root@localhost conf]# ll
total 0
dr-xr-xr-x 2 root root 0 Feb 28 05:12 all
dr-xr-xr-x 2 root root 0 Feb 28 05:12 default
dr-xr-xr-x 2 root root 0 Feb 28 05:12 eth0
dr-xr-xr-x 2 root root 0 Feb 28 05:12 lo
All the folder's in the above shown output has the file rp_filter. I will recommend enabling it by modifying the file /proc/sys/net/ipv4/conf/all/rp_filter file, if you Reverse filtering very strictly. This can be done by simply redirecting your desired boolean value(1 or 0) to the desired file.
[root@localhost conf]# echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
[root@localhost conf]#
Now restart your network for the new configuration to take effect.
However editing file's inside /proc is not at all a good practice. So you can do this by editing sysctl.conf file
[root@localhost conf]# sysctl -w "net.ipv4.conf.all.rp_filter=1"
net.ipv4.conf.all.rp_filter = 1
Replace "all" with default,eth0,<or any interface name of your wish>
Reverse Path Filter(rp_filter) settings in Red hat 6/Centos 6 mahcines
Like previously mentioned there is one more option which is to do a source validation of the packet's recieved through all the interfaces on the machine.
In other words if the source address is routable with any of the routes on any of the interface, then packet is accepted. And this is called as a loose mode reverse filtering.
The numeric value to enable this mode of rp_filter in redhat-linux 6 is 2 .
For example you can simply set the value of 2 as shown below to enable this mode.
[root@localhost conf]# echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter
[root@localhost conf]#
Rest of the setting's related to rp_filter in Red Hat enterprise Linux 6 is same as in Red Hat 5.
Tuesday, March 25, 2014
Limit Outgoing Bandwidth using 'tc' Command
You can limit the outgoing bandwidth on
server with the tc tool as shown below
(1) Limit the bandwidth to 1MBps on the
node(Xen node with brdge network)
#tc qdisc add dev peth0 handle 1: root
htb default 11
#tc class add dev peth0 parent 1:1
classid 1:11 htb rate 1Mbit
#tc -s qdisc ls dev peth0
Note: peth0 is the bridge name. For a
dedicated server it should be eth0
(2) bandwidth limiting With a Xen PV
VM.
#tc qdisc add dev viftest1.0 handle 1:
root htb default 11
#tc class add dev viftest1.0 parent 1:1
classid 1:11 htb rate 1Mbit
#tc -s qdisc ls dev peth0
R1Soft Agent Installation
Installing Backup Agent Using YUM
================================
You should configure the YUM repository to manage install and upgrades of the Backup Agent.
(1)Create a yum repository for r1soft
#cd /etc/yum.repos.d
# nano -w /etc/yum.repos.d/r1soft.repo
(use any text editor according to your convenience)
You should configure the YUM repository to manage install and upgrades of the Backup Agent.
(1)Create a yum repository for r1soft
#cd /etc/yum.repos.d
# nano -w /etc/yum.repos.d/r1soft.repo
(use any text editor according to your convenience)
(2)Add the following to the .repo file
------------------------------------------------------
[r1soft]
name=R1Soft Repository Server
baseurl=http://repo.r1soft.com/yum/stable/$basearch/
enabled=1
gpgcheck=0
[r1soft]
name=R1Soft Repository Server
baseurl=http://repo.r1soft.com/yum/stable/$basearch/
enabled=1
gpgcheck=0
--------------------------------------------------------
(3) Install serverbackup-agent
#yum install serverbackup-agent
(4) Test the connectivity with r1soft server using the following command
#serverbackup-setup –test-connection
(5) Install the kernel-devel package using YUM
#yum install kernel-devel
(Note: Please make sure that you have installed proper kernel-devel and header packages.)
(6) Run the following command to build the kernel module.
#serverbackup-setup --get-module
(7) The cdp-agent is installed now and you can restart it as follows
#/etc/init.d/cdp-agent restart
(8) It is important to fetch key from the server. Use the following command to fetch key from the cdp-server
#serverbackup-setup --get-key http://<cdp-server_IP>:<port>
To view the list of keys.
#serverbackup-setup --list-keys
CMS Version Check Script
#!/bin/bash
#
# usage : sh ver.sh
#
#
read -p "ENTER LATEST WORDPRESS VERSION: " wp
read -p "ENTER LATEST JOOMLA VERSION: " jm
read -p "ENTER LATEST VBULLETIN VERSION: " vb
read -p "ENTER LATEST PHPBB VERSION: " pb
read -p "ENTER LATEST DRUPAL VERSION: " dp
cd /home
#
# usage : sh ver.sh
#
#
read -p "ENTER LATEST WORDPRESS VERSION: " wp
read -p "ENTER LATEST JOOMLA VERSION: " jm
read -p "ENTER LATEST VBULLETIN VERSION: " vb
read -p "ENTER LATEST PHPBB VERSION: " pb
read -p "ENTER LATEST DRUPAL VERSION: " dp
cd /home
echo Printing Outdated versions:: > /tmp/versions
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~: >> /tmp/versions
echo >> /tmp/versions
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~: >> /tmp/versions
echo >> /tmp/versions
echo Wordpress installations:: >> /tmp/versions
echo ------------------------: >> /tmp/versions
find /home/*/public_html/ -type f -wholename *wp-includes/version.php -exec grep -H "wp_version = " {} \; | replace "\$wp_version" "Wordpress version" | replace "," "" | replace ";" " " | grep -v $wp >> /tmp/versions
echo >> /tmp/versions
echo ------------------------: >> /tmp/versions
find /home/*/public_html/ -type f -wholename *wp-includes/version.php -exec grep -H "wp_version = " {} \; | replace "\$wp_version" "Wordpress version" | replace "," "" | replace ";" " " | grep -v $wp >> /tmp/versions
echo >> /tmp/versions
echo Joomla Installations:: >> /tmp/versions
echo ---------------------: >> /tmp/versions
find /home/*/public_html/ -name version.php -exec grep -H "var \$RELEASE " {} \; | replace "var \$RELEASE" " Joomla version" | replace "," "" | replace ";" " " | grep -v $jm >> /tmp/versions
echo >> /tmp/versions
echo ---------------------: >> /tmp/versions
find /home/*/public_html/ -name version.php -exec grep -H "var \$RELEASE " {} \; | replace "var \$RELEASE" " Joomla version" | replace "," "" | replace ";" " " | grep -v $jm >> /tmp/versions
echo >> /tmp/versions
echo vBulletin installations:: >> /tmp/versions
echo ------------------------: >> /tmp/versions
find /home/*/public_html/ -type f -wholename *includes/config.php -exec grep -H "Licence Number" {} \; | replace "," "" | replace ";" " " | grep -v $vb >> /tmp/versions
echo >> /tmp/versions
echo ------------------------: >> /tmp/versions
find /home/*/public_html/ -type f -wholename *includes/config.php -exec grep -H "Licence Number" {} \; | replace "," "" | replace ";" " " | grep -v $vb >> /tmp/versions
echo >> /tmp/versions
echo phpBB installations:: >> /tmp/versions
echo --------------------: >> /tmp/versions
find /home/*/public_html/ -type f -wholename *includes/constants.php -exec grep -H "PHPBB_VERSION" {} \; |replace "define(" " " | replace "," "" | replace ";" " " | grep -v $pb >> /tmp/versions
echo >> /tmp/versions
echo --------------------: >> /tmp/versions
find /home/*/public_html/ -type f -wholename *includes/constants.php -exec grep -H "PHPBB_VERSION" {} \; |replace "define(" " " | replace "," "" | replace ";" " " | grep -v $pb >> /tmp/versions
echo >> /tmp/versions
echo Drupal installations:: >> /tmp/versions
echo ---------------------: >> /tmp/versions
find /home/*/public_html/ -type f -wholename *includes/bootstrap.inc -exec grep -H "define('VERSION" {} \; | replace "define(" " " | replace "," "" | replace ";" " " | grep -v $dp >> /tmp/versions
echo >> /tmp/versions
echo ---------------------: >> /tmp/versions
find /home/*/public_html/ -type f -wholename *includes/bootstrap.inc -exec grep -H "define('VERSION" {} \; | replace "define(" " " | replace "," "" | replace ";" " " | grep -v $dp >> /tmp/versions
echo >> /tmp/versions
############
cat /tmp/versions | replace "'" "" > /tmp/versions2
/bin/mv /tmp/versions2 /tmp/versions
/bin/mv /tmp/versions2 /tmp/versions
cut -d: -f1 /tmp/versions | rev| cut -d/ -f2- | rev > /tmp/versions1
cut -d: -f2- /tmp/versions | replace ")" "" | replace "|| #" "" > /tmp/versions2
cut -d: -f2- /tmp/versions | replace ")" "" | replace "|| #" "" > /tmp/versions2
paste /tmp/versions1 /tmp/versions2
rm -f /tmp/versions1 /tmp/versions2
rm -f /tmp/versions1 /tmp/versions2
Subscribe to:
Posts (Atom)