How to pass dhcp details of my local network in my vagrant file - configuration

I have a vagrant file, where the IP of my virtual box is hardcoded.
# The IP address of the first server
primary_ip = "172.17.8.101"
I wanted to dynamically assign the ip based on my local network (corporate network).
In vagrant documentation, I see we can use
The easiest way to use a private network is to allow the IP to be assigned via DHCP.
Vagrant.configure("2") do |config|
config.vm.network "private_network", type: "dhcp"
end
https://www.vagrantup.com/docs/networking/private_network.html
In the same vagrant file, during the configuration I see that the hardcoded ip is referred. Now since, I am using the 'type: dhcp', how can I pass the IP details for the below configuration?
host.vm.provision :shell, inline: %Q|echo 'export ETCD_AUTHORITY="#{primary_ip}:2379"' >> /home/vagrant/.profile|

I have used the below code snippet so that the virtualbox is depends on the host network to get IP address.
config.vm.network "public_network",
use_dhcp_assigned_default_route: true, bridge:
While running my vagrant file, I had the below bridged network interfaces. To auto select the network interface used the below code snippet.
Available bridged network interfaces:
1) Intel(R) 82579LM Gigabit Network Connection
2) VMware Virtual Ethernet Adapter for VMnet1
3) VMware Virtual Ethernet Adapter for VMnet8
code snippet.
config.vm.network "public_network", bridge: "Intel(R) 82579LM Gigabit Network Connection"

Related

Can I set a static ip address for WSL 2?

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

Handling requests to and from non-default network interface

I am working on a project that requires me to have multiple network interfaces. I followed the documentation and created three interfaces. I also changed the firewall rules. But even after changing the firewall rules, I am not getting a reply for an ICMP request to the second interface's external IP.
As seen in the screenshot I have allowed all protocols from anywhere to any instance in my network enter image description here
If you look at the routing table of your VM instance, you'll see that the default route is configured on the primary network interface eth0:
vm-instance:$ ip route
default via 10.156.0.1 dev eth0
...
Whether an Ephemeral or a Static External IP address is configured, this External IP is unknown to the operating system of the VM instance. The External IP address is mapped to the VM's Internal address transparently by VPC. You can verify this with the command
vm-instance:$ ip -4 address show
You'll see that there are no External IPs bound.
Furthermore, IP packet forwarding is disabled both between the network cards of the VM instance and network interfaces of Google-provided Linux. The commands below can verify that:
CloudShell:$ gcloud compute instances describe vm-instance --zone=your-zone | grep canIpForward
vm-instance:$ sudo sysctl net.ipv4.ip_forward
Therefore when a ping packet is received by a secondary interface, it can't reply.
To explore this behavior a bit, you may launch tcpdump on the VM instance so that listen on a secondary interface, for example eth1:
vm-instance:$ sudo apt-get install tcpdump
vm-instance:$ sudo tcpdump -i eth1
then find out External IP of your Cloud Shell appliance and ping the secondary External IP of your VM instance from Cloud Shell:
CloudShell:$ curl ifconfig.me/ip
CloudShell:$ ping [secondary_ip_of_vm_instance]
You'll see in the tcpdump output on the console of your VM instance how ICMP packets are arriving to the eth1 interface from the External IP address of your workstation. But they are not replied.
Google provides explanation of this behavior in the Troubleshooting section of the VPC documentation and suggests possible workarounds:
Virtual Private Cloud > Doc > Creating instances with multiple network interfaces > Troubleshooting > I am not able to connect to secondary interface using external IP:
The DHCP server programs a default route only on the primary network
interface of the VM. If you want to connect to the secondary interface
using an external IP, there are two options. If you only need to
connect outside the network on the secondary network interface, you
can set a default route on that network interface. Otherwise, you can
use Configuring Policy
Routing
to configure a separate routing table using source-based policy
routing in your VM.

People on an other network can't connect to my WAMP server

I'm trying to host a WAMP server (WAMP version 3.0.6 on windows 10) and http:'//localhost, my internal IP and external IP (I forwarded port 80) are working. I Also registered a free .tk domain that's working on my network. But on other WiFi networks people can't connect to my server using my external IP or my domain.
I tested it on my smartphone (using mobile data to simulate the other WiFi network) and I got the error [My server's IP] took too long to respond.
How can I fix this?
In this case you have to make sure that the router is firstly directing to your server machine(local IPs generally have the form 192.168.x.x) and to the correct port ,so if WAMP's Apache is running on port 80 router must redirect to your machine's 80 port.
I've fixed it.
I double checked my port forwarding settings and changed the external IP from port 80. Then I saw a text: "When the External IP address is 0.0.0.0 you can access this port forwarding on internet, if you set a specific External IP address here the access is limited to only this IP address on internet", so I changed my external IP to 0.0.0.0 and now it's working!

Configure in-band OpenFlow Controller with OVS not in miniet

I'm trying to configure a remote OpenFlow controller over an interface which is also part of the bridge OpenVswitch is managing. I am not using mininet; rather, I have a real VM host (supporting a few qemu-kvm VM's) with a real ethernet port. I want the tap interfaces plus the ethernet port to all be in the same bridge and managed by OVS. The OpenFlow controller resides on a different host, reachable only through the physical ethernet port. So far I have set the remote controller for the bridge as well as put the failure mode into "standalone". Unfortunatley the network is simply not coming up after a reboot (NB: before I lost connectivity I did verify that traffic was flowing between the VM host and the OF controller host on port 6633). It seems that, at a minimum, I need to update the OVS database with an "in-band" setting in some table, but I'm not sure how to do this or if this will be sufficient (along with the things I've already done). With mininet, setting this "in-band" configuration appears to be handled by the "topo" command, but (obviously) I can't do it this way. Does anyone have any experience with this kind of an OVS configuration?
Try this :
#ovs-vsctl add-br br1
#ifconfig br1 10.1.2.11 netmask 255.255.255.0
#ovs-vsctl set-controller br1 tcp:<controller-IP>:6633
You will be able to see the ovs connected to controller.

How to ssh and sftp into an ec2 behind an elastic load balacer without elastic ip address

I have been trying to figure out a way to ssh into an ec2 instance behind an elastic load balancer without assigning the ec2 instance an Elastic IP
Usually I would assign an Elastic IP onto an ec2 instance and just SSH and SFTP through that way but is their another way ,I can ssh and sftp without assigning it an elastic ip through PuTTy?
I tried this configuration - the ELB port to be 2222 and the Instance port to 22. It worked for me. For simplicity I used the same SG for both EC2 and ELB.
Similarly you can route the PORT 2220 to 20, 2221 to 21 like this for SFTP
TCP Port 2222(ELB) to 22 (Instance)
Open Putty and enter the ELB DNS with Port 2222 [Be sure if the 2222 is opened to your exit IP of office / public IP via. the SG]
Get the Connection Established [the IP 14.0.1.87 is ELB's ID and not the public IP of my machine]