DHCP on Docker
DHCP (Dynamic Host Configuration Protocol) helps us to address dynamically our hosts on the network. In fact, when a Host is configured to get its IP address dynamically, it will broadcast a DHCP REQUEST on the network searching for a DHCP server. DHCP server has to be on the same broadcast domain as the CLIENTS since routers do not forward broadcast packets.
- create macvlan network:
- docker network create -d macvlan -o parent=enp3s0 --subnet 172.16.3.0/24 --gateway 172.16.3.4 --aux-address 'host=172.16.3.250' mynet
- add macvlan-aux to the docker-host (to ping directly from docker-host) - including ip link, route etc:
- ip link add mynet-aux link enp3s0 type macvlan mode bridge
- ip addr add 172.16.3.250/32 dev mynet-aux
- run container with macvlan driver (assign static IP) and run /bin/bash:
- docker run --name='ctr0' --hostname='ctr0' --net=mynet --ip=172.16.3.249 -it centos /bin/bash
- Ping container IP from the Docker-host:
- ping 172.16.3.249
- on container (all of these can be done with docker-file):
- yum install net-tools -y
- yum install dhcp -y
- 1.1.6.1 is DHCP relay IP address
- dhcpd listens *only* on interfaces for which it finds subnet declaration in dhcpd.conf
# this server is primary and thus - authorative server on that network
authoritative;
subnet 172.16.3.0 netmask 255.255.255.0 {
range 172.16.3.1 172.16.3.3;
option routers 172.16.3.4;
option domain-name-servers 172.16.3.6;
}
subnet 172.16.3.0 netmask 255.255.255.0 {
range 172.16.3.1 172.16.3.3;
option routers 172.16.3.4;
option domain-name-servers 172.16.3.6;
}
to kill process on container:
top > k > PID > Enter
No comments:
Post a Comment