<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[LINUX的端口和服务]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Tue, 02 Dec 2008 06:49:21 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	一、端口和服务的关系<br/>端口号与相应服务的对应关系存放在/etc/services文件中，这个文件中可以找到大部分端口。使用netstat命令<br/>显示的服务名称也是从这个文件中找的。有人说将这个文件中的相应端口号注释掉，就可以禁用该端口。<br/>我试了却不起作用，这种方法应该是没有用的，是误传！将相应端口号注释掉，唯一的作用就是使用netsat<br/>命令时，将不显示服务名（比如ftp）而是显示端口号（比如21）。原理也很简单：netstat无法在/etc/services<br/>文件中找到端口号对应的服务名，自然就无法显示了。所以/etc/services文件只是起到端口号与相应服务的<br/>映射关系，与端口的启动和关闭没有关系！<br/><br/>二、查看本机开放的端口<br/>1、netstat&nbsp;&nbsp;&nbsp;&nbsp;查看端口和连接<br/>netstat&nbsp;&nbsp;&nbsp;&nbsp; 列出目前已经连接的服务名<br/>netstat -a&nbsp;&nbsp; 列出目前已经连接的和正在监听的服务名<br/>netstat -an&nbsp;&nbsp; 列出目前已经连接的和正在监听的端口号（与上面的命令功能一样，只是不解释端口号对应的服务名）<br/>netstat -ap&nbsp;&nbsp; 在上面命令的基础上列出连接的PID(进程号)，用这个PID，可以使用KILL 来杀死连接<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 例如：某个连接的PID＝111，想踢出去就使用 KILL -9 111。ok！<br/>netstat -rn&nbsp;&nbsp;&nbsp;&nbsp;输出路由表<br/>2、nmap<br/>nmap&nbsp;&nbsp; 127.0.0.1&nbsp;&nbsp;&nbsp;&nbsp; 查看本机开放的端口，会扫描所有端口<br/>nmap&nbsp;&nbsp; -p 1024&nbsp;&nbsp; 65535&nbsp;&nbsp; 127.0.0.1&nbsp;&nbsp;&nbsp;&nbsp;扫描指定端口范围<br/>nmap -PT 192.168.1.1-111&nbsp;&nbsp; 扫描一组范围的电脑<br/><br/>三、关闭和开启端口（服务）<br/>关闭端口的方法：<br/>1、因为每个端口都有对应的服务，因此要关闭端口只要关闭相应的服务就可以了。<br/>2、用IPTABLE对端口进行限制，这样也能使端口不被访问，但端口本身并没有关闭。<br/>在这儿只介绍关闭服务的方法，IPTABLE的应用以后再讨论。<br/>linux中开机自动启动的服务一般都存放在两个地方：<br/>/etc/init.d/文件夹下的服务：<br/>这个文件夹下的服务都可以通过运行相应的SCRIPT来启动或关闭。<br/>例如：启动sendmail服务&nbsp;&nbsp; ./sendmail start&nbsp;&nbsp;&nbsp;&nbsp; (打开了TCP 25端口)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;关闭sendmail服务&nbsp;&nbsp;./sendmail stop&nbsp;&nbsp;&nbsp;&nbsp;（关闭TCP 25 端口）<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 查看sendmail服务当前状态&nbsp;&nbsp; ./sendmail&nbsp;&nbsp; status （查看服务是否运行）<br/>/etc/xinetd.d/文件夹下的服务：<br/>这个文件夹下的服务需要通过更改服务的配置文件，并重新启动xinetd才可以。<br/>例如：要启动其中的auth服务，打开/etc/xinetd.d/auth配置文件，更改“disable=no”，保存退出。运行/etc/rc.d/init.d/xinetd restart<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 要停止其中的auth服务，打开/etc/xinetd.d/auth配置文件，更改“disable=yes”，保存退出。运行/etc/rc.d/init.d/xinetd restart<br/>四、控制开机自动启动的服务<br/>上面说的控制服务开关方法是在启动linux之后进行操作的，如果我想在linux启动时控制哪些服务启动、哪些服务关闭怎么做？<br/>控制服务自动启动的方法有3个：<br/>1、更改/etc/rc.d下的对应文件夹：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果你登陆的默认界面是字符界面，那么修改rc.3文件夹，如果登陆界面默认是图形界面，那么修改rc.5。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在文件夹中，每个服务的名字前都带有“K”或“S”,S就代表这个服务开机自动运行了，把它删了或前缀改为“K”下次就不会启动了。<br/>2、使用ntsysv命令：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 输入ntsysv命令，将会出现一个服务列表，需要启动的打“*”，简单。<br/>3、使用chkconfig命令：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 让某个服务不自动启动：例如httpd：chkconfig --level 35&nbsp;&nbsp; httpd&nbsp;&nbsp; off&nbsp;&nbsp;&nbsp;&nbsp;；35指的是运行级别<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 让某个服务自动启动：例如httpd：chkconfig --level 35&nbsp;&nbsp; httpd&nbsp;&nbsp; on ；<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 查看所有服务的启动状态：chkconfig --list<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 查看某个服务的启动状态：chkconfig --list &#124;grep httpd<br/>端口和服务的操作就到这儿吧。<br/><br/><br/><br/>这个小脚本可以检测WWW,ftp,ssh,sendmail + pop3服务是否开启：<br/><br/><div class="code">#!/bin/bash<br/>#program: Using to study the &#91; if ... then ... fi &#93; program<br/>#dsk 2007/10/8 3:00<br/>#content: I will using this program to show you sevices<br/>#1. print the program&#039;s work in your screen<br/>echo &quot;Now, the service of your Linux system will be detect!&quot;<br/>echo &quot;The www, ftp,ssh,and sendmail + pop3 will be detect!&quot;<br/>echo &quot; &quot;<br/>#2. www<br/>www=&#039;netstat -an&#124;grep LISTEN&#124;grep :80&#039;<br/>if &#91; &quot;$www&quot; != &quot;&quot; &#93;; then<br/>echo &quot;WWW is runing&quot;<br/>else<br/>echo &quot;WWW is NOT runing&quot;<br/>fi<br/>#3. ftp<br/>ftp=&#039;netstat -an&#124;grep LISTEN&#124;grep :21&#039;<br/>if &#91; &quot;$ftp&quot; != &quot;&quot; &#93;; then<br/>echo &quot;FTP is runing&quot;<br/>else<br/>echo &quot;FTP is not runing&quot;<br/>fi<br/>#4. ssh<br/>ssh=&#039;netstat -an&#124;grep LISTEN&#124;grep :22&#039;<br/>if &#91; &quot;$ssh&quot; != &quot;&quot; &#93;;then<br/>echo &quot;SSH is running&quot;<br/>else<br/>echo &quot;SSH is not running&quot;<br/>fi<br/>#5. sendmail + pop3<br/>smtp=&#039;netstat -an&#124;grep LISTEN&#124;grep :25&#039;<br/>pop3=&#039;netstat -an&#124;grep LISTEN&#124;grep :110&#039;<br/>if &#91; &quot;$smtp&quot; != &quot;&quot; &#93; &amp;&amp; &#91; &quot;$pop3&quot; != &quot;&quot; &#93;; then<br/>echo &quot;Sendmail is OK!&quot;<br/>elif &#91; &quot;$smtp&quot; != &quot;&quot; &#93; &amp;&amp; &#91; &quot;$pop3&quot; = &quot;&quot; &#93;; then<br/>echo &quot;Sendmail have some problems of your pop3!&quot;<br/>elif &#91; &quot;$smtp&quot; = &quot;&quot; &#93; &amp;&amp; &#91; &quot;$pop3&quot; != &quot;&quot; &#93;; then<br/>echo &quot;Sendmail have some problems of your smtp!&quot;<br/>else<br/>echo &quot;Sendmail is NOT running!&quot;<br/>fi</div>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] LINUX的端口和服务]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>