Setup default gateway with route command Linux

Display default route

The following three commands display the current routing table:

# route

Output:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 ra0
default         dsl-router      0.0.0.0         UG    0      0        0 ra0
# /sbin/route

Output:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
191.255.255.0   *               255.255.255.0   U     0      0        0 eth0
169.254.0.0     *               255.255.0.0     U     0      0        0 eth0
default         191.255.255.1   0.0.0.0         UG    0      0        0 eth0

You can use -n option, to display numerical addresses instead of trying to determine symbolic host names (via dns or /etc/hosts file). This is useful if you are trying to determine why the route to your nameserver has vanished.$

#/sbin/route -n

Output:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
191.255.255.0   0.0.0.0         255.255.255.0   U     0      0        0 venet0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 venet0
0.0.0.0         191.255.255.1   0.0.0.0         UG    0      0        0 venet0

 

Please note that a destionation entry 0.0.0.0 (or default) is the default gatway. In above example 191.255.255.1 is a default gatway.

Add / setup a new route

The syntax is as follows:
route add default gw {IP-ADDRESS} {INTERFACE-NAME}

Where,

  • IP-ADDRESS: Specify router IP address
  • INTERFACE-NAME: Specify interface name such as eth0

For example if your router IP address is 192.168.1.254 type the following command as the root user:

# route add default gw 192.168.1.254 eth0

OR use hostname such as dsl-router:

# route add default gw dsl-router eth0

Setting route using GUI tools/command under Linux

If you find above command hard to use, consider using GUI tools. If your are using Red Hat/CentOS/Fedora core Linux type following command:

# redhat-config-network

OR

If you are using other Linux distribution use command:

# network-admin

Installing iostat in CentOS with yum

Iostat is a very powerful tool for monitoring the throughput of your storage subsystems. Especially to locate bottle necks and pinpoint possible upgrade scenarios. Not immediately visible here is how to install it on Centos 5.x and 6.x.

We shall use the whatprovides tool in yum to locate the packages that provide iostat

  (more…)

Installing vim editor.

To install vim

[root@testarossa-00-0c-29-47-8f-35 ~]# yum whatprovides vim-enhanced
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.crazynetwork.it
 * epel: fr2.rpmfind.net
 * extras: mirror.crazynetwork.it
 * updates: mirror.crazynetwork.it
2:vim-enhanced-7.0.109-7.el5.i386 : A version of the VIM editor which includes
                                  : recent enhancements.
Repo        : base
Matched from:

[root@testarossa-00-0c-29-47-8f-35 ~]# yum install vim-enhanced-7.0.109-7.el5.i386 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.crazynetwork.it
 * epel: ftp.uni-koeln.de
 * extras: mirror.crazynetwork.it
 * updates: mirror.crazynetwork.it
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vim-enhanced.i386 2:7.0.109-7.el5 set to be updated
--> Processing Dependency: vim-common = 2:7.0.109-7.el5 for package: vim-enhanced
--> Running transaction check
---> Package vim-common.i386 2:7.0.109-7.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch         Version                   Repository    Size
================================================================================
Installing:
 vim-enhanced         i386         2:7.0.109-7.el5           base         1.2 M
Installing for dependencies:
 vim-common           i386         2:7.0.109-7.el5           base         6.4 M

Transaction Summary
================================================================================
Install       2 Package(s)
Upgrade       0 Package(s)

Total download size: 7.7 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): vim-enhanced-7.0.109-7.el5.i386.rpm               | 1.2 MB     00:03     
(2/2): vim-common-7.0.109-7.el5.i386.rpm                 | 6.4 MB     00:18     
--------------------------------------------------------------------------------
Total                                           344 kB/s | 7.7 MB     00:22     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : vim-common                                               1/2 
  Installing     : vim-enhanced                                             2/2 

Installed:
  vim-enhanced.i386 2:7.0.109-7.el5                                             

Dependency Installed:
  vim-common.i386 2:7.0.109-7.el5                                               

Complete!
[root@testarossa-00-0c-29-47-8f-35 ~]#

VIM cheat sheet

The list of Vim commands >

Working with files
Vim command Action
:e filename Open a new file. You can use the Tab key for automatic file name completion, just like at the shell command prompt.
:w filename Save changes to a file. If you don’t specify a file name, Vim saves as the file name you were editing. For saving the file under a different name, specify the file name.
:q Quit Vim. If you have unsaved changes, Vim refuses to exit.
:q! Exit Vim without saving changes.
:wq Write the file and exit.
: x Almost the same as :wq, write the file and exit if you’ve made changes to the file. If you haven’t made any changes to the file, Vim exits without writing the file.
These Vim commands and keys work both in command mode and visual mode.
Vim command Action
j or Up Arrow Move the cursor up one line.
k or Down Arrow Down one line.
h or Left Arrow Left one character.
l or Right Arrow Right one character.
e To the end of a word.
E To the end of a whitespace-delimited word.
b To the beginning of a word.
B To the beginning of a whitespace-delimited word.
0 To the beginning of a line.
^ To the first non-whitespace character of a line.
$ To the end of a line.
H To the first line of the screen.
M To the middle line of the screen.
L To the the last line of the screen.
:n Jump to line number n. For example, to jump to line 42, you’d type :42
Inserting and overwriting text
Vim command Action
i Insert before cursor.
I Insert to the start of the current line.
a Append after cursor.
A Append to the end of the current line.
o Open a new line below and insert.
O Open a new line above and insert.
C Change the rest of the current line.
r Overwrite one character. After overwriting the single character, go back to command mode.
R Enter insert mode but replace characters rather than inserting.
The ESC key Exit insert/overwrite mode and go back to command mode.
Deleting text
Vim command Action
x Delete characters under the cursor.
X Delete characters before the cursor.
dd or :d Delete the current line.
Entering visual mode
Vim command Action
v Start highlighting characters. Use the normal movement keys and commands to select text for highlighting.
V Start highlighting lines.
The ESC key Exit visual mode and return to command mode.
Editing blocks of text
Note: the Vim commands marked with (V) work in visual mode, when you’ve selected some text. The other commands work in the command mode, when you haven’t selected any text.
Vim command Action
~ Change the case of characters. This works both in visual and command mode. In visual mode, change the case of highlighted characters. In command mode, change the case of the character uder cursor.
> (V) Shift right (indent).
< (V) Shift left (de-indent).
c (V) Change the highlighted text.
y (V) Yank the highlighted text. In Windows terms, “copy the selected text to clipboard.”
d (V) Delete the highlighted text. In Windows terms, “cut the selected text to clipboard.”
yy or :y or Y Yank the current line. You don’t need to highlight it first.
dd or :d Delete the current line. Again, you don’t need to highlight it first.
p Put the text you yanked or deleted. In Windows terms, “paste the contents of the clipboard”. Put characters after the cursor. Put lines below the current line.
P Put characters before the cursor. Put lines above the current line.
Undo and redo
Vim command Action
u Undo the last action.
U Undo all the latest changes that were made to the current line.
Ctrl + r Redo.
Vim command Action
/pattern Search the file for pattern.
n Scan for next search match in the same direction.
N Scan for next search match but opposite direction.
Replace
Vim command Action
:rs/foo/bar/a Substitute foo with barr determines the range and a determines the arguments.
The range (r) can be
nothing Work on current line only.
number Work on the line whose number you give.
% The whole file.
Arguments (a) can be
g Replace all occurrences in the line. Without this, Vim replaces only the first occurrences in each line.
i Ignore case for the search pattern.
I Don’t ignore case.
c Confirm each substitution. You can type y to substitute this match, n to skip this match, a to substitute this and all the remaining matches (“Yes to all”), and q to quit substitution.
Examples
:452s/foo/bar/ Replace the first occurrence of the word foo with bar on line number 452.
:s/foo/bar/g Replace every occurrence of the word foo with bar on current line.
:%s/foo/bar/g Replace every occurrence of the word foo with bar in the whole file.
:%s/foo/bar/gi The same as above, but ignore the case of the pattern you want to substitute. This replaces fooFOOFoo, and so on.
:%s/foo/bar/gc Confirm every substitution.
:%s/foo/bar/c For each line on the file, replace the first occurrence of foo with bar and confirm every substitution.

Original Post : Here at tuXfiles.org

List interfaces and IPs neatly

The following command gives a neat list of the Devices and their IPs / details without all the gruesome details.

ifconfig | egrep  "Link|inet"

A sample result would be:

[root@testarossa-00-0c-29-47-8f-35 vm]# ifconfig | egrep "Link|inet"
eth0 Link encap:Ethernet HWaddr 00:0C:29:47:8F:2B 
 inet addr:192.168.47.135 Bcast:192.168.47.255 Mask:255.255.255.0
eth1 Link encap:Ethernet HWaddr 00:0C:29:47:8F:35 
 inet addr:192.168.1.71 Bcast:192.168.1.255 Mask:255.255.255.0
lo Link encap:Local Loopback 
 inet addr:127.0.0.1 Mask:255.0.0.0
peth1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF 
vif0.1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF 
vif4.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF 
virbr0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF 
 inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
xenbr1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF 
[root@testarossa-00-0c-29-47-8f-35 vm]#

Dsabling SElinux In Centos

Sometimes and with some DB platforms especially when you are testing and want to reduce the number of variables during development, testing etc.. you don not want SELinux watching your back. While it is a must to enable SELinux in hardened production systems it can be quite a pain to handle. Sometimes it needs disabling (if for a short period), Here is how.

# Important

Changes you make to files while SELinux is disabled may give them an unexpected security label, and new files will not have a label. You may need to relabel part or all of the file system after re-enabling SELinux.

Command Line

From the command line, you can edit the /etc/sysconfig/selinux file. This file is a symlink to/etc/selinux/config. The configuration file is self-explanatory. Changing the value of SELINUX orSELINUXTYPE changes the state of SELinux and the name of the policy to be used the next time the system boots.

[root@host2a ~]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=permissive
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0

At the prompt type :

echo 0 > /selinux/enforce

From the GUI

Use the following procedure to change the mode of SELinux using the GUI.

# Note

You need administrator privileges to perform this procedure.

 

  1. On the System menu, point to Administration and then click Security Level and Firewall to display the Security Level Configuration dialog box.
  1. Click the SELinux tab.
  2. In the SELinux Setting select either DisabledEnforcing or Permissive, and then click OK.
  3. If you changed from Enabled to Disabled or vice versa, you need to restart the machine for the change to take effect.

 

# Note

Changes made using this dialog box are immediately reflected in /etc/sysconfig/selinux.

Slash notation lookup table

Total-addresses: how many unique addresses can be represented. To determine how many are available to be assigned to devices you need to subtract 2 from the provided number to allow for the ‘network’ and ‘broadcast’ address. A further one of these may need to be assigned to a router.

Net bits Subnet mask Total-addresses
/20 255.255.240.0 4096
/21 255.255.248.0 2048
/22 255.255.252.0 1024
/23 255.255.254.0 512
/24 255.255.255.0 256
/25 255.255.255.128 128
/26 255.255.255.192 64
/27 255.255.255.224 32
/28 255.255.255.240 16
/29 255.255.255.248 8
/30 255.255.255.252 4

eg:  192.168.1.0/25 would include all address between 192.168.1.0 and 192.168.1.127.

eg: 192.168.1.128/25 would include all address between 192.168.1.128 and 192.168.1.255

Virtual Loopback Filesystem: Building A Linux Filesystem From An Ordinary File

Unix / Linux has a great inbuilt simplicity to it where you can create file systems on any block set . Now .. a file is a block  set so technically and truly at it’s core a file system can be built on a file and mounted :

I need a 100MB partition for some tests :

Using ofcourse Google as my calculator {pfsssst !!! obviously .. DUH}. I tried 100MB / 512 bytes and got

(100 megabytes) / (512 bytes) = 204 800

[root@localhost admin]# dd if=/dev/zero of=disk-image count=204800
204800+0 records in
204800+0 records out
104857600 bytes (105 MB) copied, 41.8633 s, 2.5 MB/s
[root@localhost admin]#

This command leaves me with a 105MB file in which to create my etx3 fs like so :

[root@localhost admin]# ls -al disk-image 
-rw-r--r--. 1 root root 104857600 Jul 13 18:17 disk-image
[root@localhost admin]#

Once this file is created I will use the mkfs to format over the disk-image file:

[root@localhost admin]# /sbin/mkfs -t ext3 -q disk-image
disk-image is not a block special device.
Proceed anyway? (y,n) y
[root@localhost admin]#

Thus a filesystem now resides on my file named disk-image.

We can now use a loopback device to mount the disk-image anywhere we need it:

[root@localhost admin]# mkdir /mnt/test1
[root@localhost admin]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@localhost admin]# mount disk-image /mnt/test1/
mount: /home/admin/disk-image is not a block device (maybe try `-o loop'?)
[root@localhost admin]# mount -o loop disk-image /mnt/test1/
[root@localhost admin]# cd /mnt/test1/
[root@localhost test1]# ls
lost+found
[root@localhost test1]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              18G  2.7G   14G  16% /
tmpfs                 504M  768K  503M   1% /dev/shm
/dev/sda1             291M   50M  226M  19% /boot
/home/admin/disk-image
                       97M  5.6M   87M   7% /mnt/test1

[root@localhost test1]# touch file1
[root@localhost test1]# mkdir -p top1/bottom1
[root@localhost test1]# tree
.
+-- file1
+-- lost+found
+-- top1
    +-- bottom1

3 directories, 1 file
[root@localhost test1]#

Thus a new file system is now running inside the file.

Backing up that file or moving it to another system would entail now quiescing any applications/scripts working with the file, unmounting the loopback fs system, doing your thing then replace all the cards on the deck 🙂

Introduction to APT (advanced package Tools)

Advanced Packaging Tool

Ubuntu — and all Debian-based distros — includes the Advanced Packaging Tool (APT), which can be used to easily download and install software for the operating system. This article looks at APT, and how it is used.

Topics :
Table of Contents
Installing Software on a Computer
Installing Software on Windows
Installing Software on Linux
Repositories
Enabling Additional Repositories
Software Updates
Configuring Package Updates
GUI Front-Ends to APT
Add/Remove Programs
Synaptic Package Manager
Using APT from the Command-Line
apt-get
dpkg
wget
apt-cache

Introduction to Yum

1. Introduction

 

Yum is a tool for automating package maintenance for a network of workstations running any operating system that use the Red Hat Package Management (RPM) system for distributing packaged tools and applications. It is derived from yup, an automated package updater originally developed for Yellowdog Linux, hence its name: yum is “Yellowdog Updater, Modified”.

Yup was originally written and maintained by Dan Burcaw, Bryan Stillwell, Stephen Edie, and Troy Bengegerdes of Yellowdog Linux (an RPM-based Linux distribution that runs on Apple Macintoshes of various generation). Yum was originally written by Seth Vidal and Michael Stenner, both at Duke University at the time. Since then both Michael and Seth have moved on, Seth to working for Red Hat, where he remains the dominant force behind yum development and maintenance.

It is important to note that yum is an open source GPL project and that many people have contributed code, ideas, bug fixes and documentation. The AUTHORS list was up to 26 or so as of the time of this HOWTO snapshot; yum is a clear example of the power of open source develpmment!

Yum is a Gnu Public License (GPL) tool; it is freely available and can be used, modified, or redistributed without any fee or royalty provided that the terms of its associated license are followed.

1.1 What Yum Can Do

(more…)