开发者

How to do port forwarding properly with VirtualBox?

I have a trouble connecting to a guest OS in VirtualBox. My environtment is as follows:

  • Host: MacOSX (Lion)
  • Guest: CentOS (5.7, 2.6.18-274.3.1.el5)
  • VirtualBox: 4.1.4 r74291 -- Network Adapter Type: NAT

In the guest OS, I can see that the httpd is running properly like:

$ ps aux | grep httpd
root      2571  0.0  3.5 258440  8824 ?        Ss   08:20   0:00 /usr/sbin/httpd
apache    2573  0.0  2.2 258440  5780 ?        S    08:20   0:00 /usr/sbin/httpd
apache    2574  0.0  2.0 258440  5184 ?        S    08:20   0:00 /usr/sbin/httpd
apache    2575  0.0  2.0 258440  5180 ?        S    08:20   0:00 /usr/sbin/httpd
apache    2576  0.0  2.0 258440  5180 ?        S    08:20   0:00 /usr/sbin/httpd
apache    2577  0.0  2.0 258440  5180 ?        S    08:20   0:00 /usr/sbin/httpd
apache    2578  0.0  2.0 258440  5180 ?        S    08:20   0:00 /usr/sbin/httpd
apache    2579  0.0  2.0 258440  5180 ?        S    08:20   0:00 /usr/sbin/httpd
apache    2580  0.0  2.0 258440  5180 ?        S    08:20   0:00 /usr/sbin/httpd
$ curl localhost
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
...

In the host OS, I did a configuration to do port forwarding as follows:

$ VBoxManage showvminfo CentOS_3 | grep "NIC 1"
NIC 1:           MAC: 080027B1FA87, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny
NIC 1 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 1 Rule(0):   name = http, protocol = tcp, host ip = , host port = 8003, guest ip = , guest port = 80
NIC 1 Rule(1):   name = ssh, protocol = tcp, host ip = , host port = 2203, guest ip = , guest port = 22

As this information go, I'm trying to do port forwarding from 8003 to 80 and from 2203 to 22. In fact, I can make the ssh connection to the guest OS with "ssh -p 2203 localhost". However, when I try to see http://localhost:8003, the browser says "Unable to load the webpage because the server sent no data."

When I try "telnet localhost 8003" in the host OS it seems the port is listening, but there appears no log in the access log of the guest OS.

What should I do to solve this problem? Thanks in advance!

(addition: Oct. 14 15:55)

$ netstat -nl | grep tcp | grep 127.0.0.1 # Host OS
tcp4       0      0  127.0.0.1.8003         127.0.0.1.64698        ESTABLISHED
tcp4       0      0  127.0.0.1.64698        127.0.0.1.8003         ESTABLISHED
tcp4       0      0  127.0.0.1.26164        127.0.0.1.53917        ESTABLISHED
tcp4       0      0  127.0.0.1.53917        127.0.0.1.26164        ESTABLISHED
tcp4       0      0  127.0.0.1.2203         127.0.0.1.53183        ESTABLISHED
tcp4       0      0  127.0.0.1.53183        127.0.0.1.2203         ESTABLISHED

$ netstat -nl | grep tcp # Guest OS
tcp        0      0 0.0.0.0:111          开发者_Python百科       0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:952                 0.0.0.0:*                   LISTEN
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN
tcp        0      0 :::80                       :::*                        LISTEN
tcp        0      0 :::22                       :::*                        LISTEN
tcp        0      0 :::443                      :::*                        LISTEN


It seems that like mkj wrote, you have a firewall installed.

try running (as root): yum install system-config-firewall-tui

run system-config-firewall-tui, select customize and make sure that "WWW (HTTP)" is checked.


Although old question, but this may be helpful to someone, as I faced this problem today. As mentioned by mkj, the issue is with Guest OS ( Centos 6 in my case) firewall. It allows ssh (port 22) connection, but blocks others. I had issue accessing postgresql server running in Guest OS (at port 5432) from Host. So executing following iptables command on Guest OS worked:

 $ sudo iptables -I INPUT -p tcp -m tcp --dport 5432 -j ACCEPT

In your case, for httpd server running at port 80, you may have to do below:

 $ sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT

I never faced this problem when running ubuntu/debian as Guest OS, so probably firewall is not configured in them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜