Search code examples
dockernmapdocker-network

DOCKER: Linux Container on Windows 10, how to use nmap to scan device's mac address


I am trying to setup the docker which can successfully scan the subnet device's mac address by using nmap. And I've spent 3 days to figure out how to do it but still failed.

For example:

  • The host IP: 10.19.201.123
  • The device IP: 10.19.201.101

I've setup docker container which can ping 10.19.201.123 and 10.19.201.101 both successfully. But when I use nmap to scan mac address from docker container, I got below:

~$sudo nmap -sP 10.19.201.101
 Starting Nmap 7.01 ( https://nmap.org ) at 2018-05-29 08:57 UTC
 Nmap scan report for 10.19.201.101
 Host is up (0.00088s latency).
 Nmap done: 1 IP address (1 host up) scanned in 0.39 seconds

However, if I use nmap to scan mac address from VM (10.19.201.100), I got:

~$sudo nmap -sP 10.19.201.101
 Starting Nmap 7.01 ( https://nmap.org ) at 2018-05-29 17:16 CST
 Nmap scan report for 10.19.201.101
 Host is up (0.00020s latency).
 MAC Address: 0F:01:H5:W3:0G:J5(ICP Electronics)
 Nmap done: 1 IP address (1 host up) scanned in 0.32 seconds

PLEASE, who can help or give prompts of how to do it?


Solution

  • For who is still struggling with this issue, I've figured out how to do it on Windows 10. The solution is to make the container running on the same LAN as your local host, so nmap can scan the LAN device successfully. Below is the way to make your docker container run on the host LAN.

    Windows 10 HOME

    Change the virtual box setting

    1. Stop VM first by administrator docker-machine stop default
    2. Open Virtual Box
    3. Select default VM and click Settings
    4. Go to Network page, and enable new Network Adapter on Adapter 3 (DO NOT CHANGE Adapter 1 & 2)
    5. Attached Adapter 3 to bridged Adapter with your physical network and click OK
    6. Start VM by administrator docker-machine start default
    7. Open Docker Quickstart Terminal to run container, the new container should be run on the LAN now.

    Windows 10 PROFESSIONAL/ENTERPRISE

    Create vSwitch with physical network adapter

    1. Open Hyper-V Manager
    2. Action list- > Open Virtual Switch Manager
    3. Create new virtual switch -> select Type: External
    4. Assign your physical network adapter to the vSwitch
    5. Check "Allow management operating system to share this network adapter" and apply change
    6. Go to Control Panel\All Control Panel Items\Network Connections.
    7. Check the vEthernet you just created, and make sure the IPV4 setting is correct. (sometimes the dhcp setting will be empty and you need to reset again here)
    8. Go back to Hyper-V Manager, and go into Setting page of MobyLinuxVM (ensure it's shut down, if it's not, Quit Docker)
    9. Add Hardware > Network Adapter, select the vSwitch you just created and apply change

    Modify Docker source code

    1. Find the MobyLinux creation file: MobyLinux.ps1 (normally it's located at: X:\Program Files\Docker\Docker\resources)
    2. Edit the file, and find the function: function New-MobyLinuxVM
    3. Find below line in the function: $vmNetAdapter = $vm | Hyper-V\Get-VMNetworkAdapter
    4. Update it to: $vmNetAdapter = $vm | Hyper-V\Get-VMNetworkAdapter | Select-Object -First 1
    5. Save file by administrator
    6. Restart Docker, and the container should run on the LAN now.