Permanently set hostname in Ubuntu

Debian based systems use the file /etc/hostname to read the hostname of the computer at boot time and set it up using the init script /etc/init.d/hostname.sh

One can edit the file /etc/hostname and change the hostname and then run:

/etc/init.d/hostname.sh start

Update /etc/hosts ip 127.0.0.1 respectively ( leave the localhost entry untouched)

Steps:

  1. sudo vi  /etc/hostname
  2. Save the file with the hostname you like to set
  3. sudo /etc/init.d/hostname.sh start
  4. sudo vi /etc/hostname
  5. Save file with 127.0.0.1 entry updated
  6. Test using hostname -f
  7. Log off using exit

Ref: http://sysblogd.com/50/change-hostname-permanently-on-debian-or-ubuntu.htm

Installing SNMP on Centos 6.x

Installing SNMP daemon and tools:

As root

yum -y install net-snmp.i686

yum -y install net-snmp-utils

Once these are installed start the snmp daemon:

/etc/init.d/snmpd start

chkconfig snmpd on

 

This is just the basic install but testing it :

snmpwalk -v 1 -c public -O e 127.0.0.1

For production servers it is advisable to at least change the community name.

All configs are in

/etc/snmp/snmpd.conf

and traps are setup here:

/etc/snmp/snmptrapd.conf

No traps are set by default.

Enjoy !!

Missing Perl module with phptop how to fix.

While trying to run phptop after unzipping it I get the following error:

[root@torino phptop-0.5.3]# ./phptop 
Can't locate Term/Size.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at ./phptop line 24.
BEGIN failed--compilation aborted at ./phptop line 24.
[root@torino phptop-0.5.3]#

 

To fix it I had to follow the coming steps:

[root@torino phptop-0.5.3]# yum install cpan
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: it.centos.contactlab.it
 * epel: mirror.karneval.cz
 * extras: it.centos.contactlab.it
 * updates: mirror.bofh.so
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package perl-CPAN.i686 0:1.9402-127.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package Arch Version Repository Size
================================================================================
Installing:
 perl-CPAN i686 1.9402-127.el6 base 244 k
Transaction Summary
================================================================================
Install 1 Package(s)
Total download size: 244 k
Installed size: 663 k
Is this ok [y/N]: y
Downloading Packages:
perl-CPAN-1.9402-127.el6.i686.rpm | 244 kB 00:00 
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
 Installing : perl-CPAN-1.9402-127.el6.i686 1/1 
 Verifying : perl-CPAN-1.9402-127.el6.i686 1/1
Installed:
 perl-CPAN.i686 0:1.9402-127.el6
Complete!
[root@torino phptop-0.5.3]#

Then run cpan

[root@torino phptop-0.5.3]#cpan

And you will be asked  whether to accept default answers just press <ENTER>/

Lots of test later you are presented with the cpan prompt tyoe install Term::Size as follows:

  • ommit: wrote '/usr/share/perl5/CPAN/Config.pm'
    Terminal does not support AddHistory.
    cpan shell -- CPAN exploration and modules installation (v1.9402)
    Enter 'h' for help.
    cpan[1]> install Term::Size

After a long verbose build process assuming all went well ( you need internet connectivity to perform this step) type quit at the prompt as so:

cpan[2]> quit

This returns you to the shell prompt:

[root@torino phptop-0.5.3]# ./phptop 
No phptop records found.
[root@torino phptop-0.5.3]#

Voila !!! the program is working.The error is due to the lack of page reads as yet but the program compiled (JIT) and ran.

 

 

 

Installing EPEL Repository on CentOS

EPEL stands for Extra Packages for Enterprise Linux. This is a massive collection of packages that are very useful for the building of many modern stacks and include many tools for the running and maintenance of systems.

The homepage of EPEL is here: http://fedoraproject.org/wiki/EPEL.

You can browse the package set using repoview:

Installing on Centos 5.x & 6.x:

For EL5:

su -c 'rpm -Uvh http://mirror.switch.ch/ftp/mirror/epel/5/i386/epel-release-5-4.noarch.rpm'
...
su -c 'yum install puppet'

For EL6:

su -c 'rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm'
...
su -c 'yum install puppet'

For EL7

sudo yum install epel-release

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