9
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

Vagrantで仮想環境側のポートをあける

1.ホストマシーンの3000番ポートをゲストOSの3000番ポートへフォワードする

Vagrantfileに以下の設定を追記

Vagrantfile
# config.vm.network :forwarded_port, guest: 80, host: 8081
config.vm.network :forwarded_port, guest: 3000, host: 3000

# Create a private network, which allows host-only access to the machine

2.ゲストOSのポート解放設定

vagrant sshコマンドで仮想環境に入り、以下のコマンドからiptablesを編集

ターミナル
$ sudo vi /etc/sysconfig/iptables

-A INPUT -p tcp -m tcp --dport 3000 -j ACCEPT追記

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3000 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

3.vagrantの再起動

ターミナル
$ vagrant halt
$ vagrant up

参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
9
Help us understand the problem. What are the problem?