The IP address configured for the host-only network is not within the allowed ranges - vagrant

I got this error when I run vagrant up on my macOS:
The IP address configured for the host-only network is not within the
allowed ranges. Please update the address used to be within the
allowed ranges and run the command again.
Address: 192.168.10.10 Ranges: 192.168.56.0/21
The same Vagrantfile works before, but not any more.
Any idea?

I found the "issue" started to happen after VirtualBox 6.1.26.
The way to solve is creating a new file at /etc/vbox/networks.conf on your macOS with content
* 10.0.0.0/8 192.168.0.0/16
* 2001::/64
Make sure including the asterisks *. Then the issue should be gone.
Regarding the networks.conf content, it can be found at https://www.virtualbox.org/manual/ch06.html#network_hostonly

By modifying the vagrantfile as below, it works for me.
cfg.vm.network "private_network", ip:"192.168.56.10"
I just changed the ip address from "192.168.1.10" to "192.168.56.10".
(Thanks to link in #Hongbo Miao's answers. (https://www.virtualbox.org/manual/ch06.html#network_hostonly))

Changing a Vagrantfile directly is not recommended if you didn't create it.
You can use this instead
vagrant config static_ip 192.168.56.2
The ip address can be any in the range 192.168.56.2 - 192.168.63.254. Make sure to run vagrant reload after making changes.

I had the same problem on MacOs with my Laravel Homestead and I solved doing:
sudo su -
mkdir /etc/vbox/
cd /etc/vbox/
echo '* 0.0.0.0/0 ::/0' > /etc/vbox/networks.conf
chmod 644 /etc/vbox/networks.conf

Easy Solve
$ mkdir /etc/vbox/
$cd /etc/vbox/
vbox$ sudo vi networks.conf
* 10.0.0.0/8 192.168.0.0/16
* 2001::/64

These are some trouble shooting steps that i took for resolving the issue.
In the System Preferences under Security & Privacy, enabling VirtualBox / Oracle.
After the changes restart the VirtualBox
If these doesn't resolve the issue check the following in you Vagrant File.
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
os = "generic/ubuntu2004"
net_ip = "192.168.50"
As you can see the ip range given is not what vagrant is looking for. Change the net_ip value to 192.168.56 .
This will resolve the issue.

I had the same issue on macOS after a system upgrade.
In the System Preferences under Security & Privacy, enabling VirtualBox / Oracle solved it.

Please check if your Virtualbox is updated! A reinstall solved this problem.

Got the same issue solved by the following steps
sudo nano /etc/vbox/networks.conf
10.0.0.0/8 192.168.0.0/16
2001::/64
0.0.0.0/0 ::/0
sudo "/Library/Application Support/VirtualBox/LaunchDaemons/VirtualBoxStartup.sh" restart

Related

No access to web or mysql on vagrant after upgrading to macos monterey

Last week I decided to upgrade the mac to the latest version Monterey. Well. Most things works, except for Vagrant. Well.. it works, except there is almost no connection to the server.
vagrant ssh works.
I have been able to launch virtualbox, but access to http or mysql is not happening.
I know the mysql-server is running. The same goes with the apache server.
Logs have been checked and I cannot see that any traffic going to the server.
Ping is not working.
I have updated virtualbox. I have destroyed the box and upgraded vagrant / homestead. still no luck.
MORE INFO:
When I run traceroute I see that the first hit is the correct IP I have set in hosts file. Then it goes to 192.168.0.1 which isn't going anywhere.
I guess the 192.168.0.1 comes from the mac virtualbox / vagrant is running on.
Any pointers on what to do next are welcome.
Probably the same problem as mine (I couldn't use any longer IP 192.168.10.10). VirtualBox did some changes lately (from VirtualBox 6.1.28 I think) and a new configuration is needed to use your preferred (192.168.0.1) IP address:
On Linux, macOS and Solaris Oracle VM VirtualBox will only allow IP
addresses in 192.168.56.0/21 range to be assigned to host-only
adapters. For IPv6 only link-local addresses are allowed. If other
ranges are desired, they can be enabled by creating
/etc/vbox/networks.conf and specifying allowed ranges there. For
example, to allow 10.0.0.0/8 and 192.168.0.0/16 IPv4 ranges as well as
2001::/64 range put the following lines into /etc/vbox/networks.conf:
* 10.0.0.0/8 192.168.0.0/16
* 2001::/64
You can check the whole information here.
Alternatively (skipping the networks.conf configuration) you can use any IP from the initially supported range like for instance: 192.168.56.10

Cannot clone git repo un EC2 iNSTANCE

I used the following command and tried to clone a repo but unfortunately the following error pops up. I cannot go further
ubuntu#ip-add-rr-ee-ss:~$ git clone https://github.com/repo/file.git
Cloning into 'file'...
fatal: unable to access 'https://github.com/repo/file.git/': Could not resolve host: github.com
Could not resolve host
This must be due to DNS issue on your EC2 instance (I can see that you're using Ubuntu here)
You can try to use curl to test the connection to that URL first
Check the DNS configuration: cat /etc/resolv.conf
If possible, you
should replace your current DNS setting with others DNS like google
(8.8.8.8 & 8.8.4.4)
Try to edit that file: vi /etc/resolv.conf
You
should insert/edit the following into:
nameserver 8.8.8.8
nameserver 8.8.4.4
Save the file by clicking [Esc] and type :wq
I fixed the problem once I added the following to my outbound connection for my group security setting:
Type: All traffic
Protocol: All
ip: 0.0.0.0/0
This also fixed my sudo yum install issues too.

How to resolve domains within a vagrant box?

I have a Debian Vagrant box running a Nginx server which hosts two websites/services that should share data via JSON endpoints.
Websites are accessible with https://app.test and https://cdn.app.test from the browser of the Host MacOS system.
To do this I have setup config.vm.network "private_network", ip: "33.33.33.10" in the Vagrantfile.
I have added to the /etc/hosts file on MacOS:
33.33.33.10 app.test
33.33.33.10 cdn.app.test
I can access both domains from the Mac, that works.
However I cannot use curl https://cdn.app.test/ within the Vagrant box shell because the Domains won't be resolved.
Neither curl_init or file_get_contents work.
I guess the problem is that the Vagrant cannot see the MacOS hosts entries.
What is the right way to configure this dev system? What is the easy fix?
The easy fix is to add
127.0.0.1 app.test
127.0.0.1 cdn.app.test
to /etc/hosts in the Debian Vagrant box.
For Vagrant. copy the default config from /etc/apache2/sites-available/000-default.conf to /etc/apache2/sites-available/"".conf
vagrant ssh // login
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/"<your-test-domain>".conf
Folder name in sites-available should be the exact same as the one that you will be changing in your hosts file later.
Then edit your ServerName and DocumentRoot, enable it -> sudo a2ensite "".conf
restart Apache, edit your hosts file in your host OS.
Inside your hosts file, point to your private IP as specified in Vagrantfile

Using dnsmasq with wildcard on Mac

I'd like to point all *.test domains to my Laravel Homestead machine on 192.168.10.10. I used to have it working with *.dev domains, but after new *.dev policy implemented by Chrome 63, I prefer to change it to *.test.
I fail to understand how local DNS works, as it seems to use trillion different configs and caches. What I did is:
Making sure 192.168.10.10 with HTTP Host set to me.test works. It works.
In /usr/local/etc/dnsmasq.conf, I do have an entry address=/.test/192.168.10.10 (I also tried with 127.0.0.1)
In /etc/resolver/test file, I put nameserver 127.0.0.1 - it used to work this way with /etc/resolver/dev. I still don't understand why it's 127.0.0.1 and not 192.168.10.10. I tried both anyway.
Clearing DNS cache with sudo killall -HUP mDNSResponder; sudo killall mDNSResponderHelper; sudo dscacheutil -flushcache
Restarting dnsmasq with sudo launchctl stop homebrew.mxcl.dnsmasq; sudo launchctl start homebrew.mxcl.dnsmasq.
Trying to visit http://me.test/.
It doesn't work. The domain will take forever to be loaded and nothing happens.
What am I doing wrong?
My OS is High Sierra, dnsmasq installed via homebrew.
I don't use dnsmasq, but I believe you want to edit /usr/local/etc/dnsmasq.conf and have listen-address=127.0.0.1 set so dnsmasq is listening on that IP, but have address=/.test/192.168.10.10 so that .test is routed to 192.168.10.10.
Then make sure System Preferences -> Advanced you have 127.0.0.1 as the first DNS server entry for your connection.
Make sure you're restarting dnsmasq every time you edit the configuration file.

Vagrant Port Forwarding on Mac OS X Lion

I've been struggling trying to connect to a centos 6.4 vm using Vagrant.
I'm using salt as a provisioning agent and I have installed apache,php,mysql packages successfully.
When i ssh into the box apache is running fine. I added an index.html file in /var/www and I get the contents back when I curl localhost:80
Vagrant.configure("2") do |config|
## Chose your base box
config.vm.box = "centos63"
config.vm.box_url = ""
## For masterless, mount your salt file root
config.vm.synced_folder "salt/roots/", "/srv/"
## Use all the defaults:
config.vm.provision :salt do |salt|
salt.verbose = true
salt.run_highstate = true
salt.minion_config = "salt/minion"
end
end
Vagrant::Config.run do |config|
config.vm.forward_port 80, 8080
config.vm.share_folder "mypath", "/var/www/leo", "."
end
I ran sudo lsof -i :8080 on my local machine and gave me no results. I also cleared the iptable config in the guest machine with iptables -F. When I curl the guest machine
curl -v 'localhost:8080'
* About to connect() to localhost port 8080 (#0)
* Trying ::1...
* Connection refused
* Trying 127.0.0.1...
* Connection refused
* Trying fe80::1...
* Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
Do I need guest additions installed? I looked around on how to install this but I'm not sure if it has to be installed on the host or the guest. Not sure what else to try.
What you are trying to do here isn't possible just using vagrant without running vagrant as root. You can run Vagrant as root i believe but VirtualBox won't agree with that. You can continue to use a port number or if you want or need to use port 80 there is a way.
I had this issue when a client of mine asked me to do a Wordpress Multisite setup. With Wordpress MS you can't have port numbers in the URL b/c some of the URL mapping will not work correctly. I was surprised when I found that out and didn't want to go back to using a program like MAMP.
Anyway here are two ways to achieve this goal (neither are very hard). I'm a Mac user so these are Mac specific Answers, I will see if there is a Windows version and update my answer when I can test it to make sure (see below, there is a way).
Way #1 (Mac IP Firewall Utility):
In your vagrant file
config.vm.forward_port 80, 8080
config.vm.forward_port 443, 8443
Thats pretty normal.
Now open up terminal and you can use the ipfw utility
sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to me 80
sudo ipfw add 101 fwd 127.0.0.1,8443 tcp from any to me 443
Now that cmd is not permanent so you would have to re-run the cmd if you restarted your machine. You can make it permanent though and I am including a link below that will explain the rest of way #1.
Web Development on Port 80 and 443 in Vagrant
Way #2 (Mac POW and Anvil):
If you don't have Pow yet, get it! It's a really cool app.
Install Pow and Anvil, you can find Anvil there and you can find Pow there.
You can read the docs on how to set those up but don't pay attention to the "static" and "rack" sites part, you need this part.
You will be using Port Proxying through Pow to take the incoming traffic from mycoolsite.dev and forward it to the virtual machine like mycoolsite.dev:8080 and then the virtual machine will forward 8080 to 80 and back up the line your content will come.
After you install Anvil/Pow and get them set up run this line:
echo 8080 > ~/.pow/mycoolsite
Then click Anvil in the task bar (you may have to refresh it or close and reopen) and turn the site on, thats it, what?? Really? Pow and Anvil rock!!
So there are two ways I have found, I'm sure that there are some things you can do with your Hosts file and I used to do that a bunch. However, these other ways that are available really make it easy to forget about that pesky hosts file.
Note for Windows Users (and Mac users that don't like the first 2 ways): You can use Vagrant Host Manager, you can find out how to set it up here on github. It is a vagrant plugin and basically will edit your hosts file for you, all you do is your vagrantfile config and you are good to go after that. I just tested it on Windows 7 and it worked there so it should be good, if you have any issues just look through the docs on github or file an issue for the Vagrant Host Manager team to review.
I changed the guest port to 5656 and it worked. When running lsof -i :8080 I didn't see any results so i figured nothing was using that port maybe I was wrong.

Resources