Skip to content

Commit 050e66a

Browse files
Separated names of docker VLAN network and routing interface
1 parent d975947 commit 050e66a

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

Enable-host-to-container-networking.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
#Change these variables!
44
NIC_NAME="eth0"
5-
DOCKERNETWORK_NAME="dockervlan"
5+
DOCKER_ROUTING_INTERFACE_NAME="dockerrouteif"
66
DOCKERNETWORK_IP_ADDRESS="192.168.0.249/32"
77
DOCKERNETWORK_IP_RANGE="192.168.0.64/26"
88

99
sleep 15 #Do not rush things if executing during boot. This line is not mandatory and can be removed.
1010

1111

12-
ip link add ${DOCKERNETWORK_NAME} link ${NIC_NAME}type macvlan mode bridge ; ip addr add ${DOCKERNETWORK_IP_ADDRESS} dev ${DOCKERNETWORK_NAME} ; ip link set ${DOCKERNETWORK_NAME} up
13-
ip route add ${DOCKERNETWORK_IP_RANGE} dev ${DOCKERNETWORK_NAME}
12+
ip link add ${DOCKER_ROUTING_INTERFACE_NAME} link ${NIC_NAME}type macvlan mode bridge ; ip addr add ${DOCKERNETWORK_IP_ADDRESS} dev ${DOCKER_ROUTING_INTERFACE_NAME} ; ip link set ${DOCKER_ROUTING_INTERFACE_NAME} up
13+
ip route add ${DOCKERNETWORK_IP_RANGE} dev ${DOCKER_ROUTING_INTERFACE_NAME}

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ You can reach the container with custom defined IP address from any host on the
1010
Check the **Enable-host-to-container-networking.sh** script file or manual steps defined.
1111
For making container accessible within the same host - one needs to create ethernet interface and route the containers used IP address (or range) trough the new interface:
1212

13-
* Create new interface (Interface name is *dockervlan*, and *eth0* is the host interface):
14-
`ip link add dockervlan link eth0 type macvlan mode bridge`
13+
* Create new interface (Interface name is *dockerrouteif*, and *eth0* is the host interface):
14+
`ip link add dockerrouteif link eth0 type macvlan mode bridge`
1515

1616
* Then assign IP address to that interface (Imagine it as a gateway - just like a router works but without NAT). In this example I used 192.168.0.249:
17-
`ip addr add 192.168.0.249/32 dev dockervlan`
17+
`ip addr add 192.168.0.249/32 dev dockerrouteif`
1818
**NOTE: Ensure defined IP address is not used by another host/device/container though!**
1919
**NOTE: If you check logs i.e. host is using DNS server which is in a container, any requests made from the host will be seen as coming from this IP**
2020

2121
* Bring up that interface:
22-
`ip link set dockervlan up`
22+
`ip link set dockerrouteif up`
2323

2424
* And finally define a range which should be routed trough that iterface:
25-
`ip route add 192.168.0.64/26 dev dockervlan`
25+
`ip route add 192.168.0.64/26 dev dockerrouteif`
2626

2727
Lastly, bring up the docker compose file:
2828
`docker-compose up -d`
@@ -33,6 +33,7 @@ Host interface name: `eth0`
3333
Gateway: `192.168.0.1`
3434
Subnet: `192.168.0.0/24`
3535
Host IP: `192.168.0.2`
36-
Interface name trough which traffic is routed: `dockervlan`
36+
Interface name trough which traffic is routed: `dockerrouteif`
37+
Docker VLAN name: `Dockervlan`
3738
Dockervlan interface IP: `192.168.0.249`
3839
dockervlan routed IP range: `192.168.0.64/26`

ansible/playbooks/playbook.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
username: "user" #home dir username i.e. /home/user/
55
nic_name: "eth0" #Host nic interface name
66
dockernetwork_name: "dockervlan"
7+
docker_routing_interface_name: "dockerrouteif"
78
network_subnet: "192.168.0.0/24"
89
network_ip_range: "192.168.0.64/26"
910
network_gateway: "192.168.0.1"

ansible/playbooks/roles/docker-compose-macvlan/templates/Enable-host-to-container-networking.sh.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
sleep 15 #Do not rush things if executing during boot. This line is not mandatory and can be removed.
44

5-
ip link add {{ dockernetwork_name }} link {{ nic_name }} type macvlan mode bridge ; ip addr add {{ dockernetwork_ip_address }} dev {{ dockernetwork_name }} ; ip link set {{ dockernetwork_name }} up
6-
ip route add {{ dockernetwork_ip_range }} dev {{ dockernetwork_name }}
5+
ip link add {{ docker_routing_interface_name }} link {{ nic_name }} type macvlan mode bridge ; ip addr add {{ dockernetwork_ip_address }} dev {{ docker_routing_interface_name }} ; ip link set {{ docker_routing_interface_name }} up
6+
ip route add {{ dockernetwork_ip_range }} dev {{ docker_routing_interface_name }}

0 commit comments

Comments
 (0)