How to fetch MAC address of remote machine from docker container
If you are able to ping given remote machine from docker container but unable to get the mac address that means either
- MAC address is not available in the routing table
- The host network interface is not available inside a Docker container.
For #1 case you can ping the machine which can add MAC address of that machine in the routing table.
For #2 case you can add a host network interface to Docker container.
eg. docker run --network="host" -it network_service:latest
How to get the IP address of the docker host from inside a docker container
/sbin/ip route|awk '/default/ { print $3 }'
As @MichaelNeale noticed, there is no sense to use this method in Dockerfile
(except when we need this IP during build time only), because this IP will be hardcoded during build time.
How does the Docker assign MAC addresses to containers?
Docker start assigning always the same mac 02:42:ac:11:00:02
for the first container and then is increasing by one each mac for each different container.
Not sure why they are using that mac address. It seems 02:42:ac
doesn't match any real vendor in oui databases. Look at the official documentation about this. They say:
The MAC address is generated using the IP address allocated to the container to avoid ARP collisions, using a range from 02:42:ac:11:00:00 to 02:42:ac:11:ff:ff
Anyway, you can set any mac address on container generation using --mac-address
parameter on the docker run command. For example doing a command like this docker run -ti --mac-address 00:00:00:00:00:11 ubuntu:trusty
Hope it helps.
Related Topics
Start Tomcat from Eclipse in Port 80 in Ubuntu with Authbind
Creating Filename_$(Date %Y-%M-%D) from Systemd Bash Inline Script
Counting Lines Starting with a Certain Word
Nohup Create New Files Nohup.Out by Day
The Behavior When a Gnu Make Phony Target Happens to Be The Same as a Directory Name
Arduino Upload Error "Stk500_Recv(): Programmer Is Not Responding" in Fedora
Possible to Assign a New Ip Address on Every Http Request
How to Extract Value from JSON Contained in a Variable Using Jq in Bash
How to Two Mmap on Same /Dev File
Git Wont Reset File Permissions Over Cifs Mount
Command Execution with Nohup in Background
Timeouting a While Loop in Linux Shell Script
Using Sftp to Transfer Images from HTML Form to Remote Linux Server Using Perl/Cgi.Pm