Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4600534
  • 博文数量: 671
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 7310
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-14 09:56
文章分类

全部博文(671)

文章存档

2011年(1)

2010年(2)

2009年(24)

2008年(271)

2007年(319)

2006年(54)

我的朋友

分类: LINUX

2007-01-08 13:27:33

linux下的方法:
   使用命令netstat -ntlp 查找到端口号所对应的进程号,然后使用ps -ef 查找所对应的具体的进程(名称),然后将该进程kill掉就可以了;
   chkconfig --list
---- 说明一点: solaris下,没有chkconfig命令,netstat 也不带netstat -ntlp

# uname -a  
SunOS isd 5.9 Generic_117171-07 sun4u sparc SUNW,Sun-Fire-V240
# netstat -ntlp
netstat: illegal option -- t
usage: netstat [-anv] [-f address_family]
       netstat [-g | -p | -s] [-n] [-f address_family] [-P protocol]
       netstat -m
       netstat -i [-I interface] [-an] [-f address_family] [interval]
       netstat -r [-anv] [-f address_family|filter]
       netstat -M [-ns] [-f address_family]
       netstat -D [-I interface] [-f address_family]
# chkconfig --list
chkconfig: not found


linux 下如何直接关闭某个服务呢?(面试IBM时也被这个问题给问住了,主要是和solaris弄混淆了)

1)由xinetd.d控制的,修改/etc/xinetd.d/下对应的文件

[root@idns xinetd.d]# pwd
/etc/xinetd.d
xinetd.d]# ls -rlt
×ÜÓÃÁ¿ 128
-rw-r--r--    1 root     root          515 2005-02-04  time-udp
-rw-r--r--    1 root     root          495 2005-02-04  time
-rw-r--r--    1 root     root          508 2005-02-04  tftp
-rw-r--r--    1 root     root          303 2005-02-04  telnet
-rw-r--r--    1 root     root          406 2005-02-04  sgi_fam
-rw-r--r--    1 root     root          312 2005-02-04  services
-rw-r--r--    1 root     root          317 2005-02-04  rsync
-rw-r--r--    1 root     root          429 2005-02-04  rsh
-rw-r--r--    1 root     root          376 2005-02-04  rlogin
-rw-r--r--    1 root     root          359 2005-02-04  rexec
-rw-r--r--    1 root     root          333 2005-02-04  pop3s
-rw-r--r--    1 root     root          266 2005-02-04  ktalk
-rw-r--r--    1 root     root          307 2005-02-04  kshell
-rw-r--r--    1 root     root          322 2005-02-04  krb5-telnet
-rw-r--r--    1 root     root          309 2005-02-04  klogin
-rw-r--r--    1 root     root          357 2005-02-04  ipop3
-rw-r--r--    1 root     root          451 2005-02-04  ipop2
-rw-r--r--    1 root     root          363 2005-02-04  imaps
-rw-r--r--    1 root     root          368 2005-02-04  imap
-rw-r--r--    1 root     root          325 2005-02-04  gssftp
-rw-r--r--    1 root     root          322 2005-02-04  eklogin
-rw-r--r--    1 root     root          358 2005-02-04  echo-udp
-rw-r--r--    1 root     root          339 2005-02-04  echo
-rw-r--r--    1 root     root          353 2005-02-04  dbskkd-cdb
-rw-r--r--    1 root     root          437 2005-02-04  daytime-udp
-rw-r--r--    1 root     root          417 2005-02-04  daytime
-rw-r--r--    1 root     root          239 2005-02-04  cups-lpd
-rw-r--r--    1 root     root          580 2005-02-04  chargen-udp
-rw-r--r--    1 root     root          560 2005-02-04  chargen
-rw-r--r--    1 root     root          230 2005-02-04  amidxtape
-rw-r--r--    1 root     root          227 2005-02-04  amandaidx
-rw-r--r--    1 root     root          318 2005-02-04  amanda
若要启动或关闭上述这些进程,直接修改里面文件的内容

sample : 打开主机的telnet

# telnet 127.0.0.1
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

说明telnet未打开!
[root@idns xinetd.d]# vi telnet
# default: on
# description: The telnet server serves telnet sessions; it uses
#       unencrypted username/password pairs for authentication.
service telnet
{
        disable = no  由yes改为no
        flags           = REUSE
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/sbin/in.telnetd
        log_on_failure  += USERID
}
保存,退出!
                                   
[root@idns xinetd.d]# ps -ef|grep xine
root      1327     1  0  2005 ?        00:00:00 xinetd -stayalive -pidfile /var/run/xinetd.pid
root     15526 15118  0 13:57 pts/0    00:00:00 grep xine
[root@idns xinetd.d]# kill -HUP 1327
[root@idns xinetd.d]# telnet 127.0.0.1
Trying 127.0.0.1...
Connected to idns (127.0.0.1).
Escape character is '^]'.
Red Hat Enterprise Linux AS release 3 (Taroon Update 2)
Kernel 2.4.21-15.ELsmp on an i686
login:
证明telnet 已打开!

2)不由xinet.d控制的进程,就只能手工杀掉并重起(一般脚本在/etc/init.d里)

说明一下solaris下如何关闭服务:

1)   由/etc/inetd.conf控制的服务,将该服务对应的行直接加#再 kill –HUP ‘inetd pid ‘即可!

2)   不由/etc/inetd.conf控制的服务,和linux下基本一样, 只能手工杀掉并重起(一般脚本在/etc/init.d里)

关于inetd.conf 与/etc/services的区别 (选自版主platinum )

/etc/services只是一个 “service_name/protocol & port” 的对照表而已,inetd.conf是记载下哪些会被加载的服务(未加#)
若你把 apache 的 listen 端口改为 12345,那么netstat -lp,会看到端口12345在监听.若你在 /etc/services 里面添加 12345 端口的说明,前面注释为 platinum,那么 netstat -lp 就会变为 platinum 服务了.
若用 iptables 做针对 port 的 DROP 的话,iptables -vL 也会看到同样的效果
这是在 /etc/nsswitch.conf 里面定义的,service 的解析使用 files
这个功能隶属于 /lib/libnss_files.so.1 和 /lib/libnss_files.so.2
关于 /etc/services 有很多人有误解,以为删了/添了一行数据,就可以关掉/开启某个服务,这是错误的概念,我这里说一下.

#grep 8080 /etc/services
webcache        8080/tcp                        # WWW caching service
webcache        8080/udp                        # WWW caching service
阅读(1783) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~