I'm doing some Ruby on Rails development on a WSL 2. The rails app connects to a MySQL server running on my Windows host. When I used WSL 1 it as easy to set the host to 127.0.0.1 but on WSL 2 I have to use the nameserver written in /etc/resolv.conf
But I found out that IP address written in resolv.conf changes on reboots.
Is there a way to set a static IP address for WSL 2 ?
You can consider ocroz/wsl2-boot (see INSTALL for installation instructions)
After running wsl-boot command:
The WSL network is configured as per its predefined definition always (Windows side),
All WSL hosts are configured with their predefined static IP always (Linux side),
All WSL hosts and connected Hyper-V VMs can talk to each other always,
The DNS resolution works however you are connected to Internet or VPN,
You can SSH to WSL host without any delay.
Dec. 2022, microsoft/WSL issue 4210 also adds:
With the latest Windows 11 (22621+), you can already specify the network adapter you want to use for WSL2 in .wslconfig:
[wsl2]
networkingMode=bridged
vmSwitch=my-switch
ipv6=true
So, now you can create a Hyper-V external virtual switch for WSL2 and fix the IP address, no other scripts are required. It works out-of-box.
The same thread adds:
Create a vSwitch in Hyper-V,I Use Hyper-V Gui to do this. Hyper-V has three types of virtual switches -- external, internal, and private.
I choose the "external" type , which is bridge type, the same as VMWare workstation.
set this config in .wslconfig
I find the IP change to the network of my home router,which is replace the old of eth0.
You can set DHCP in you home router, then Fix the IP of the bridge.
To sum up, in the case of bridge, it is essentially DHCP , and whether it is fixed or not depends on the DHCP server.
If you don't want /etc/hosts, /etc/resolv.conf to change after restart, you can create
/etc/wsl.conf
[network]
generateHosts = false
generateResolvConf = false
Related
Question: How do I get CDK to work on the corporate laptop using virtualbox without running into the 'could not find mathcing ip for mac' issue?
environment: Windows7, CDK 3.2.0, Virtualbox 5.0.x/5.1.x various versions tried. Key callout, corporate machine has VPN software (cisco anyconnect) while home pc does not, home pc works fine. Issue happens regardless if using VPN or not. Virtualbox (all versions) proven to work using vagrant.
Key finding:
minishift ssh -> functions, doing an ifconfig returns eth0 with a 10.0.*
network, instead of the expected 192.168.99.* network segments configured
for virtualbox network host adapters. Explicitly using minishift config set
host-only-cidr 192.168.99.1/24 with matching virtualbox host adapters
doesn't change outcome
Details:
c:\devrh\cdk\bin>minishift version
minishift v1.7.0+204ce19 CDK v3.2.0-1
c:\devrh\cdk\bin>minishift start --vm-driver=virtualbox -- Starting local
OpenShift cluster using 'virtualbox'
hypervisor ... -- Starting Minishift VM ............................ FAIL
E1108 10:27:05.991687 3128 start.go:356] Error starting the VM: Error
configuring authorization on host: Could not find matching IP for MAC
address 0800279fa156. Retrying. Error starting
the VM: Error configuring authorization on host: Could not find matching IP
for MAC address 0800279fa156
corporate workstation has the issue, home PC does not.
Minishift delete and restart, same issue (different MAC address, but same issue).
Virtualbox remove all host adapters, minishift delete, restart (which auto-creates new host adapters), same issue.
Minishift --profile approach, same issue.
Uninstalled virtualbox, installed the version from the RHDevSuite installer with the CDK from the installer, all steps tested with that combination as well, same issue.
Additional notes, Virtualbox is working fine with vagrant (static IP’s in vagrant files), virtualbox/vagrant combo works on both corporate and home machine without issues.
Apologies for the bad english, i'm french. :D
I've been looking for an answer since approximatively 4 days, and I don't know how to fix my issue.
So:
I want to virtualize two servers using virtualBox on Windows7 and i want them all on the same local network.
My VMs are running on Ubuntu 16.04
On the first VM I installed a lamp web server with MySQL 5.7 and i add phpmyadmin.
On the second VM I installed Jira standalone
--> I need to connect to my Database from my Jira server
So I used the Bridge adapter on each machine:
network configuration
network configuration
Ip adresses are attributed with the DHCP protocol.
The SQL machine ip is 192.168.6.80
The Jira machine ip is 192.168.6.101
The Host machine ip is 192.168.6.87
I'm able to ping each machine so there is no problem.
SQL server
When I start the machine everything seems to work, i can access from my SQL server:
localhost : home page of apache 2 saying "It Works"
localhost:5671 :
[���
5.7.18-0ubuntu0.16.04.1� ���UKBeM�ÿ÷�ÿ����������T(DGKg1hwd=�mysql_native_password���ÿ„Got
packets out of order
localhost/phpmyadmin : the index page where I can connect perfectly with root.
Host Machine (Windows)
192.168.6.80 : home page of apache 2 saying "It Works"
192.168.6.80:5671 :
[���
5.7.18-0ubuntu0.16.04.1� ���UKBeM�ÿ÷�ÿ����������T(DGKg1hwd=�mysql_native_password���ÿ„Got
packets out of order
192.168.6.80/phpmyadmin : the index page where I can connect perfectly with root.
Jira server
Here when i start the machine it works during approximatively 2-3 minutes,
I'am able to connect via:
mysql -u root -p -h 192.168.6.80 -P 5671
I am perfectly connected and i can also access to all the other adresses.
And then it stop working on this machine only.
Unable to connect
Firefox can’t establish a connection to the server at 192.168.6.80.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer’s network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
And when i re-try to connect via mysql on terminal I get the Error 2003 (HYOOO)
This happen only when i use the connection of my work, at home it works perfectly without stopping!!
I have few leads:
problems of proxy authentication
problems of firewall configuration
i am in a private network with a domain name called something.eu
And when i launch firefox the proxy shows up automatically:
and-etc-ha.something.eu:9090
So i'm invited to enter my id and password.
My id is : luc.myName#something.eu
After that i'm connected to internet with firefox but not in terminal when i want to use apt.
I search on the web and i found this:
export http_proxy="http://Username:password#proxyip:port/"
and
export http_proxy="http://Domain\user:pasword#proxyip:port/"
So I tried different ways and i was able to download with apt. But the internet connexion with firefox was unstable. But if I use firefox on my host machine the connexion is perfect.
I also tried with settings -> network -> network proxy -> method manual
http: and-etc-ha.something.eu port: 9090
I don't know if I was understandable, tell me!^^
If you have any ideas to help me to solve this problem let me know.
Bye!
I found the cause: In fact there was a ip conflict inside the LAN because the DHCP was giving in-use ip address.
I decide to use the NAT connection with Port Forwarding on VirtualBox.
With that configuration I'm able to access my VMs on my LAN using the host ip address followed by the port of my choice.
I am a beginner in linux and I need to upload my JavaEE project on Amazon Ec2 hosting. I am using putty to connect to the server and successfully installed mysql and tomcat. What I need now is to access the tomcat server i.e., http://ipaddress:8080. Can Anybody tell me how to know the ipaddress of the server to access the tomcat server installed. I have used grep --color nameserver /etc/resolv.conf to get the ipaddress but If I type http://ipaddress (from the command):8080 it says the site cannot be reached. Can anybody help me with that.
Regards,
The IP Address is similar to the below, found under Instances / Instances:
The Security Groups you have set up are Located under Network & Security / Security Groups:
Note that in the above, port 3306 can only be reached by one hard-coded IP Address, whereas port 110 is reachable from anywhere. Please also see CIDR.
To hook a certain Security Group into a running instance, perform that off the first screen shot, lower right.
This is my scenario,
I have a Ubuntu 12.10 host and a win 7 guest installed in the virtual box. The Network is configured to be NAT in the virtual box. I have a mysql sever installed in the Ubuntu with “bind_address” in my.cnf is commented out.
How can I access this mysql server from the windows 7 guest? I did some search in Google and came accross with this Host-Only Networking With VirtualBox but I cant get it work as I don't have statics IP with my internet vendor and my network knowledge is very bad. All I know is that I have DHCP enabled Internet connection. So if i do any IP's in the network settings I don't have Internet.
I know that there are plenty of solutions on the other way around (access the guest server from the host) but still cant figure it out.
So any help is appreciated.
Thanks
Your external IP being static or not has no bearing to accessing a virtualized server on your LAN.
Set VirtualBox to bridge mode.
Simply determine your computer's DHCP-selected internal IP (usually 192.168.1.SOMETHING) and replace the last number with another that is less than 250. For example, if your computer was 192.168.1.6, 192.168.1.70 would work fine on the VM(pick a high number to void conflicts).
Set it by using the control panel->adapter settings. Reboot the VM. Connect to MySQL at 192.168.1.70(or the address you picked earlier).
Note: If your computer's address is in a different subnet (192.168.0.XXX, 10.XX.XX.XX, etc) change the last number and keep the first numbers the same as on the host.
I am using Vagrant 1.1.2 on Mac OS X 10.7.5
I am running into an issue with the default networking setup. The network seems to be configured to use a DHCP server providing IPs from 10.0.2.? network, with the gateway being set to 10.0.2.2
Sadly, in the organization I work for, there actually exists a server at 10.0.2.2, which causes huge network communication delays.
How can I configure Vagrant's VirtualBox to use DHCP server providing IPs from a different network? The documentation at http://www.vagrantup.com/ completely ignores this issue, which unfortunately renders my Vagrant useless.
When I disconnect from the corporate network, Vagrant works as expected. So I am quite sure the issue is in the IP collision.
That's more a VirtualBox issue so should have to get Vagrant to set a VirtualBox option for a different DHCP subnet like so:
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natnet1", "192.168/16"]
end