个人工具

“Quick HOWTO : Ch16 : Telnet, TFTP, and xinetd/zh”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
安装Telnet服务软件
Setting Up A Telnet Server
第85行: 第85行:
 
而对于Debian/Ubuntu来说,Telnet服务包前缀为<code>"telnetd"</code>,如:<code>telnetd_0.17-32_i386.deb</code>。
 
而对于Debian/Ubuntu来说,Telnet服务包前缀为<code>"telnetd"</code>,如:<code>telnetd_0.17-32_i386.deb</code>。
  
==Setting Up A Telnet Server==
+
==配置Telnet服务==
  
Setting up the telnet server is easy to do, but the procedure differs between Linux distributions.
+
telnet服务的配置很简单,但在不同Linux发行版本中其过程略有不同。
  
 
===Redhat / Fedora===
 
===Redhat / Fedora===
  
To set up a Telnet server use the <code>chkconfig</code> command to activate Telnet.
+
使用<code>chkconfig</code>命令来配置telnet服务。
  
 
  [root@bigboy tmp]# chkconfig telnet on
 
  [root@bigboy tmp]# chkconfig telnet on
  
You can also use the <code>chkconfig --list</code> command to verify that telnet will be started on the next reboot.
+
你也可以使用<code>chkconfig --list</code>来确认telnet将在系统重启后启动。
  
 
  [root@bigboy tmp]# chkconfig --list | grep telnet
 
  [root@bigboy tmp]# chkconfig --list | grep telnet
第101行: 第101行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
Use the chkconfig command to deactivate telnet, even after the next reboot.
+
使用chkconfig命令来关闭telnet服务。
  
 
  [root@bigboy tmp]# chkconfig telnet off
 
  [root@bigboy tmp]# chkconfig telnet off

2008年12月19日 (五) 23:41的版本


简介

许多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

In Debian / Ubuntu, the Telnet server runs using the inetd, not the xinetd daemon, and uses a single /etc/inetd.conf configuration to manage the activation of the daemons it controls.

To stop Telnet you need only to edit the configuration file, comment out the Telnet server line, and restart inetd as seen in this example:

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:~#

Note: The xinetd package provides much more flexibility than its inetd equivalent. xinetd allows you to restrict connections to specific source IP addresses and allows you to specify the TCP port and server IP address on which to listen. You may want to convert your system to use the xinetd package for Telnet by installing xinetd and creating your own custom /etc/xinetd.d/telnet configuration file. The rest of the examples in this chapter assume that the more versatile xinetd is being used.

Note: You can test whether the Telnet process is running with the following command which is used to check the TCP/UDP ports on which your server is listening, if it isn't running then there will be no response.

[root@bigboy tmp]# netstat -a | grep telnet
tcp        0        0        *:telnet        *:*        LISTEN 
[root@bigboy tmp]#

Basic Telnet Security

There are a number of things you can do to improve the security of telnet. For example, you should also try to ensure that telnet sessions run over secure internal networks or across VPNs to reduce the risk of exposing sensitive data to unauthorized eyes. Check out some other options.

Let Telnet Listen On Another TCP Port

Letting telnet run on an alternate TCP port doesn't encrypt the traffic, but it makes it less likely to be detected as telnet traffic. Remember that this isn't a foolproof strategy; good port scanning programs can detect telnet and other applications running on alternative ports.

1) Edit your /etc/services file and add an entry for a new service. Call it stelnet.

# Local services
stelnet         7777/tcp                        # "secure" telnet

2) Copy the telnet configuration file called /etc/xinetd.d/telnet and call it /etc/xinetd.d/stelnet:

[root@bigboy tmp]# cp /etc/xinetd.d/telnet /etc/xinetd.d/stelnet

3) Edit the new /etc/xinetd.d/stelnet file. Make the new service stelnet and add a port statement for TCP port 7777.

# 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) Use chkconfig to activate stelnet.

[root@bigboy tmp]# chkconfig stelnet on

5) Check to make sure your server is now listening on port 7777 with the netstat command.

[root@bigboy tmp]# netstat -an | grep 777
tcp   0  0 0.0.0.0:7777       0.0.0.0:*          LISTEN
[root@bigboy tmp]#
You should now be able to log in to the new stelnet server on port 7777. This is done using the telnet command with the TCP port as the second argument.
[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:

Let Telnet Allow Connections From Trusted Addresses

You can restrict telnet logins access to individual remote servers by using the only_from keyword in the telnet configuration file. Here's how.

1) Add a list of trusted servers to the /etc/xinetd.d/telnet file separated by spaces:

# 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) Restart telnet.

[root@bigboy tmp]# chkconfig telnet off
[root@bigboy tmp]# chkconfig telnet on

3) Test the telnet session. Servers that are not on the trusted list get the message 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]#