Tag Archives: unix

How to find and trace open ports in unix

Listing all the preocess ids:

# /usr/bin/ps -ef | sed 1d | awk ‘{print $2}’

Mapping the files to ports using the PID:

# /usr/proc/bin/pfiles 2>/dev/null | /usr/xpg4/bin/grep
or
# /usr/bin/ps -o pid -o args -p | sed 1d

Mapping the sockname to port using the port number:

# for i in `ps -e|awk ‘{print $1}’`; do echo $i; pfiles $i 2>/dev/null | grep ‘port: 1521’; done
or
# pfiles -F /proc/* | nawk ‘/^[0-9]+/ { proc=$2} ; /[s]ockname: AF_INET/ { print proc “n ” $0 }’

There were two explanations why “lsof” did not show, what was expected:

1) One thing that might prevent lsof to print all, is if the ports are controlled by inetd or some such (i.e. there is nothing actively listening on them until you try talking to them).

Also, try telneting to the port and then run lsof while the telnet session is connected.

2) On Solaris 10, using “lsof -i” to show mapping of processes to TCP ports incorrectly shows all processes that have socket open as using port 65535, for example:

sshd 8304 root 8u IPv4 0x60008cdac0 0t0 TCP *:65535
(LISTEN)
sendmail 1446 root 5u IPv4 0x60007ebbe00 0t0 TCP *:65535
(LISTEN)

This is a known bug in lsof that can _not_ be fixed because of differences between Solaris 10 and previous versions. So the useful “lsof -i :” is now not useful.

Collecting Unix System Information

At the very least, collect the following information for each system that you have:
1. Hostname:
% hostname
2. Hostname aliases:
% grep `hostname` /etc/hosts | awk ‘{ print $3 }’
3. Host network addresses:
% grep `hostname` /etc/hosts | awk ‘{ print $1 }’
4.   Host ID:
% hostid
5. System serial number:
On the back of most all computers.
6. Manufacturer of the system’s hardware:
On the front of most computers
7. System model name:
On the front of most computers
8. CPU type:
% uname -a
9. Application architecture:
% uname -a
10.   Kernel architecture:
% uname -a
11.  Amount of main memory:
Can be found at boot time
% dmesg
12.  Operating system name:
% uname -a
13.  Operating system version:
% uname -a
14.  Kernel version:
% uname -a
15.  Disk configuration:
% df

How do I extend the terminal width or set term variables with ksh? / Not Getting the full command info from ps in Unix terminal ?

To identify processes to kill we need to view the FULL output from the ps command (we use the comm field). But by default we are not able to view full command.  So here is the solution..

Solaris :

/usr/ucb/ps -awux

You may need two “w” options. From ps(1b):

-w Uses a wide output format (132 columns rather than 80). If the option letter is repeated, that is, -ww, uses arbitrarily wide output. This information is used to decide how much of long commands to print.

AIX / Linux :

I have a putty remote session or any terminal session with ksh shell. When I insert a long command I can see ‘<‘ suddenly appear on the line and my command begins to scroll horizontally between prompt and ‘<‘ sign while I keep on writing it.

I want to make it clear: a ‘<‘ sing does not appear at the end of the visible line (ie. limited by putty window) but in the middle of it. Is there a way to change it to higher value? I tried TERM, but did not set it.

Answer: You have to define $COLUMNS after you login or in .kshrc. Similarly, you can also define $LINES.

Open your .kshrc or edit .kshrc, and add

# echo $SHELL
/usr/bin/ksh
# export COLUMNS=1000
# ps -ef

 

How do I extend the terminal width or set term variables with ksh? / Not Getting the full command info from ps in Unix terminal ?

To identify processes to kill we need to view the FULL output from the ps command (we use the comm field). But by default we are not able to view full command.  So here is the solution..

Solaris :

/usr/ucb/ps -awux

You may need two “w” options. From ps(1b):

-w Uses a wide output format (132 columns rather than 80). If the option letter is repeated, that is, -ww, uses arbitrarily wide output. This information is used to decide how much of long commands to print.

AIX / Linux :

I have a putty remote session or any terminal session with ksh shell. When I insert a long command I can see ‘<‘ suddenly appear on the line and my command begins to scroll horizontally between prompt and ‘<‘ sign while I keep on writing it.

I want to make it clear: a ‘<‘ sing does not appear at the end of the visible line (ie. limited by putty window) but in the middle of it. Is there a way to change it to higher value? I tried TERM, but did not set it.

Answer: You have to define $COLUMNS after you login or in .kshrc. Similarly, you can also define $LINES.

Open your .kshrc or edit .kshrc, and add

# echo $SHELL
/usr/bin/ksh
# export COLUMNS=1000
# ps -ef

 

Compaq Tru64 UNIX: Setting up Standard File Systems

The following table shows the variables and their corresponding values.


Variables in Standard File Systems

 
Variable Description
<diskname> Full path of a disk, for example, /dev/rz11c
<rawdiskname> Full path of a raw disk, for example, /dev/rrz11c
<disktype> Disk type, for example, rz28
<mountpointname> Full path of a mount point, for example,
SAP DB: /sapdb/<SAPSID>/sapdata1
Informix: Not applicable
Oracle: /oracle/<SAPSID>/sapdata1


To set up a standard file system:

1. Ask the customer which disks are available and make sure that they do not belong to
one of the categories listed in the following table:


Avoidable Disk Categories

Disk Category How to Check
Mounted disks grep <diskname> /etc/fstab
Swapdevices swapon -s | grep <diskname>
Advanced FS cd /etc/fdmns; showfdmn * | grep <diskname>
Volumes within LSM (Logical Storage manager) volprint -Ath | grep <diskname>


2. Create disk label, if necessary:
disklabel -w -r <rawdiskname> <disktype>
3. Create empty file system:
newfs -m 0 <rawdiskname>

4. Create mount point:
mkdir <mountpointname>
5. Add line to /etc/fstab:
<diskname> <mountpointname> ufs
6. Mount file system:
mount <mountpointname>

HP-UX: Checking and Modifying the UNIX Kernel

 

Manual Configuration of the Kernel

 

1. Change the kernel parameters according to the table Recommended Kernel Parameters

for HP-UX in the file

 

/stand/system

 

2. Generate a new kernel after making the changes using the following command:

 

mk_kernel -o /stand/vmunix -s /stand/system

 

3. Reboot your system.

 

Configuration of the Kernel Using SAM

  • Enter the command

 

/usr/sbin/sam

 

  • Select:

Kernel Configuration à Configurable Parameters

 

  • Choose the parameter you want to modify and select:

Actions à Modify Configurable Parameter

 

  • Modify all kernel parameters according to the table Recommended Kernel Parameters for HP-UX.
  • Select Process New Kernel from the Actions menu.
  • Exit SAM.
  • Reboot your system.

 

Unix Sort by IP Address

[root@sunx4150 ~]# cat /etc/hosts

# Do not remove the following line, or various programs
# that require network functionality will fail.
10.1.50.101             sunx4150.xyz.com localhost.localdomain localhost
127.0.0.1               sunx4150.xyz.com localhost.localdomain localhost
10.0.51.50      T5220   T5220.xyz.com
10.0.50.36      ibmaix  ibmaix.xyz.com
10.0.50.9            bucnodc01.xyz.com
10.0.50.36      ibmaix.xyz.com ibmaix
10.1.50.106    ibmcl03.xyz.com     ibmcl03
10.1.51.83      nnl106.xyz.com
10.1.50.134     dbcimb01
10.0.2.20        bkonetapp1
10.112.2.101     spblrdc010
10.0.2.11        bpelapp1
[root@sunx4150 ~]#
[root@sunx4150 ~]#

[root@sunx4150 ~]# sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /etc/hosts

# Do not remove the following line, or various programs
# that require network functionality will fail.
10.0.2.11        bpelapp1
10.0.2.20        bkonetapp1
10.0.50.9         bucnodc01.xyz.com
10.0.50.36      ibmaix  ibmaix.xyz.com
10.0.50.36      ibmaix.xyz.com ibmaix
10.0.51.50      T5220   T5220.xyz.com
10.1.50.101             sunx4150.xyz.com localhost.localdomain localhost
10.1.50.106    ibmcl03.xyz.com     ibmcl03
10.1.50.134     dbcimb01
10.1.51.83      nnl106.xyz.com
10.112.2.101     spblrdc010
127.0.0.1               sunx4150.xyz.com localhost.localdomain localhost
[root@sunx4150 ~]#
[root@sunx4150 ~]#

[root@sunx4150 ~]# sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /etc/hosts | awk '$1!~/:/ &&

!/^$/ && !/^#/’
10.0.2.11        bpelapp1
10.0.2.20        bkonetapp1
10.0.50.9        bucnodc01.xyz.com
10.0.50.36      ibmaix  ibmaix.xyz.com
10.0.50.36      ibmaix.xyz.com ibmaix
10.0.51.50      T5220   T5220.xyz.com
10.1.50.101             sunx4150.xyz.com localhost.localdomain localhost
10.1.50.106    ibmcl03.xyz.com     ibmcl03
10.1.50.134     dbcimb01
10.1.51.83      nnl106.xyz.com
10.112.2.101     spblrdc010
127.0.0.1               sunx4150.xyz.com localhost.localdomain localhost

[root@sunx4150 ~]# sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /etc/hosts | awk '$1!~/:/ && !/^$/ && !/^#/ && !/localhost/'

10.0.2.11        bpelapp1
10.0.2.20        bkonetapp1
10.0.50.9        bucnodc01.xyz.com
10.0.50.36      ibmaix  ibmaix.xyz.com
10.0.50.36      ibmaix.xyz.com ibmaix
10.0.51.50      T5220   T5220.xyz.com
10.1.50.106    ibmcl03.xyz.com     ibmcl03
10.1.50.134     dbcimb01
10.1.51.83      nnl106.xyz.com
10.112.2.101     spblrdc010
[root@sunx4150 ~]#