# VLANs do not survive reboot [solved]

## n3bul4

Hey guys,

I have one question.

I successfully managed to create a VLAN in the following way.

```

# vconfig add eth0 10

# ifconfig eth0.10 192.168.0.2 netmask 255.255.255.0

# route add default gw 192.168.0.1

```

My problem is that when I reboot the machine, the eth0.10 VLAN device is not created.

This is what I have in my /etc/conf.d/net file.

```

config_eth0="null"

vlans_eth0="10"

config_eth0_10="192.168.0.2 netmask 255.255.255.0"

routes_eth0_10="default via 192.168.0.1"

```

I also tried to set the module to "iproute2" but still the same problem.

Any help would be appreciated.

RegardsLast edited by n3bul4 on Sun Mar 01, 2015 11:09 am; edited 1 time in total

----------

## n3bul4

Nobody an idea?

----------

## Hu

What output is printed at boot when the interface is supposed to come up?

Your manual configuration was done using vconfig, which is no longer supported by netifrc.  Can you hand configure it using iproute2?

----------

## n3bul4

Thanks for your hint!

I could actually solve it the following way:

```

#/etc/conf.d/net

config_eth0="null"

ip link add link eth0 name eth0.11 type vlan id 11

config_eth0_11="192.168.1.3 netmask 255.255.255.0"

routes_eth0_11="default via 192.168.1.1"

```

Followed by:

```

ln -s /etc/init.d/net.lo /etc/init.d/net.eth0.11

rc-update add net.eth0.11 default

```

The problem was, that at boot time it simply told me that the device eth0.11 was not not found.

I didn't know that I can use iproute2 commands directly in the /etc/conf.d/net file.

Regards

----------

## szatox

you do know that line

ip link add link eth0 name eth0.11 type vlan id 11 

will be executed every time you call ANY of your net* scripts, don't you?

Netifrc uses modules translating it's internal comands to a form tools actually configuring network can understand. Vconfig is not supporte = there is no module for it. You can try iproute module instead as it's also capable of doing what you want.

Otherwise, at least encapsulate this line in an pre-up function declaration or something like that so it will only be called when you start the interface. And you might also need post-down to clean up afterwards. All that stuff a module normally handles for you.

----------

## n3bul4

Hey szatox,

yeah I realized that the ip command is executed every time a network device is started / stopped.

It actually just gives me a warning, so I was not too much worried about that.

But you are totally right, that it is not a clean solution.

I actually tried a lot of different configurations including to define the iproute2 module like this:

```

modules="iproute2"

```

The problem was that it was always claiming about not finding the device (net.eth0.11 in this case).

So the device was not created by ip command.

It somehow seems, that iproute2 module doesn't recognize the configuration.

What I used was the following:

```

config_eth0="null"

vlans_eth0="11"

config_eth0_11="192.168.0.2 netmask 255.255.255.0"

routes_eth0_11="default via 192.168.0.1"

```

but it seems that iproute2 is ignoring the vlans_eth0 line and the ones that follow.

As I said it simply claims about not finding the device.

Anyway, thanks for your input. I wasn't aware about the pre-up / post-down functionality.

So for now I solved it the following way:

```

preup(){

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

                ip link add link eth0 name ${IFACE} type vlan id 10

        fi

}

postdown(){

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

                ip link del ${IFACE}

        fi

}

```

Which works perfectly and doesn't give me any warnings any more.

I am really wondering about how this can be achieved without those two functions.

Do you have an example configuration for using module iproute2 without the need of those functions?

Regards

----------

## n3bul4

OK I actually figured it out on my own   :Smile: 

This is a working /etc/conf.d/net

```

modules="iproute2"

config_eth0="null"

vlans_eth0="11"

config_eth0_11="192.168.0.2 netmask 255.255.255.0"

routes_eth0_11="default via 192.168.0.1"

vlan_11_name="vlan11"

```

My mistake was that I actually thought that I have to add a net.eth0.10 init script.

```

ln -s /etc/init.d/net.lo /etc/init.d/net.eth0.11

rc-update add net.eth0.11

```

This is actually not needed / wrong, so I simply removed the init script and now everything is working as expected without the need of any pre-up and post-down functions.

```

rc-update del net.eth0.11

rm /etc/init.d/net.eth0.11

```

Thanks for your help!

Regards

----------

