Closed chrislangston closed 5 years ago
Hey Chris,
Thanks for the lab feedback and glad you found it useful. The hosts file entry is to let the 'leaf' device resolve the name of the edge gateway server to an IP. Even through, in the case of the labs, they happen to both be on the same physical VM, because we use a hostname (config.yaml) that is different than the machine name, we have to tell the leaf device how to resolve it.
Essentially, we don't have a DNS server handy and so we don't assume one, so we 'fake it' with the hosts file entry. Technically, we could have given the VM a DNS entry in the Azure portal and gone that way, but then the leaf device, which is on the same VM, would go through the external interface of the VM and we would have had to put stuff in the labs to deal with the Azure network security groups, opening ports, etc. Thus the use of 127.0.0.1 as the IP for mygateway.local as well, since it's all on one box for the labs.
So, for your questions above... #1 - they are the same box, so 'yes' (but if they were different, it would need to be the leaf device) and #2 if you give your VM a 'real' DNS name, you don't need to add a hosts file entry at all, as Azure provides the real DNS services to resolve the name.
However, one note to remember: whatever name your leaf devices use to connect to IoT Edge, i.e. the name use you use as the GatewayHostName in your connection string, that MUST be the name that you use as your hostname in config.yaml. So, if your leaf devices are going to use the VMs DNS name (i.e. myvm.eastus.cloudapp.azure.com) to connect to IoT Edge, you have to use that same name as your hosts file in config.yaml (and restart iotedge).
does that make sense?
if you need more info about the relationship between the hostname in config.yaml and the gatewayhostname parameter, and the certificates involved, check out this article (which I also wrote :-)) https://docs.microsoft.com/en-us/azure/iot-edge/iot-edge-certs
Hi @stevebus.
I'm following through your Hands on Lab (this tutorial should be the reference for the main IoT Edge as a Transparent Gateway documentation as it's so good) and I'm not clear what adding the entry to the /etc/hosts is for?
https://github.com/AzureIoTGBB/azure-iot-edge-hol-linux/tree/master/module1#additional-miscellaneous-setup
The docs state: 'There are a few final steps needed to set up our specific lab scenario. We are using our Edge device as a gateway, so we need a) our IoT Device to be able to find it and b) to have valid certificates so the IoT Device will open a successful TLS connection to the Edge
Add a host file entry for our Edge device -- this will let our "IoT Device" resolve and find our Edge gateway. To do this:
run 'sudo nano /etc/hosts' add a row at the bottom with the following 127.0.0.1 mygateway.local save and close the file (CTRL-O, CTRL-X) confirm you can successfully "ping mygateway.local" '
In my case I'm going to have maybe 50 Android "leaf" downstream devices that connect through IoT Edge as a transparent gateway.
Questions:
Are these instructions stating that we should add this entry to the "leaf" downstream device for their /etc/hosts entry or for adding this to the IoT Edge Gateway Device?
Why the 127.0.0.1 mygateway.local? I will give the IoT Edge Gateway Device as DNS name in the Azure Portal. Should I enter the DNS name here or what you have indicated 'mygateway.local'?
Thanks,
Chris