Skip to content

Instantly share code, notes, and snippets.

@pasupulaphani
Last active December 29, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasupulaphani/7629545 to your computer and use it in GitHub Desktop.
Save pasupulaphani/7629545 to your computer and use it in GitHub Desktop.
Working with vagrant.1. vagrantFile with port forwarded and nat enabled2. Opening ports on vm instance.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "centos_6.4"
config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box"
# Enable access via "localhost:8080" to access port 80 on the guest machine.
config.vm.network :forwarded_port, guest: 80, host: 8080, auto_correct: true
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
Vagrant::Config.run do |config|
config.vm.provision :chef_client do |chef|
chef.chef_server_url = "https://api.opscode.com/organizations/orgname"
chef.validation_key_path = "path to pem file"
chef.environment = "development"
chef.run_list = ["recipe[iptables]"]
end
end
end
# With RHEL 7 / CentOS 7, firewalld was introduced to manage iptables. IMHO, firewalld is more suited for workstations than for server environments.
# It is possible to go back to a more classic iptables setup. First, stop and mask the firewalld service:
systemctl stop firewalld
systemctl mask firewalld
# Then, install the iptables-services package:
yum install iptables-services
# Enable the service at boot-time:
systemctl enable iptables
# Managing the service
systemctl [stop|start|restart] iptables
# Saving your firewall rules can be done as follows:
service iptables save
ssh -p 2222 root@127.0.0.1
pass: vagrant
Opening up ports:
To access apps hosted on your VM from your machine.
You may have to open up some ports on a linux vm or a machine.
You need to open port to accept or allow connections in iptables
## allow everyone to access port 80 and 443 (IPv4 Only)##
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT
Note:All ACCEPT lines should be above REJECT lines in the cofiguration
# restart service
service iptables restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment