Skip to content

Instantly share code, notes, and snippets.

@b2un0
Last active December 12, 2023 20:43
Show Gist options
  • Save b2un0/08a51d3297178fcdb6829686489cad6f to your computer and use it in GitHub Desktop.
Save b2un0/08a51d3297178fcdb6829686489cad6f to your computer and use it in GitHub Desktop.

features

  • working macvlan with docker
  • systemd network devices
  • each container can reach the whole nework (full routing)
  • docker-compose.yml example with static ipv4 on macvlan
  • if no ip defined, container get a ip within 192.168.155.192/27

macvlan

docker network create \
                    -d macvlan \
                    -o parent=eth0 \
                    --subnet=192.168.155.0/24 \
                    --gateway=192.168.155.0 \
                    --ip-range 192.168.155.192/27 \
                    macvlan # the name
version: '3.5'
services:
whoami:
image: containous/whoami:latest
restart: unless-stopped
container_name: whoami
hostname: whoami
networks:
macvlan:
ipv4_address: 192.168.155.210
networks:
macvlan:
external: true
; /etc/systemd/network/eth0.network
[Match]
Name=eth0
[Network]
MACVLAN=vbridge
DHCP=yes
MulticastDNS=yes
; /etc/systemd/network/vbridge.netdev
[NetDev]
Name=vbridge
Kind=macvlan
[MACVLAN]
Mode=bridge
; /etc/systemd/network/vbridge.network
[Match]
Name=vbridge
[Network]
IPForward=yes
LinkLocalAddressing=no
Address=192.168.155.223/32
Gateway=192.168.155.1
DNS=192.168.155.1
[Route]
Destination=192.168.155.0/24
Gateway=192.168.155.1
Scope=global
GatewayOnlink=yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment