windows icon indicating copy to clipboard operation
windows copied to clipboard

[Question]: How do I specify an IP to Windows?

Open Southseast opened this issue 9 months ago • 4 comments

Is your question not already answered in the FAQ?

  • [X] I made sure the question is not listed in the FAQ.

Is this a general question and not a technical issue?

  • [X] I am sure my question is not about a technical issue.

Question

This is a similar question in the FAQ, but I want to specify an IP to Windows instead of DHCP. What should I do?

Southseast avatar May 16 '24 06:05 Southseast

You can just use macvlan mode with DHCP=N. This will allow you to choose any IP you like, but the traffic will still be tunneled to the VM (this means Windows does not know what outside IP it has).

If for some reason you also really need Windows to know its own IP (normally there are no reasons for that), then you must set DHCP=Y. But the name "DHCP" for the setting is a bit misleading, because what it really does is to create a macvtap interface. And you will also need that interface if you want to assign a static IP on the network.

So in that case set DHCP=Y, boot the container and then go inside the Window Control Panel and set a static IP for the network adaptor so that it ignores the DHCP server.

kroese avatar May 16 '24 10:05 kroese

When I use macvlan mode with DHCP=Y and enter ipconfig on the cmd, it is shown as follows.

C:\Users\Docker\Desktop>ipconfig

Windows IP Configuration


Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::4192:558f:7082:a7b1%12
   IPv4 Address. . . . . . . . . . . : 172.22.108.102
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 172.22.108.254

Tunnel adapter isatap.{167133D2-1830-4B68-A65C-1A019F1A5D7B}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

So I use netsh interface ip set address "Ethernet" static 172.22.108.75 255.255.255.0 172.22.108.254 to modify the network configuration. But now it shows "no internet access" and I can't connect Windows via RDP.

Southseast avatar May 16 '24 11:05 Southseast

And this is my docker-compose.yml

version: "3"
services:
  windows:
    image: dockurr/windows
    container_name: windows
    environment:
      DHCP: "Y"
    volumes:
      - ./2012.iso:/storage/custom.iso
      - ./storage:/storage
    devices:
      - /dev/kvm
      - /dev/vhost-net
    device_cgroup_rules:
      - 'c *:* rwm'
    cap_add:
      - NET_ADMIN
    stop_grace_period: 2m
    restart: on-failure
    networks:
      vlan:
        ipv4_address: 172.22.108.98
        
networks:
  vlan:
    driver: macvlan
    driver_opts:
      parent: ens33
    ipam:
      config:
        - subnet: "172.22.108.0/24"
          ip_range: "172.22.108.0/24"
          gateway: "172.22.108.254"

Southseast avatar May 16 '24 11:05 Southseast

I am not sure why.. I use the same network code in another project ( https://github.com/vdsm/virtual-dsm ) and I know for sure that it works there to set a static IP. Because macvtap provides a direct connection to the network, it should not matter at all if you use dynamic or static IP. I never tested it with this container, I just expected it would work for Windows too since I cannot think of any reason why it would work with DSM (Linux) and not with Windows.

For a quick solution, wouldnt it be an alternative for you to just configure your DHCP server to give Windows the IP you want? That would solve your problem also.

kroese avatar May 16 '24 15:05 kroese

Sorry, it's my problem. It's unfortunately I tried setting up two different static IPs, and they were both occupied repeatedly in vlan. Now it work.

Southseast avatar May 17 '24 09:05 Southseast