“Quick HOWTO : Ch16 : Telnet, TFTP, and xinetd/zh”的版本间的差异
来自Ubuntu中文
小 (文字错误) |
|||
(未显示另一用户的1个中间版本) | |||
第24行: | 第24行: | ||
[root@bigboy tmp]# service xinetd restart | [root@bigboy tmp]# service xinetd restart | ||
− | + | 为了让xinetd在机器启动时运行,使用chconfig命令: | |
[root@bigboy tmp]# chkconfig xinetd on | [root@bigboy tmp]# chkconfig xinetd on | ||
第228行: | 第228行: | ||
Connection closed by foreign host. | Connection closed by foreign host. | ||
[root@smallfry tmp]# | [root@smallfry tmp]# | ||
+ | [[Category:Quick_HOWTO]] |
2013年3月14日 (四) 15:29的最新版本
目录
简介
许多linux网络应用程序并不依靠它们自己向特定tcp端口提供访问限制或绑定;取而代之的是它们经常将大量的这种任务交给一个专门为这种目的而生的程序套件来负责;这个套件就是xinetd。
管理xinetd程序
Fedora linux默然下已安装xinetd并将/etc/xinetd.conf作为它的主配置文件。幸运的是你不必经常编辑此文件,这样xinetd每天的工作就是启动和停止xinetd管理的程序。
控制 xinetd
启动和停止xinetd守护进程由/etc/init.d目录下的脚本控制。在启动时的行为由chkconfig控制。
在系统启动后,你可以使用下面命令来启动/停止/重启 xinetd进程:
[root@bigboy tmp]# service xinetd start [root@bigboy tmp]# service xinetd stop [root@bigboy tmp]# service xinetd restart
为了让xinetd在机器启动时运行,使用chconfig命令:
[root@bigboy tmp]# chkconfig xinetd on
控制 xinetd管理的应用程序
Xinetd管理应用程序将其所有的配置文件都保存在/etc/xinetd.d目录下。你可以通过将每个配置文件的disable状态设置为yes/no来告诉xinetd是否允许其启动。
你不必通过编辑这些文件来激活或关闭相应的应用程序。chkconfig命令会自动地帮你启动或停止相应的应用程序!这里有个激活和关闭Samba SWAT web GUI管理应用程序的例子。
[root@bigboy tmp]# chkconfig swat on [root@bigboy tmp]# chkconfig swat off
Telnet
Telnet是这样一种服务,它允许用户登录你的服务器并得到一个类似于你登录VGA终端后的命令提示符。Telnet服务是Fedora中默认安装但不启动的。
Telnet的缺点是只能以纯文本形式发送数据。这就意味着别人可以利用网络分析工具通过分析数据包获得你的用户名和密码。因此对于远程登录来说,使用具有多种加密方式的SSH更安全。
尽管如此,Telnet仍旧被普遍使用。很多网络设备上没有SSH客户端,这使得人们不得不使用telnet来访问其他设备和服务器。稍后我会告诉你如何降低Telnet的不安全性。
使用Telnet客户端
在命令行中使用telnet进行远程登录的命令很简单。你只要输入“telnet IP地址/服务器名"即可。
下面的例子中某人从服务器bigboy登录到服务器smallfry,查看路由表后即注销登录。
[root@bigboy tmp]# telnet 192.168.1.105 Trying 192.168.1.105... Connected to 192.168.1.105. Escape character is '^]'. Linux 2.4.18-14 (smallfry.my-site.com) (10:35 on Sunday, 05 January 2003) Login: peter Password: Last login: Fri Nov 22 23:29:44 on ttyS0 You have new mail. [peter@smallfry peter]$ [peter@smallfry peter]$ netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 255.255.255.255 0.0.0.0 255.255.255.255 UH 40 0 0 wlan0 192.168.1.0 0.0.0.0 255.255.255.0 U 40 0 0 wlan0 127.0.0.0 0.0.0.0 255.0.0.0 U 40 0 0 lo 0.0.0.0 192.168.1.1 0.0.0.0 UG 40 0 0 wlan0 [peter@smallfry peter]$ exit logout Connection closed by foreign host. [root@bigboy tmp]#
安装Telnet服务软件
旧版的RedHat默认已经安装Telnet服务,但Fedora没有,因此你要自己安装。
大部分Linux软件都有预编译包,因此下载和安装并非难事。如果你忘了怎么安装,可以参考第6章 "Installing Linux Software"。
在搜索安装包时,切记Telnet服务RPM包的文件名通常以 "telnet-server
"开头,然后是版本号,如:telnet-server-0.17-28.i386.rpm
。
而对于Debian/Ubuntu来说,Telnet服务包前缀为"telnetd"
,如:telnetd_0.17-32_i386.deb
。
配置Telnet服务
telnet服务的配置很简单,但在不同Linux发行版本中其过程略有不同。
Redhat / Fedora
使用chkconfig
命令来配置telnet服务。
[root@bigboy tmp]# chkconfig telnet on
你也可以使用chkconfig --list
来确认telnet将在系统重启后启动。
[root@bigboy tmp]# chkconfig --list | grep telnet telnet: on [root@bigboy tmp]#
使用chkconfig命令来关闭telnet服务。
[root@bigboy tmp]# chkconfig telnet off
Debian / Ubuntu
在Debian / Ubuntu中Telnet服务通过inetd
来运行,而不是xinetd
,并使用/etc/inetd.conf
目录下单一的配置文件来管理其守护进程的活动状态。
要停止Telnet服务你只需编辑其配置文件,注释掉telnet服务那一行,然后重启inetd
即可。如下所示:
root@u-bigboy:~# vi /etc/inetd.conf ... ... ... # # File: /etc/inetd.conf # #telnet stream tcp nowait telnetd.telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd ... ... ... root@u-bigboy:~# /etc/init.d/inetd restart * Restarting internet superserver... ...done. root@u-bigboy:~# netstat -a | grep telnet root@u-bigboy:~#
注: xinetd
比inetd
更加灵活。xinetd
允许你限制来自特定IP地址的连接,允许你设置特定的TCP端口和要监听的服务器IP地址。为了安装xinetd
并通过创建个性化的/etc/xinetd.d/telnet
配置文件来管理telnet,你可能需要更换你的系统。本章后面的例子假设你用的是 xinetd
。
注: 你可以使用下面的命令来查看你的服务程序正在监听的TCP/UDP端口从而测试telnet进程是否在运行,如果telnet不在运行则将没有任何结果。
[root@bigboy tmp]# netstat -a | grep telnet tcp 0 0 *:telnet *:* LISTEN [root@bigboy tmp]#
基本Telnet安全
你可以通过很多方法来提高telnet的安全性。例如,你可以通过确保telnet运行在安全的内网或VPNs环境中以减小敏感数据被暴露给非法用户的风险。我们来看看其他的一些方法。
让Telnet监听其他TCP端口
让telnet监听其他替换TCP端口并非加密telnet通信,只是使其不易被探测。虽然好的端口扫描工具可以扫描到使用其他替换端口的telnet和其他服务,但这种做法并非一无是处。
1) 修改/etc/services文件如下:
# Local services stelnet 7777/tcp # "secure" telnet
2) 复制telnet配置文件/etc/xinetd.d/telnet为/etc/xinetd.d/stelnet:
[root@bigboy tmp]# cp /etc/xinetd.d/telnet /etc/xinetd.d/stelnet
3) 编辑新建的/etc/xinetd.d/stelnet文件,创建新服务stelnet并设置其端口为TCP7777。
# default: on # description: The telnet server serves telnet sessions # unencrypted username/password pairs for authentication. service stelnet { flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.telnetd log_on_failure += USERID disable = no port = 7777 }
4) 用chkconfig激活stelnet.
[root@bigboy tmp]# chkconfig stelnet on
5) 用netstat命令确认你的telnet服务现在监听的是7777端口。
[root@bigboy tmp]# netstat -an | grep 777 tcp 0 0 0.0.0.0:7777 0.0.0.0:* LISTEN [root@bigboy tmp]#
6)你现在可以通过7777端口登录stelnet服务了。只要将TCP端口号作为telnet命令的第二个参数即可。
[root@smallfry tmp]# telnet 192.168.1.100 7777 Trying 192.168.1.100... Connected to 192.168.1.100. Escape character is '^]'. Fedora Core release 2 (Tettnang) Kernel 2.6.8-1.521 on an i686 login:
让Telnet只允许来自信任的IP地址的连接
你可以通过在telnet配置文件中使用only_from关键字限制远程服务器的telnet登录。具体如下:
1) 在/etc/xinetd.d/telnet文件中添加信任的服务器IP地址列表,IP地址之间用空格隔开:
# default: on # description: The telnet server serves telnet sessions # unencrypted username/password pairs for authentication. service telnet { flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.telnetd log_on_failure += USERID disable = no only_from = 192.168.1.100 127.0.0.1 192.168.1.200 }
2) 重启telnet.
[root@bigboy tmp]# chkconfig telnet off [root@bigboy tmp]# chkconfig telnet on
3) 测试telnet会话。不在信任列表中的服务器将收到“Connection closed by foreign host”的信息。
[root@smallfry tmp]# telnet 192.168.1.100 Trying 192.168.1.100... Connected to 192.168.1.100. Escape character is '^]'. Connection closed by foreign host. [root@smallfry tmp]#