netcat“连接被拒绝”在本地主机上
我试图从 php 文件启动的 netcat 连接中获取一个值,但它终止了:
localhost [127.0.0.1] 2000 (?) : Connection refused
我不知道为什么,但如果我以 apache 用户(www-data)的身份 ssh 它,它会很好地工作,这就是我的已经完成:
1)开始一个无限循环,稍有延迟地提供日期:
$ (while true; do nc -l -p 2000 -c "sleep 5; date"; done)&
2)检查是否正常工作:
$ su www-data
$ nc localhost 2000
Fri Oct 16 21:33:20 COT 2009
3)按如下方式创建/var/www/test.php:4
<pre><?php
exec('nc localhost 2000>>/var/www/dates.txt 2>>/var/www/errors.txt &');
?></pre>
)在浏览器上运行它:
http://myserver.com/test.php
5)最后查看两个 txt,日期为空(与 #2 中的响应完全不同),并且错误有“连接被拒绝”错误。
该服务器是一个运行 Ubuntu Server 9.04 的 LAMP 集群,带有 DRBD 和 Heartbeat。
让我发疯的是,这个 test.php 在我的笔记本电脑(Ubuntu Desktop 9.04 上的 LAMP)中运行良好,并且服务器似乎已经打开并正在侦听端口:
$ netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:4743 0.0.0.0:* LISTEN 2326/openhpid
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3364/mysqld
tcp 0 0 0.0.0.0:2000 0.0.0.0:* LISTEN 9510/nc
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3470/apache2
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2320/sshd
tcp 0 0 127.0.0.1:3551 0.0.0.0:* LISTEN 2354/apcupsd
tcp6 0 0 :::22 :::* LISTEN 2320/sshd
我认为这是一个与编程相关的问题,对吗? ,如果不是,请关闭它而不发表任何评论。
提前致谢!
I'm trying to get a value from a netcat connection started at a php file, but it dies with:
localhost [127.0.0.1] 2000 (?) : Connection refused
I don't know why but it works well if I ssh it as apache user (www-data), this is what I've done:
1) Start an endless loop serving a date with a little delay:
$ (while true; do nc -l -p 2000 -c "sleep 5; date"; done)&
2) Check if is working:
$ su www-data
$ nc localhost 2000
Fri Oct 16 21:33:20 COT 2009
3) Create /var/www/test.php as follows:
<pre><?php
exec('nc localhost 2000>>/var/www/dates.txt 2>>/var/www/errors.txt &');
?></pre>
4) Run it on a browser:
http://myserver.com/test.php
5) Finally take a look at both txt's, dates is empty (nothing like the response in #2) and errors has the "Connection refused" error.
The server is a LAMP cluster running Ubuntu Server 9.04 with DRBD and Heartbeat.
What is driving me crazy is that this test.php works well in my laptop (LAMP on Ubuntu Desktop 9.04) and the server seems to have the ports already open and listening:
$ netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:4743 0.0.0.0:* LISTEN 2326/openhpid
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3364/mysqld
tcp 0 0 0.0.0.0:2000 0.0.0.0:* LISTEN 9510/nc
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3470/apache2
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2320/sshd
tcp 0 0 127.0.0.1:3551 0.0.0.0:* LISTEN 2354/apcupsd
tcp6 0 0 :::22 :::* LISTEN 2320/sshd
I think that this is a programming related question right?, if not just close it without any comments please.
Thank in advanced!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这毕竟是一个权限问题...修复了使用 visudo 编辑 /etc/sudoers 来添加:
Well, it was a permission problem after all... fixed editing /etc/sudoers with visudo to add: