Monday 29 September 2014

How to change system hostname in Linux ?

Recently  we got a request from one of our  visitor to post article related to hostname change in Linux operating systems. I am going to cover this  now.

There are two general way to do this 

1)  Temporary 
2)  Permanent

First we go and learn about how to check host name (system name) of the server.
Use "hostname" command to list the system system name.
[root@umser1 ~]# hostname umser1.unixmantra.com [root@umser1 ~]#
    -s, --short              short host name
    -a, --alias               alias names
    -i, --ip-address      addresses for the hostname
    -I, --all-ip-addresses all addresses for the host
    -f, --fqdn, --long    long host name (FQDN)
    -A, --all-fqdns        all long host names (FQDNs)
    -d, --domain           DNS domain name
    -y, --yp, --nis          NIS/YP domainname
    -F, --file                  read hostname or NIS domainname from given fil
In Cent OS  we have another command additionally 
[root@umser1 ~]# sysctl kernel.hostname
kernel.hostname = umser1.unixmantra.com
[root@umser1 ~]#

Change the hostname on a running system (Temporarily) :

This is pretty simple  
#hostname  new-name
will set the hostname of the system to  new-name. This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations – see bellow how to set this permanently). You will most probably need to exit the current shell in order to see the change in your shell prompt.

How Do I Change Hostname Permanently?

For Debian  Systems:
Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh
# /etc/hostname
umser2.unixmantra.com
So on a Debian based system we can edit the file /etc/hostname and change the name of the system and then run:
/etc/init.d/hostname.sh start
to make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used hostname.sh).
For Redhat/Fedora/Cent OS Systems:
As you know if you need  changes to be  permanent   you need to hard-code the relevant configuration files.

To make the hostname name permanent in  RH variants ,you must edit the /etc/sysconfig/network file to change  "HOSTNAME" value to your new hostname.
#vi /etc/sysconfig/network

NETWORKING=yes
HOSTNAME="umser2.unixmantra.com"
GATEWAY="192.168.1.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"
Verification:

Open new session and  there you go ,we can  see our  new hostname
[root@umser2 ~]# hostname
umser2.unixmantra.com
[root@umser2 ~]#

Friday 5 September 2014

Getting "Server refused to allocate pty" upon login attempt

Problem(Abstract)

You are unable to log into AIX because the maximum number of pseudo-terminals have already been allocated.

Symptom

An attempt to log into AIX via telnet or ssh results in this error:

"Server refused to allocate pty"

- You have increased the maximum number of ptys but you still see the problem.
- Each time you log in, the pty number increases and the pty numbers are not getting released and re-used.

Diagnosing the problem

The symptoms may indicate that there is an application that is holding on to ptys and not releasing it.

Try using the 'fuser' command to find the culprit application, like this:
# cd /dev/pts
# fuser *
The 'fuser' command will list all PIDs associated with each pty device.

If there is a process that is not releasing its ptys, you will see its PID occur many times in the fuser output above

Resolving the problem

Restarting the application that you diagnosed above should release all the ptys held by that application. Contact the application vendor support to see if there is a patch or configuration for the problem.