利用busybox内置的telnetd搭建开发板端的telnet服务器,采用xinetd管理
1、xinetd移植
到网上下载xinetd-2.3.14.tar.gz,根据你的嵌入式平台交叉编译之,例如我的平台是:
#make CC=unicore32-linux-gcc
(我没有Install,所以就没有执行./configure之类的配置)
编译完成之后,在xinetd目录下生成xinetd的可执行文件,可以将其放在usr/sbin/目录下,然后在contrib目录下会有一些脚本和配置文件。
分别将xinetd.d和xinetd.conf拷贝到etc/目录下,将xinetd拷贝到/etc/init.d/目录下。
我们在运行#/etc/init.d/xinted restart的时候,可能会报一些错误,主要就是xinetd这个脚本里面的一些路径和路径下的文件问题,可以根据提示信息自行修改,我给出我的配置信息。
(1)、/etc/init.d/xinetd
- #!/bin/sh
- ### BEGIN INIT INFO
- # Provides: inetd
- # Required-Start: $local_fs $remote_fs
- # Required-Stop: $local_fs $remote_fs
- # Should-Start: $syslog
- # Should-Stop: $syslog
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: Start or stop the xinetd daemon.
- ### END INIT INFO
- # clear poisonned environment
- unset TMPDIR
- NAME=xinetd
- DAEMON=/usr/sbin/$NAME
- PIDFILE=/var/run/$NAME.pid
- test -x "$DAEMON" || exit 0
- test -e /etc/default/$NAME && . /etc/default/$NAME
- case "$INETD_COMPAT" in
- [Yy]*)
- XINETD_OPTS="$XINETD_OPTS -inetd_compat"
- if perl -MSocket -e 'exit (!socket($sock, AF_INET6, SOCK_STREAM, 0))'; then
- XINETD_OPTS="$XINETD_OPTS -inetd_ipv6"
- fi
- ;;
- esac
- . /lib/lsb/init-functions
- checkportmap () {
- if grep "^[^ *#]" /etc/xinetd.conf | grep -q 'rpc/'; then
- if ! rpcinfo -u localhost portmapper >/dev/null 2>&1; then
- echo
- echo "WARNING: portmapper inactive - RPC services unavailable!"
- echo " Commenting out or removing the RPC services from"
- echo " the /etc/xinetd.conf file will remove this message."
- echo
- fi
- fi
- }
- case "$1" in
- start)
- checkportmap
- log_daemon_msg "Starting internet superserver" "$NAME"
- start-stop-daemon --start --quiet --background --exec "$DAEMON" -- \
- -pidfile "$PIDFILE" $XINETD_OPTS
- log_end_msg $?
- ;;
- stop)
- log_daemon_msg "Stopping internet superserver" "$NAME"
- start-stop-daemon --stop --signal 3 --quiet --oknodo --exec "$DAEMON"
- log_end_msg $?
- ;;
- reload)
- log_daemon_msg "Reloading internet superserver configuration" "$NAME"
- start-stop-daemon --stop --signal 1 --quiet --oknodo --exec "$DAEMON"
- log_end_msg $?
- ;;
- restart|force-reload)
- $0 stop
- $0 start
- ;;
- status)
- status_of_proc -p "$PIDFILE" "$DAEMON" xinetd && exit 0 || exit $?
- ;;
- *)
- echo "Usage: /etc/init.d/xinetd {start|stop|reload|force-reload|restart|status}"
- exit 1
- ;;
- esac
- exit 0
(2)、/etc/xinetd.conf
- #
- # This is the master xinetd configuration file. Settings in the
- # default section will be inherited by all service configurations
- # unless explicitly overridden in the service configuration. See
- # xinetd.conf in the man pages for a more detailed explanation of
- # these attributes.
- includedir /etc/xinetd.d
(3)、/etc/xinetd.d/telnet
- # default: on
- # description: The telnet server serves telnet sessions; it uses \
- # unencrypted username/password pairs for authentication.
- service telnet
- {
- disable = no
- instances = 10
- nice = 0
- port = 23
- #bind = 192.168.1.255
- #only_from = 192.168.1.0/24
- flags = REUSE
- socket_type = stream
- wait = yes
- user = root
- server = /sbin/telnetd
- server_args = -l /bin/sh -p 23
- log_on_failure += USERID
- }
2、配置完了之后,配置你的网卡,设置IP之类的
#/etc/init.d/xinted restart
#netstat -tln
查看是否出现port23监听状态
/wifi-test # netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN
#这时你就可以在你的客户端使用telnet访问你的开办板的telnet服务器了
#telnet 192.168.1.4
阅读(1880) | 评论(1) | 转发(1) |