# macvlan support in init scripts

## totatis

Hi,

I've configured my box to use macvlans, which work great. However, I'd like to make it static, thus declaring them in init scripts. I haven't been able to find how to declare them in /etc/conf.d/net, the net.example file doesn't mention them. Is there a way to declare macvlans in standard /etc/conf.d/net ? If so, how ? I've searched the forums but top no avail.

Thanks.

----------

## gerdesj

 *totatis wrote:*   

> Hi,
> 
> I've configured my box to use macvlans, which work great. However, I'd like to make it static, thus declaring them in init scripts. I haven't been able to find how to declare them in /etc/conf.d/net, the net.example file doesn't mention them. Is there a way to declare macvlans in standard /etc/conf.d/net ? If so, how ? I've searched the forums but top no avail.
> 
> Thanks.

 

I've just had a quick look around (never heard of macvlans before) but it seems to allow you to create fake additional nics from a base one each with its own mac address.  As you say there seems to be no direct support in net.

However assuming that you want to do this with eth0, simply put in a postup and postdown script, put these in net:

```

postup() {

    

    if [ "${IFACE}" = "eth0" ]; then

       einfo " ${IFACE} up"

    fi

    

    return 0

}

postdown() {

    if [ "${IFACE}" = "eth0" ]; then

      einfo " ${IFACE} down"

    fi

    return 0

}

```

Put your commands in where I've put einfo.  Something like:

ip link add link eth0 address xx:xx:xx:xx:xx:xx macvlan0 type macvlan

Now I have no idea if you could get away with making a normal init.d symlink for this thing and then use net to configure it.  Put in a dependency on eth0 though! If not just put the additional ip commands in the up/down scripts.

Make sure the module gets loaded as well (/etc/conf.d/modules)

Cheers

Jon

----------

## totatis

Thanks for your reply !

Actually, it's the way i've done it at the moment : putting myself some bit of scripts. I was wondering if there was an "official" ie direct way of doing it in net confs.

As you summed up, i've used macvlan to create fake nics on a single physical one, each with its own mac. One good thing about macvlan is that it works as expected with respect to iptables ou iproute2.

----------

## gerdesj

 *totatis wrote:*   

> Thanks for your reply !
> 
> Actually, it's the way i've done it at the moment : putting myself some bit of scripts. I was wondering if there was an "official" ie direct way of doing it in net confs.
> 
> As you summed up, i've used macvlan to create fake nics on a single physical one, each with its own mac. One good thing about macvlan is that it works as expected with respect to iptables ou iproute2.

 

And thank you for introducing me to it.  

It looks ideal for proper firewalling with only one NIC and a ADSL router that can't do 802.1Q  :Cool: 

Perhaps I will submit a feature request bug against OpenRC ...

Cheers

Jon

----------

## Gregoire

 *totatis wrote:*   

> Hi,
> 
> I've configured my box to use macvlans, which work great. However, I'd like to make it static, thus declaring them in init scripts. I haven't been able to find how to declare them in /etc/conf.d/net, the net.example file doesn't mention them. Is there a way to declare macvlans in standard /etc/conf.d/net ? If so, how ? I've searched the forums but top no avail.
> 
> Thanks.

 

Could you be kind enough to share how you did it ?

I am trying to do something similar whithout much success : dhcp with macvlan ?

Thank you very much.

----------

