请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

关于vagrant端口映射的问题

老师你好:
我在vagrantfile中添加了

config.vm.network "forwarded_port", guest: 5000, host: 5000

然后使用vagrant reload命令重启,输出

➜ vagrant reload
==> web: Attempting graceful shutdown of VM...
==> web: Checking if box 'centos/7' version '1811.02' is up to date...
==> web: Clearing any previously set forwarded ports...
==> web: Fixed port collision for 22 => 2222. Now on port 2201.
==> web: Clearing any previously set network interfaces...
==> web: Preparing network interfaces based on configuration...
    web: Adapter 1: nat
    web: Adapter 2: hostonly
==> web: Forwarding ports...
    web: 5000 (guest) => 5000 (host) (adapter 1)
    web: 22 (guest) => 2201 (host) (adapter 1)
==> web: Running 'pre-boot' VM customizations...
==> web: Booting VM...
==> web: Waiting for machine to boot. This may take a few minutes...
    web: SSH address: 127.0.0.1:2201
    web: SSH username: vagrant
    web: SSH auth method: private key
==> web: Machine booted and ready!
[web] GuestAdditions seems to be installed (6.0.0) correctly, but not running.
Redirecting to /bin/systemctl start vboxadd.service
Redirecting to /bin/systemctl start vboxadd-service.service
==> web: Checking for guest additions in VM...
==> web: Setting hostname...
==> web: Configuring and enabling network interfaces...
==> web: Rsyncing folder: /Users/s/Vagrant/centos7/ => /vagrant
==> web: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> web: flag to force provisioning. Provisioners marked to run always will still run.

~/Vagrant/centos7 took 39s 

看输出日志没有任何的错误,但是我在宿主机上使用telnet去访问5000端口一直失败。

~/Vagrant/centos7 took 18s 
➜ telnet 192.168.100.100 5000
Trying 192.168.100.100...
telnet: connect to address 192.168.100.100: Connection refused
telnet: Unable to connect to remote host

~/Vagrant/centos7 took 31s 

请问这个问题怎么解决啊??????

正在回答 回答被采纳积分+3

1回答

麦兜搞IT 2019-01-15 04:33:16

您好。

第一,确保主机上能ping通192.168.100.100

第二,您的vagrant上有什么服务开启了5000端口么,首先要确保你在vagrant主机内部能通过telnet 127.0.0.1 5000 连接上。

0 回复 有任何疑惑可以回复我~
  • 提问者 sliverg #1
    我使用sudo firewall-cmd  --add-port=5000/tcp && sudo firewall-cmd --reload  ,提示成功,但是使用telnet 127.0.0.1 5000 还是连接不通
    回复 有任何疑惑可以回复我~ 2019-01-15 08:21:32
  • 麦兜搞IT 回复 提问者 sliverg #2
    嗯,那您的vagrant主机上开通了什么服务监听5000端口么,确保服务是运行的,否则5000端口打开了,没有服务监听也是不行的。  比如您如果想telnet 127.0.0.1 80, 那80端口必须是开的,比如nginx,apache都可以。
    回复 有任何疑惑可以回复我~ 2019-01-16 04:51:23

相似问题

登录后可查看更多问答,登录/注册

问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信