HyperV - Static Ip with Vagrant











up vote
1
down vote

favorite
1












I'm using Laravel Homestead with Vagrant, and I thought I'd would make sense to use Hyper-V instead of Virtual Box, as it's integrated with Windows.



Here is my problem. Every now and then my Hyper-v virtual machine will get a new IP, usually something 172.20.83.X. This messes up my hosts file as I assing ips to test domains. Thus every time my hyper-v server gets a new ip, I have to re-enter the new ip, which quickly becomes very tedious.



I'm wondering if there is a way I can set the ip to always be the same on my machine.



I tried tinkering with the virtual switch manager for the server, but ended up losing complete internet.










share|improve this question






















  • What type of virtual switch is yours? external? internal? or private?
    – S.Leon
    Sep 3 at 6:50










  • @S.Leon, it's external :)
    – Jazerix
    Sep 3 at 13:20















up vote
1
down vote

favorite
1












I'm using Laravel Homestead with Vagrant, and I thought I'd would make sense to use Hyper-V instead of Virtual Box, as it's integrated with Windows.



Here is my problem. Every now and then my Hyper-v virtual machine will get a new IP, usually something 172.20.83.X. This messes up my hosts file as I assing ips to test domains. Thus every time my hyper-v server gets a new ip, I have to re-enter the new ip, which quickly becomes very tedious.



I'm wondering if there is a way I can set the ip to always be the same on my machine.



I tried tinkering with the virtual switch manager for the server, but ended up losing complete internet.










share|improve this question






















  • What type of virtual switch is yours? external? internal? or private?
    – S.Leon
    Sep 3 at 6:50










  • @S.Leon, it's external :)
    – Jazerix
    Sep 3 at 13:20













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I'm using Laravel Homestead with Vagrant, and I thought I'd would make sense to use Hyper-V instead of Virtual Box, as it's integrated with Windows.



Here is my problem. Every now and then my Hyper-v virtual machine will get a new IP, usually something 172.20.83.X. This messes up my hosts file as I assing ips to test domains. Thus every time my hyper-v server gets a new ip, I have to re-enter the new ip, which quickly becomes very tedious.



I'm wondering if there is a way I can set the ip to always be the same on my machine.



I tried tinkering with the virtual switch manager for the server, but ended up losing complete internet.










share|improve this question













I'm using Laravel Homestead with Vagrant, and I thought I'd would make sense to use Hyper-V instead of Virtual Box, as it's integrated with Windows.



Here is my problem. Every now and then my Hyper-v virtual machine will get a new IP, usually something 172.20.83.X. This messes up my hosts file as I assing ips to test domains. Thus every time my hyper-v server gets a new ip, I have to re-enter the new ip, which quickly becomes very tedious.



I'm wondering if there is a way I can set the ip to always be the same on my machine.



I tried tinkering with the virtual switch manager for the server, but ended up losing complete internet.







networking hyper-v vagrant






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 2 at 21:30









Jazerix

1094




1094












  • What type of virtual switch is yours? external? internal? or private?
    – S.Leon
    Sep 3 at 6:50










  • @S.Leon, it's external :)
    – Jazerix
    Sep 3 at 13:20


















  • What type of virtual switch is yours? external? internal? or private?
    – S.Leon
    Sep 3 at 6:50










  • @S.Leon, it's external :)
    – Jazerix
    Sep 3 at 13:20
















What type of virtual switch is yours? external? internal? or private?
– S.Leon
Sep 3 at 6:50




What type of virtual switch is yours? external? internal? or private?
– S.Leon
Sep 3 at 6:50












@S.Leon, it's external :)
– Jazerix
Sep 3 at 13:20




@S.Leon, it's external :)
– Jazerix
Sep 3 at 13:20










2 Answers
2






active

oldest

votes

















up vote
1
down vote













It seems that the external DHCP server with the scope of 172.20.23.X will provide IP addresses for your virtual machines.
You can use filters in the DHCP console to prevent the DHCP server from issuing addresses to these machines by entering the mac address of the virtual machine. As shown below:
enter image description here



enter image description here



Then you can use other DHCP to set reserved addresses for your virtual machine (my understanding is that you don't want to get the address in the 172.20.83.X scope, so use other DHCP) or manually configure static addresses so that their information is the same as the contents of your host file.






share|improve this answer





















  • Also, make sure that you're not using a dynamic MAC address on your Hyper-V VM. This will cause you to get new IPs even with the DHCP reservation. You can check this under the Network adapters advanced settings...I believe, by default, they're set to dynamic.
    – essjae
    Sep 7 at 18:19












  • This is in no way a criticism of your answer, as at least it provides "workaround" to be applied post-provisioning, but not to be able to specify a static IP address, programatically, while provisioning the VM, is a huge pain. Many workflows require creating and destroying these types of VMs routinely, so any degree of "manual" work required is problematic. Hopefully, Vagrant will address this via github.com/hashicorp/vagrant/issues/8384
    – Ben Johnson
    Nov 28 at 16:38




















up vote
0
down vote













The Asker, and anyone with a similar use-case, is likely operating on a workstation (not Windows Server edition), for local development purposes, in which case a relatively simple solution exists.



Create the Switch



In Hyper-V Manager, create a new Virtual Switch, under Actions panel -> Virtual Switch Manager... -> Create Virtual Switch. Assuming the VM should be able to connect to the Internet, choose the External switch type.



On the next screen, give the switch a name, such as internet-enabled, and choose the physical network interface that is connected to the Internet.



The resultant switch should look something like this:



enter image description here



Hard-Code the Switch's IP Address (Gateway for the VM)



Locate the network adapter that is associated with the new switch, i.e., under Control Panel -> Network and Internet -> Network Connections; its name will reflect the name given in the previous step, e.g., vEthernet (internet-enabled). Right-click the adapter and choose Properties.



Next, click Internet Protocol Version 4 (TCP/IPv4) and click Properties. Enter 192.168.10.1 for the IP address, and 255.255.255.0 for the Subnet mask. The settings should look like this:



enter image description here



Assign a Static IP Address in Guest VM



The final step is to assign a static IP address in the guest VM.



Unfortunately, Vagrant does not (as of v2.2.1) support static IP configuration (see: https://github.com/hashicorp/vagrant/issues/8384 ), so this static IP cannot be assigned prior to provisioning the VM.



Until Vagrant supports this capability, one can simply provision the VM normally and edit the network configuration subsequently.



The process for setting a static IP varies per guest OS, but in Ubuntu 18.04 LTS, for example, it's as simple as editing /etc/netplan/01-netcfg.yaml to include values that match the virtual switch configuration from above (the spaces must be exact!):



network:
version: 2
ethernets:
eth0:
dhcp4: no
addresses: [192.168.10.10/24]
gateway4: 192.168.10.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]


After saving the file, apply the changes with:



$ sudo netplan apply


The VM should reflect the static IP immediately, which can be confirmed with ifconfig:



$ sudo ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::215:5dff:fe38:12a prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:38:01:2a txqueuelen 1000 (Ethernet)
...


The host can now ping the guest at 192.168.10.10, and the guest can ping the host at 192.168.10.1.



References:




  • https://www.veeam.com/blog/how-to-configure-hyper-v-virtual-switch.html

  • https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-04-bionic-beaver-linux#h6-2-1-ubuntu-server






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1354658%2fhyperv-static-ip-with-vagrant%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    It seems that the external DHCP server with the scope of 172.20.23.X will provide IP addresses for your virtual machines.
    You can use filters in the DHCP console to prevent the DHCP server from issuing addresses to these machines by entering the mac address of the virtual machine. As shown below:
    enter image description here



    enter image description here



    Then you can use other DHCP to set reserved addresses for your virtual machine (my understanding is that you don't want to get the address in the 172.20.83.X scope, so use other DHCP) or manually configure static addresses so that their information is the same as the contents of your host file.






    share|improve this answer





















    • Also, make sure that you're not using a dynamic MAC address on your Hyper-V VM. This will cause you to get new IPs even with the DHCP reservation. You can check this under the Network adapters advanced settings...I believe, by default, they're set to dynamic.
      – essjae
      Sep 7 at 18:19












    • This is in no way a criticism of your answer, as at least it provides "workaround" to be applied post-provisioning, but not to be able to specify a static IP address, programatically, while provisioning the VM, is a huge pain. Many workflows require creating and destroying these types of VMs routinely, so any degree of "manual" work required is problematic. Hopefully, Vagrant will address this via github.com/hashicorp/vagrant/issues/8384
      – Ben Johnson
      Nov 28 at 16:38

















    up vote
    1
    down vote













    It seems that the external DHCP server with the scope of 172.20.23.X will provide IP addresses for your virtual machines.
    You can use filters in the DHCP console to prevent the DHCP server from issuing addresses to these machines by entering the mac address of the virtual machine. As shown below:
    enter image description here



    enter image description here



    Then you can use other DHCP to set reserved addresses for your virtual machine (my understanding is that you don't want to get the address in the 172.20.83.X scope, so use other DHCP) or manually configure static addresses so that their information is the same as the contents of your host file.






    share|improve this answer





















    • Also, make sure that you're not using a dynamic MAC address on your Hyper-V VM. This will cause you to get new IPs even with the DHCP reservation. You can check this under the Network adapters advanced settings...I believe, by default, they're set to dynamic.
      – essjae
      Sep 7 at 18:19












    • This is in no way a criticism of your answer, as at least it provides "workaround" to be applied post-provisioning, but not to be able to specify a static IP address, programatically, while provisioning the VM, is a huge pain. Many workflows require creating and destroying these types of VMs routinely, so any degree of "manual" work required is problematic. Hopefully, Vagrant will address this via github.com/hashicorp/vagrant/issues/8384
      – Ben Johnson
      Nov 28 at 16:38















    up vote
    1
    down vote










    up vote
    1
    down vote









    It seems that the external DHCP server with the scope of 172.20.23.X will provide IP addresses for your virtual machines.
    You can use filters in the DHCP console to prevent the DHCP server from issuing addresses to these machines by entering the mac address of the virtual machine. As shown below:
    enter image description here



    enter image description here



    Then you can use other DHCP to set reserved addresses for your virtual machine (my understanding is that you don't want to get the address in the 172.20.83.X scope, so use other DHCP) or manually configure static addresses so that their information is the same as the contents of your host file.






    share|improve this answer












    It seems that the external DHCP server with the scope of 172.20.23.X will provide IP addresses for your virtual machines.
    You can use filters in the DHCP console to prevent the DHCP server from issuing addresses to these machines by entering the mac address of the virtual machine. As shown below:
    enter image description here



    enter image description here



    Then you can use other DHCP to set reserved addresses for your virtual machine (my understanding is that you don't want to get the address in the 172.20.83.X scope, so use other DHCP) or manually configure static addresses so that their information is the same as the contents of your host file.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 4 at 7:44









    S.Leon

    3355




    3355












    • Also, make sure that you're not using a dynamic MAC address on your Hyper-V VM. This will cause you to get new IPs even with the DHCP reservation. You can check this under the Network adapters advanced settings...I believe, by default, they're set to dynamic.
      – essjae
      Sep 7 at 18:19












    • This is in no way a criticism of your answer, as at least it provides "workaround" to be applied post-provisioning, but not to be able to specify a static IP address, programatically, while provisioning the VM, is a huge pain. Many workflows require creating and destroying these types of VMs routinely, so any degree of "manual" work required is problematic. Hopefully, Vagrant will address this via github.com/hashicorp/vagrant/issues/8384
      – Ben Johnson
      Nov 28 at 16:38




















    • Also, make sure that you're not using a dynamic MAC address on your Hyper-V VM. This will cause you to get new IPs even with the DHCP reservation. You can check this under the Network adapters advanced settings...I believe, by default, they're set to dynamic.
      – essjae
      Sep 7 at 18:19












    • This is in no way a criticism of your answer, as at least it provides "workaround" to be applied post-provisioning, but not to be able to specify a static IP address, programatically, while provisioning the VM, is a huge pain. Many workflows require creating and destroying these types of VMs routinely, so any degree of "manual" work required is problematic. Hopefully, Vagrant will address this via github.com/hashicorp/vagrant/issues/8384
      – Ben Johnson
      Nov 28 at 16:38


















    Also, make sure that you're not using a dynamic MAC address on your Hyper-V VM. This will cause you to get new IPs even with the DHCP reservation. You can check this under the Network adapters advanced settings...I believe, by default, they're set to dynamic.
    – essjae
    Sep 7 at 18:19






    Also, make sure that you're not using a dynamic MAC address on your Hyper-V VM. This will cause you to get new IPs even with the DHCP reservation. You can check this under the Network adapters advanced settings...I believe, by default, they're set to dynamic.
    – essjae
    Sep 7 at 18:19














    This is in no way a criticism of your answer, as at least it provides "workaround" to be applied post-provisioning, but not to be able to specify a static IP address, programatically, while provisioning the VM, is a huge pain. Many workflows require creating and destroying these types of VMs routinely, so any degree of "manual" work required is problematic. Hopefully, Vagrant will address this via github.com/hashicorp/vagrant/issues/8384
    – Ben Johnson
    Nov 28 at 16:38






    This is in no way a criticism of your answer, as at least it provides "workaround" to be applied post-provisioning, but not to be able to specify a static IP address, programatically, while provisioning the VM, is a huge pain. Many workflows require creating and destroying these types of VMs routinely, so any degree of "manual" work required is problematic. Hopefully, Vagrant will address this via github.com/hashicorp/vagrant/issues/8384
    – Ben Johnson
    Nov 28 at 16:38














    up vote
    0
    down vote













    The Asker, and anyone with a similar use-case, is likely operating on a workstation (not Windows Server edition), for local development purposes, in which case a relatively simple solution exists.



    Create the Switch



    In Hyper-V Manager, create a new Virtual Switch, under Actions panel -> Virtual Switch Manager... -> Create Virtual Switch. Assuming the VM should be able to connect to the Internet, choose the External switch type.



    On the next screen, give the switch a name, such as internet-enabled, and choose the physical network interface that is connected to the Internet.



    The resultant switch should look something like this:



    enter image description here



    Hard-Code the Switch's IP Address (Gateway for the VM)



    Locate the network adapter that is associated with the new switch, i.e., under Control Panel -> Network and Internet -> Network Connections; its name will reflect the name given in the previous step, e.g., vEthernet (internet-enabled). Right-click the adapter and choose Properties.



    Next, click Internet Protocol Version 4 (TCP/IPv4) and click Properties. Enter 192.168.10.1 for the IP address, and 255.255.255.0 for the Subnet mask. The settings should look like this:



    enter image description here



    Assign a Static IP Address in Guest VM



    The final step is to assign a static IP address in the guest VM.



    Unfortunately, Vagrant does not (as of v2.2.1) support static IP configuration (see: https://github.com/hashicorp/vagrant/issues/8384 ), so this static IP cannot be assigned prior to provisioning the VM.



    Until Vagrant supports this capability, one can simply provision the VM normally and edit the network configuration subsequently.



    The process for setting a static IP varies per guest OS, but in Ubuntu 18.04 LTS, for example, it's as simple as editing /etc/netplan/01-netcfg.yaml to include values that match the virtual switch configuration from above (the spaces must be exact!):



    network:
    version: 2
    ethernets:
    eth0:
    dhcp4: no
    addresses: [192.168.10.10/24]
    gateway4: 192.168.10.1
    nameservers:
    addresses: [8.8.8.8,8.8.4.4]


    After saving the file, apply the changes with:



    $ sudo netplan apply


    The VM should reflect the static IP immediately, which can be confirmed with ifconfig:



    $ sudo ifconfig
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
    inet6 fe80::215:5dff:fe38:12a prefixlen 64 scopeid 0x20<link>
    ether 00:15:5d:38:01:2a txqueuelen 1000 (Ethernet)
    ...


    The host can now ping the guest at 192.168.10.10, and the guest can ping the host at 192.168.10.1.



    References:




    • https://www.veeam.com/blog/how-to-configure-hyper-v-virtual-switch.html

    • https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-04-bionic-beaver-linux#h6-2-1-ubuntu-server






    share|improve this answer

























      up vote
      0
      down vote













      The Asker, and anyone with a similar use-case, is likely operating on a workstation (not Windows Server edition), for local development purposes, in which case a relatively simple solution exists.



      Create the Switch



      In Hyper-V Manager, create a new Virtual Switch, under Actions panel -> Virtual Switch Manager... -> Create Virtual Switch. Assuming the VM should be able to connect to the Internet, choose the External switch type.



      On the next screen, give the switch a name, such as internet-enabled, and choose the physical network interface that is connected to the Internet.



      The resultant switch should look something like this:



      enter image description here



      Hard-Code the Switch's IP Address (Gateway for the VM)



      Locate the network adapter that is associated with the new switch, i.e., under Control Panel -> Network and Internet -> Network Connections; its name will reflect the name given in the previous step, e.g., vEthernet (internet-enabled). Right-click the adapter and choose Properties.



      Next, click Internet Protocol Version 4 (TCP/IPv4) and click Properties. Enter 192.168.10.1 for the IP address, and 255.255.255.0 for the Subnet mask. The settings should look like this:



      enter image description here



      Assign a Static IP Address in Guest VM



      The final step is to assign a static IP address in the guest VM.



      Unfortunately, Vagrant does not (as of v2.2.1) support static IP configuration (see: https://github.com/hashicorp/vagrant/issues/8384 ), so this static IP cannot be assigned prior to provisioning the VM.



      Until Vagrant supports this capability, one can simply provision the VM normally and edit the network configuration subsequently.



      The process for setting a static IP varies per guest OS, but in Ubuntu 18.04 LTS, for example, it's as simple as editing /etc/netplan/01-netcfg.yaml to include values that match the virtual switch configuration from above (the spaces must be exact!):



      network:
      version: 2
      ethernets:
      eth0:
      dhcp4: no
      addresses: [192.168.10.10/24]
      gateway4: 192.168.10.1
      nameservers:
      addresses: [8.8.8.8,8.8.4.4]


      After saving the file, apply the changes with:



      $ sudo netplan apply


      The VM should reflect the static IP immediately, which can be confirmed with ifconfig:



      $ sudo ifconfig
      eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
      inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
      inet6 fe80::215:5dff:fe38:12a prefixlen 64 scopeid 0x20<link>
      ether 00:15:5d:38:01:2a txqueuelen 1000 (Ethernet)
      ...


      The host can now ping the guest at 192.168.10.10, and the guest can ping the host at 192.168.10.1.



      References:




      • https://www.veeam.com/blog/how-to-configure-hyper-v-virtual-switch.html

      • https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-04-bionic-beaver-linux#h6-2-1-ubuntu-server






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        The Asker, and anyone with a similar use-case, is likely operating on a workstation (not Windows Server edition), for local development purposes, in which case a relatively simple solution exists.



        Create the Switch



        In Hyper-V Manager, create a new Virtual Switch, under Actions panel -> Virtual Switch Manager... -> Create Virtual Switch. Assuming the VM should be able to connect to the Internet, choose the External switch type.



        On the next screen, give the switch a name, such as internet-enabled, and choose the physical network interface that is connected to the Internet.



        The resultant switch should look something like this:



        enter image description here



        Hard-Code the Switch's IP Address (Gateway for the VM)



        Locate the network adapter that is associated with the new switch, i.e., under Control Panel -> Network and Internet -> Network Connections; its name will reflect the name given in the previous step, e.g., vEthernet (internet-enabled). Right-click the adapter and choose Properties.



        Next, click Internet Protocol Version 4 (TCP/IPv4) and click Properties. Enter 192.168.10.1 for the IP address, and 255.255.255.0 for the Subnet mask. The settings should look like this:



        enter image description here



        Assign a Static IP Address in Guest VM



        The final step is to assign a static IP address in the guest VM.



        Unfortunately, Vagrant does not (as of v2.2.1) support static IP configuration (see: https://github.com/hashicorp/vagrant/issues/8384 ), so this static IP cannot be assigned prior to provisioning the VM.



        Until Vagrant supports this capability, one can simply provision the VM normally and edit the network configuration subsequently.



        The process for setting a static IP varies per guest OS, but in Ubuntu 18.04 LTS, for example, it's as simple as editing /etc/netplan/01-netcfg.yaml to include values that match the virtual switch configuration from above (the spaces must be exact!):



        network:
        version: 2
        ethernets:
        eth0:
        dhcp4: no
        addresses: [192.168.10.10/24]
        gateway4: 192.168.10.1
        nameservers:
        addresses: [8.8.8.8,8.8.4.4]


        After saving the file, apply the changes with:



        $ sudo netplan apply


        The VM should reflect the static IP immediately, which can be confirmed with ifconfig:



        $ sudo ifconfig
        eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
        inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
        inet6 fe80::215:5dff:fe38:12a prefixlen 64 scopeid 0x20<link>
        ether 00:15:5d:38:01:2a txqueuelen 1000 (Ethernet)
        ...


        The host can now ping the guest at 192.168.10.10, and the guest can ping the host at 192.168.10.1.



        References:




        • https://www.veeam.com/blog/how-to-configure-hyper-v-virtual-switch.html

        • https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-04-bionic-beaver-linux#h6-2-1-ubuntu-server






        share|improve this answer












        The Asker, and anyone with a similar use-case, is likely operating on a workstation (not Windows Server edition), for local development purposes, in which case a relatively simple solution exists.



        Create the Switch



        In Hyper-V Manager, create a new Virtual Switch, under Actions panel -> Virtual Switch Manager... -> Create Virtual Switch. Assuming the VM should be able to connect to the Internet, choose the External switch type.



        On the next screen, give the switch a name, such as internet-enabled, and choose the physical network interface that is connected to the Internet.



        The resultant switch should look something like this:



        enter image description here



        Hard-Code the Switch's IP Address (Gateway for the VM)



        Locate the network adapter that is associated with the new switch, i.e., under Control Panel -> Network and Internet -> Network Connections; its name will reflect the name given in the previous step, e.g., vEthernet (internet-enabled). Right-click the adapter and choose Properties.



        Next, click Internet Protocol Version 4 (TCP/IPv4) and click Properties. Enter 192.168.10.1 for the IP address, and 255.255.255.0 for the Subnet mask. The settings should look like this:



        enter image description here



        Assign a Static IP Address in Guest VM



        The final step is to assign a static IP address in the guest VM.



        Unfortunately, Vagrant does not (as of v2.2.1) support static IP configuration (see: https://github.com/hashicorp/vagrant/issues/8384 ), so this static IP cannot be assigned prior to provisioning the VM.



        Until Vagrant supports this capability, one can simply provision the VM normally and edit the network configuration subsequently.



        The process for setting a static IP varies per guest OS, but in Ubuntu 18.04 LTS, for example, it's as simple as editing /etc/netplan/01-netcfg.yaml to include values that match the virtual switch configuration from above (the spaces must be exact!):



        network:
        version: 2
        ethernets:
        eth0:
        dhcp4: no
        addresses: [192.168.10.10/24]
        gateway4: 192.168.10.1
        nameservers:
        addresses: [8.8.8.8,8.8.4.4]


        After saving the file, apply the changes with:



        $ sudo netplan apply


        The VM should reflect the static IP immediately, which can be confirmed with ifconfig:



        $ sudo ifconfig
        eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
        inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
        inet6 fe80::215:5dff:fe38:12a prefixlen 64 scopeid 0x20<link>
        ether 00:15:5d:38:01:2a txqueuelen 1000 (Ethernet)
        ...


        The host can now ping the guest at 192.168.10.10, and the guest can ping the host at 192.168.10.1.



        References:




        • https://www.veeam.com/blog/how-to-configure-hyper-v-virtual-switch.html

        • https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-04-bionic-beaver-linux#h6-2-1-ubuntu-server







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 29 at 22:05









        Ben Johnson

        62678




        62678






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1354658%2fhyperv-static-ip-with-vagrant%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Probability when a professor distributes a quiz and homework assignment to a class of n students.

            Aardman Animations

            Are they similar matrix