LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2021, 01:21 AM   #1
kevindd992002
Member
 
Registered: May 2019
Posts: 58

Rep: Reputation: Disabled
Correct way of using macvlan in Debian 10


So I have these in my /etc/network/interfaces:

# The macvlan network subinterface
auto mac0
iface mac0 inet manual
pre-up ip link add mac0 link enp1s0 type macvlan mode bridge
pre-up ip addr add 192.168.20.110/32 dev mac0
post-up ip route add 192.168.20.96/28 dev mac0
post-down ip link del mac0 link enp1s0 type macvlan mode bridge

I'm doing this because I use macvlan in some of my docker containers for them to have their own IP's (in the same subnet) while on a single physical host. However, without the mac0 interface in the host, it won't reach the docker containers. This is explained here.

Everything is working well except that sometimes packets coming from the same physical host use the macvlan interface IP (192.168.20.110) instead of its actual enp1s0 interface IP (192.168.20.22). That makes sense because it's sharing the same interface and has essentially two IP's with the same MAC address.

However, without actually assigning an IP address on the mac0 interface, sometimes my whole networks gets bogged down when traffic from one of the docker containers using the docker macvlan network gets initiated.

So my question is how do I stop the host from using the mac0 interface IP as source IP when it is initiating traffic out the physical network?

Last edited by kevindd992002; 03-04-2021 at 02:15 AM.
 
Old 03-05-2021, 10:20 PM   #2
kevindd992002
Member
 
Registered: May 2019
Posts: 58

Original Poster
Rep: Reputation: Disabled
Anybody?
 
Old 03-15-2021, 09:10 AM   #3
kevindd992002
Member
 
Registered: May 2019
Posts: 58

Original Poster
Rep: Reputation: Disabled
BUMP!
 
Old 04-17-2021, 10:29 AM   #4
kevindd992002
Member
 
Registered: May 2019
Posts: 58

Original Poster
Rep: Reputation: Disabled
BUMP!
 
Old 07-28-2023, 03:05 PM   #5
oldium
LQ Newbie
 
Registered: Jul 2023
Posts: 3

Rep: Reputation: 0
Almost good

Hi, I found your post really inspiring, thanks. I used little bit modified version - it is necessary to just bring the interface up before the Debian configures it for you. Something like:

Code:
auto mac0
iface mac0 inet static
    address 192.168.20.96/28
    pre-up ip link add mac0 link enp1s0 type macvlan mode bridge
    post-down ip link del mac0
In my case I omit the auto mac0 line and bound it to real interface up and down. So my actual config looks like (I enhanced enp1s0 definition by post-up and pre-down scripts to handle additional mac0 interface):

Code:
allow-hotplug enp1s0
iface enp1s0 inet static   
    post-up ifup mac0    
    pre-down ifdown mac0 
    ...

iface mac0 inet static
    ...

Last edited by oldium; 07-28-2023 at 03:09 PM.
 
Old 07-28-2023, 03:08 PM   #6
oldium
LQ Newbie
 
Registered: Jul 2023
Posts: 3

Rep: Reputation: 0
deleted

Last edited by oldium; 07-28-2023 at 03:09 PM.
 
Old 10-16-2023, 08:20 AM   #7
oldium
LQ Newbie
 
Registered: Jul 2023
Posts: 3

Rep: Reputation: 0
I was able to share the main network interface with Docker. I used the following configuration:

Code:
allow-hotplug enp1s0

iface enp1s0 inet manual
    post-up ifup mac0
    pre-down ifdown mac0

iface mac0 inet static
    pre-up ip link add mac0 link enp1s0 type macvlan mode bridge
    post-down ip link del mac0
    address 192.168.1.100/24
    gateway 192.168.1.1
    ...
This uses randomly generated MAC address for mac0 interface, so if you want to have a fixed one, just add hwaddress aa:bb:cc:dd:ee:ff to the mac0 interface parameters. You can configure the mac0 interface as usual, no need to have it static (see man interfaces).

I had to restart the system to get this working (/etc/init.d/networking restart was not enough).

And in Docker Compose (all IP addresses are just examples), use:

Code:
services:
  my-service:
    ...
    dns:
      - "8.8.8.8"
    networks:
      servicenet:
        ipv4_address: "192.168.1.101"

networks:
  servicenet:
    driver: macvlan
      parent: enp1s0
      macvlan_mode: bridge
    ipam:
      config:
        - subnet: "192.168.1.0/24"
        - gateway: "192.168.1.1"

Last edited by oldium; 10-16-2023 at 08:22 AM.
 
Old 01-07-2024, 06:33 PM   #8
jstrot
LQ Newbie
 
Registered: Jan 2024
Posts: 1

Rep: Reputation: 0
Works! + systemd-networkd

Thanks for all the comments in this thread. It is the solution for me with a LAN of 172.16.0.0/16 and a docker macvlan subnet of 172.16.100.0/24. Both other machines on the network and the host are able to access the services in this macvlan network.

On one machine I'm using a Debian style /etc/network/interfaces setup like @oldium (except I don't set the gateway as I don't want this to be a default route on the host).

On another machine I'm using the systemd-networkd style setup like this:

/etc/systemd/network/20-wired.network
Code:
[Match]
Name=eth0

[Network]
DHCP=yes
MACVLAN=br-macvlan
/etc/systemd/network/40-br-macvlan.netdev
Code:
[NetDev]
Name=br-macvlan
Kind=macvlan

[MACVLAN]
Mode=bridge
/etc/systemd/network/40-br-macvlan.network
Code:
[Match]
Name=br-macvlan

[Network]
IPForward=yes
Address=172.16.100.1/24
Cheers!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to make macvlan work with bridge? Brian Lu Linux - Networking 3 09-05-2019 02:40 PM
LXC in macvlan mode fails to ping gateway andrew036 Linux - Virtualization and Cloud 0 06-23-2014 04:44 AM
macvlan on host, macvtap guest, routing via host gives error nikunjmaster Linux - Virtualization and Cloud 0 01-01-2014 06:44 PM
[SOLVED] Assigning dynamic IP addresses on aliases using macvlan? magpiesally Linux - Networking 5 07-30-2013 02:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration