Setting hostname

#vim /etc/sysconfig/network

Use something like

HOSTNAME=testarossa.maranello.local

to overwrite the default name and domain of the server.

e.g.

NETWORKING=yes
HOSTNAME=testarossa.maranello.local

To avoid rebooting issue the following :

hostname  testarossa.maranello.local

That will set it for the current  session.

 

 

 

Monitoring connections

To monitor TCP and UDP connections the following command is very useful:

netstat -t -u

to have a continuous update use the watch command:

watch netstat -t -u

There is a much stronger tool for real time analysis called iptraf.

It is quite self explanatory :

at command line run

iptraf

This tool has many functions and is text mode menu ncurses based application really worth learning.

 

Fixing Warning: RPMDB altered outside of yum

What does it mean?

The yum message “Warning: RPMDB altered outside of yum.” or, as the yum message said for a few months, “Warning: RPMDB has been altered since the last yum transaction.” means some application has altered the rpm database (installed or removed a package) without going through the Yum APIs. This is almost always due to someone using rpm directly (Ie. rpm -ivh blah.rpm), but another possibility is an application built on top of the rpm APIs (Ie. smart, apt, zypp). While it’s possible that someone has hacked your machine and altered the rpmdb maliciously, it would have to be done poorly to trigger this warning.

Why has yum started to emit this warning?

There are three main sets of reasoning behind bringing this to the users attention.

New yum features require yum being “the” packaging API

There are now a few features in yum, requested by users of the package management system, that require yum is aware of all package actions on the system. Here a few of the current ones:

  • The most obvious example is “yum history”, which records when packages were installed, when and by whom. If yum is not involved in installing/updating/removing/etc. some packages then a lot of the benefits of “yum history” are gone. For instance there is no useful audit trail anymore, you can’t use “yum history list blah” and know you have all the instances where something happened to “blah”.
  • Yum now has it’s own database, for package information it wants to record but has no corresponding entry in the rpmdb, the obvious example is “the id of the repository that this package was installed from” but there are quite a few pieces of info. now.
  • Following on from the previous point, rpmdb versions are a significant feature for managing many machines by yum. They require information from the yumdb, so installing something via. yum on one machine but via. rpm on another would give the machines different “rpmdb versions”.

This is not a complete list, and as more package management features are implemented they are much more likely to be implemented at the yum layer than at the rpm layer. Not because rpm is bad, but for the same reasons that the above features were implemented in yum, it’s much easier and faster to implement them there.

 

Solution :

# yum clean all
 

Setting up NTP server

Setting up NTP is very important for a host of application especially clusters and applications like DBs requiring all the servers to be critically time-wise synced.

Install NTP on Red Hat and CentOS 6

$ yum install ntp
$ chkconfig ntpd on
$ ntpdate pool.ntp.org
$ service ntpd start

Install NTP on Ubuntu

$ apt-get install ntp

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.