使用流浪盒时,是否需要为livereload添加转发端口?

时间:2015-02-10 12:45:53

标签: gruntjs vagrant livereload grunt-contrib-watch puphpet

我试图将livereload浏览器扩展程序与使用puphpet配置的vagrant box一起使用。

我认为端口35729被阻止,因为我无法从主机操作系统(OSX)telnet到该端口。客户操作系统是Ubuntu 14.04。

添加IPTables规则是否足够,或者我是否需要添加新的转发端口并重新配置该框?

iptables -L

target     prot opt source               destination         
ACCEPT     icmp --  anywhere             anywhere             /* 000 accept all icmp */
ACCEPT     all  --  anywhere             anywhere             /* 001 accept all to lo interface */
ACCEPT     all  --  anywhere             anywhere             /* 002 accept related established rules */ state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             multiport ports 1025,socks /* 100 tcp/1025, 1080 */
ACCEPT     tcp  --  anywhere             anywhere             multiport ports ssh /* 100 tcp/22 */
ACCEPT     tcp  --  anywhere             anywhere             multiport ports https /* 100 tcp/443 */
ACCEPT     tcp  --  anywhere             anywhere             multiport ports http /* 100 tcp/80 */
DROP       all  --  anywhere             anywhere             /* 999 drop all */

我尝试添加以下内容:

sudo iptables -A OUTPUT -p tcp -m tcp --dport 35729 -j ACCEPT
sudo iptables -A INPUT -p tcp -m tcp --sport 35729 -j ACCEPT

但这并没有解决问题。我也尝试将此添加到config.yml并运行vagrant provision

    forwarded_port:
        l1J8zgpT2xBX:
            host: '35729'
            guest: '35729'

1 个答案:

答案 0 :(得分:0)

添加forwarded_port下的端口应该足够了,因为我已经将代码写入PuPHPet以将其添加到操作系统防火墙:

if has_key($vm_values, 'vm')
  and has_key($vm_values['vm'], 'network')
  and has_key($vm_values['vm']['network'], 'forwarded_port')
{
  create_resources( iptables_port, $vm_values['vm']['network']['forwarded_port'] )
}

define iptables_port (
  $host,
  $guest,
) {
  if ! defined(Firewall["100 tcp/${guest}"]) {
    firewall { "100 tcp/${guest}":
      port   => $guest,
      proto  => tcp,
      action => 'accept',
    }
  }
}

但是,您必须运行$ vagrant reload,而不是$ vagrant provision。重新加载会影响盒子本身 - 内存,cpus,端口共享等。配置会影响你设置的任何配置脚本(在这种情况下是Puppet)。