【主机】查看服务器端口状态

早上查看邮件的时候 收到 oracle 1521 不能访问的报警邮件。立即登录服务器,查看 lsnrctl status 一切正常!同事和网络工程师沟通了,发现是凌晨ACL 推演导致暂时不可访问。
这里总结几种查看服务器上端口的状态的方法:
1 netstat -an 查看网络端口 
oracle@yangDB2:/opt/oracle/10.2.0/orcl/network/admin>netstat -antp       
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address       Foreign Address             State       PID/Program name   
tcp        0      0 127.0.0.1:2208      0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:111         0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:784         0.0.0.0:*                   LISTEN      -                   
tcp        0      0 127.0.0.1:1521      0.0.0.0:*                   LISTEN      21883/tnslsnr       
tcp        0      0 127.0.0.1:631       0.0.0.0:*                   LISTEN      -                   
tcp        0      0 127.0.0.1:25        0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:38173       0.0.0.0:*                   LISTEN      5902/ora_d000_orcl  
tcp        0      0 127.0.0.1:2207      0.0.0.0:*                   LISTEN      -                   
tcp        0      0 127.0.0.1:25045     127.0.0.1:1521              ESTABLISHED 5880/ora_pmon_orcl  
tcp        0      0 127.0.0.1:1521      127.0.0.1:25045             ESTABLISHED 21883/tnslsnr       
tcp        0      0 :::22               :::*                        LISTEN      -                   
tcp        0   1036 ::ffff:10.250.7.230:22 ::ffff:10.1.165.1:51312  ESTABLISHED -   
2 lsof -i :port,使用lsof -i :port就能看见所指定端口运行的程序,同时还有当前连接。 
oracle@dba-host1:/home/oracle>lsof -i :1521
COMMAND   PID   USER   FD   TYPE    DEVICE SIZE NODE NAME
oracle    300 oracle   14u  IPv4 380560725       TCP dba-host1.hz.ali.com:1521->10.250.3.42:32845 (ESTABLISHED)
oracle    302 oracle   14u  IPv4 380560734       TCP dba-host1.hz.ali.com:1521->10.250.3.42:32846 (ESTABLISHED)
oracle    304 oracle   14u  IPv4 380560743       TCP dba-host1.hz.ali.com:1521->10.250.3.42:32847 (ESTABLISHED)
oracle    306 oracle   14u  IPv4 380560752       TCP dba-host1.hz.ali.com:1521->10.250.3.42:32848 (ESTABLISHED)
oracle    575 oracle   14u  IPv4 386960754       TCP dba-host1.hz.ali.com:1521->10.1.170.195:55487 (ESTABLISHED)
oracle    952 oracle   14u  IPv4 361820559       TCP dba-host1.hz.ali.com:1521->10.250.2.14:54674 (ESTABLISHED)
oracle   1445 oracle   14u  IPv4 387183135       TCP dba-host1.hz.ali.com:1521->10.250.3.111:15845 (ESTABLISHED)
oracle   1548 oracle   14u  IPv4 386924530       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33970 (ESTABLISHED)
oracle   1550 oracle   14u  IPv4 386924539       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33971 (ESTABLISHED)
oracle   1650 oracle   14u  IPv4 385984708       TCP dba-host1.hz.ali.com:1521->10.1.170.148:1717 (ESTABLISHED)
oracle   2036 oracle   14u  IPv4 385310535       TCP dba-host1.hz.ali.com:1521->10.1.170.143:44647 (ESTABLISHED)
oracle   2734 oracle   14u  IPv4 379270888       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2837 (ESTABLISHED)
oracle   2736 oracle   14u  IPv4 379270897       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2849 (ESTABLISHED)
oracle   2738 oracle   14u  IPv4 379270907       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2855 (ESTABLISHED)
oracle   2740 oracle   14u  IPv4 379270916       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2856 (ESTABLISHED)
oracle   2742 oracle   14u  IPv4 379270925       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2857 (ESTABLISHED)
oracle   2744 oracle   14u  IPv4 379270934       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2859 (ESTABLISHED)
oracle   2746 oracle   14u  IPv4 379270943       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2860 (ESTABLISHED)
oracle   2748 oracle   14u  IPv4 379270952       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2861 (ESTABLISHED)
oracle   2828 oracle   14u  IPv4 379271084       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2875 (ESTABLISHED)
oracle   2830 oracle   14u  IPv4 379271093       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2877 (ESTABLISHED)
oracle   2832 oracle   14u  IPv4 379271102       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2878 (ESTABLISHED)
oracle   2834 oracle   14u  IPv4 379271111       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2880 (ESTABLISHED)
oracle   2836 oracle   14u  IPv4 379271120       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2881 (ESTABLISHED)
oracle   2838 oracle   14u  IPv4 379271129       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2882 (ESTABLISHED)
oracle   2840 oracle   14u  IPv4 379271138       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2884 (ESTABLISHED)
oracle   2842 oracle   14u  IPv4 379271147       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2885 (ESTABLISHED)
oracle   2856 oracle   14u  IPv4 379271211       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2895 (ESTABLISHED)
oracle   2858 oracle   14u  IPv4 379271220       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2896 (ESTABLISHED)
oracle   2870 oracle   14u  IPv4 379271274       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2905 (ESTABLISHED)
oracle   2872 oracle   14u  IPv4 379271283       TCP dba-host1.hz.ali.com:1521->10.250.3.100:2906 (ESTABLISHED)
oracle   3456 oracle   14u  IPv4 355696647       TCP dba-host1.hz.ali.com:1521->10.250.3.51:32818 (ESTABLISHED)
oracle   3460 oracle   14u  IPv4 355696666       TCP dba-host1.hz.ali.com:1521->10.250.3.51:32821 (ESTABLISHED)
oracle   3464 oracle   14u  IPv4 355696685       TCP dba-host1.hz.ali.com:1521->10.250.3.51:32823 (ESTABLISHED)
oracle   3466 oracle   14u  IPv4 355696694       TCP dba-host1.hz.ali.com:1521->10.250.3.51:32824 (ESTABLISHED)
oracle   3475 oracle   14u  IPv4 355696731       TCP dba-host1.hz.ali.com:1521->10.250.3.51:32828 (ESTABLISHED)
oracle   3543 oracle   14u  IPv4 355696974       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33015 (ESTABLISHED)
oracle   3545 oracle   14u  IPv4 355696984       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33016 (ESTABLISHED)
oracle   3547 oracle   14u  IPv4 355696993       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33017 (ESTABLISHED)
oracle   3549 oracle   14u  IPv4 355697002       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33018 (ESTABLISHED)
oracle   3551 oracle   14u  IPv4 355697012       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33019 (ESTABLISHED)
oracle   3553 oracle   14u  IPv4 355697021       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33020 (ESTABLISHED)
oracle   3555 oracle   14u  IPv4 355697030       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33021 (ESTABLISHED)
oracle   3557 oracle   14u  IPv4 355697039       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33022 (ESTABLISHED)
oracle   3559 oracle   14u  IPv4 355697048       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33023 (ESTABLISHED)
oracle   3561 oracle   14u  IPv4 355697057       TCP dba-host1.hz.ali.com:1521->10.250.3.51:33024 (ESTABLISHED)
oracle   3742 oracle   14u  IPv4 387787027       TCP dba-host1.hz.ali.com:1521->10.250.3.111:39453 (ESTABLISHED)
oracle   3915 oracle   14u  IPv4 332853968       TCP dba-host1.hz.ali.com:1521->10.250.3.78:49232 (ESTABLISHED)
oracle   3917 oracle   14u  IPv4 332853977       TCP dba-host1.hz.ali.com:1521->10.250.3.78:49233 (ESTABLISHED)
oracle   3919 oracle   14u  IPv4 332853986       TCP dba-host1.hz.ali.com:1521->10.250.3.78:49234 (ESTABLISHED)
oracle   3921 oracle   14u  IPv4 332853995       TCP dba-host1.hz.ali.com:1521->10.250.3.78:49235 (ESTABLISHED)
oracle   3923 oracle   14u  IPv4 332854004       TCP dba-host1.hz.ali.com:1521->10.250.3.78:49236 (ESTABLISHED)
oracle   3925 oracle   14u  IPv4 332854014       TCP dba-

3 nmap 端口扫描
oracle@yangDB2:/opt/oracle/10.2.0/orcl/network/admin>nmap 10.1.157.42
Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2011-08-18 21:31 CST
Interesting ports on 10.1.157.42:
Not shown: 1670 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
111/tcp  open  rpcbind
952/tcp  open  unknown
1521/tcp open  oracle
5801/tcp open  vnc-http-1
5802/tcp open  vnc-http-2
5901/tcp open  vnc-1
5902/tcp open  vnc-2
6001/tcp open  X11:1
6002/tcp open  X11:2

4 文件/etc/services显示的各个服务的端口号;
oracle@yangDB2:/opt/oracle/10.2.0/orcl/network/admin>cat /etc/services | more
# /etc/services:
# $Id: services,v 1.42 2006/02/23 13:09:23 pknirsch Exp $
#
# Network services, Internet style
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports
# are included, only the more common ones.
#
# The latest IANA port assignments can be gotten from
#       http://www.iana.org/assignments/port-numbers
# The Well Known Ports are those from 0 through 1023.
# The Registered Ports are those from 1024 through 49151
# The Dynamic and/or Private Ports are those from 49152 through 65535
#
# Each line describes one service, and is of the form.:
# service-name  port/protocol  [aliases ...]   [# comment]

tcpmux          1/tcp                           # TCP port service multiplexer
tcpmux          1/udp                           # TCP port service multiplexer
rje             5/tcp                           # Remote Job Entry
rje             5/udp                           # Remote Job Entry
echo            7/tcp
echo            7/udp
discard         9/tcp           sink null
discard         9/udp           sink null
systat          11/tcp          users
systat          11/udp          users
daytime         13/tcp
daytime         13/udp
qotd            17/tcp          quote
qotd            17/udp          quote
msp             18/tcp                          # message send protocol
--More--
使用netstat -a 可以看见所有的端口号,这个自己测试啦。。
上一篇:【教程】阿里云商标自助注册申请快速入门


下一篇:[leetcode/lintcode 题解] 算法面试真题详解:最大线段覆盖