# Using multiple vlan on one interface

## Raze

hi folks,

i want to use multiple IPs from different class c networks in vlans one nic.

Switch is configured as trunk, "CONFIG_VLAN_8021Q=y" is set, net-misc/vconfig iss merged and one IP also works. I guess the problem iss the gateway for the second vlan.

Heres my config, which works for one of the vlans:

```

config_eth0=('null')

vlans_eth0='58 30'

vconfig_eth0=( 'set_name_type VLAN_PLUS_VID_NO_PAD' )

config_vlan58=('87.xxx.xxx.10 netmask 255.255.255.128 brd 87.xxx.xxx.xxx')

routes_vlan58=('default via 87.xxx.xxx.129')

config_vlan30=('87.xxx.xxx.20 netmask 255.255.255.192 brd 87.xxx.xxx.xxx')

routes_vlan30=('default via 87.xxx.xxx.65')

```

Ive also tried changing the metric of the vlans, but no change. Is there anything special about using multiple Clacc-C networks with different gateways on one nic in vlan configuration?

Edit:

Im using 2.6.28-hardened-r9 amd64 if this maybe relevant ..

----------

## nativemad

Hi, 

 *Quote:*   

> Is there anything special about using multiple Clacc-C networks with different gateways on one nic in vlan configuration?
> 
> 

 

it doesn't has to do with the vlans actually... It is generally a problem to have multible default-gateways! Either you have to set some routes to different destinations manually, or you need to use iproute2! http://lartc.org/howto/lartc.rpdb.multiple-links.html

I have the following, which sets the default to one nic and sets the necessary stuff to use the second also, if you bind something (ping -I for example) explicitly to that ip or to answers queries from connections.   :Wink: 

```
ip route flush table T1

ip route flush table T2

ip route flush table main

ip route add 192.168.10.0/24 dev eth1 src 192.168.10.3

ip route add 192.168.0.0/24 dev eth0 src 192.168.0.3

ip route add 192.168.10.0/24 dev eth1 src 192.168.10.3 table T2

ip route add default via 192.168.10.1 dev eth1 table T2

ip rule add from 192.168.10.3 table T2

ip route add 192.168.0.0/24 dev eth0 src 192.168.0.3 table T1

ip route add default via 192.168.0.1 dev eth0 table T1

ip rule add from 192.168.0.3 table T1

route add default gw 192.168.0.1

route add default gw 192.168.10.1

```

in /etc/iproute2/rt_tables i've added:

```
1       T1

2       T2

```

Hope that helps a bit!   :Razz: 

Cheers

----------

## Raze

That helps, thanks.

One more thing .. i want to use multiple IPs from different class C networks in one vlan, each with a different gateway.

ip route add default via aa.aa.aa.aa dev vlan30 table R2

and

ip route add default via bb.bb.bb.bb dev vlan30 table R2

doesnt work, it gets me

```
RTNETLINK answers: Invalid argument
```

If i only start one of the IPs it works fine. 

```
config_vlan30=(         'aa.aa.aa.aa netmask 255.255.255.192 brd aa.aa.aa.255')
```

works

```
config_vlan30=(         'aa.aa.aa.aa netmask 255.255.255.192 brd aa.aa.aa.255'

                       'bb.bb.bb.bb netmask 255.255.255.192 brd bb.bb.bb.255')
```

doesnt work.

any suggestions about this one?

----------

## nativemad

You should use different tables for the different subnets! 

Thats why the "rule add subnet table" rule is for in my example!  :Wink: 

Just replace my ethX entries with vlan30 and adjust the subnet-declarations in my example and you should be fine!  :Smile: 

Be aware, normal outgoing traffic will always use the first gateway if no explicit outgoing ip is given, unless you set weights and so on. (read lartc for more details)

----------

## Raze

Thats clear, but we got different class c networks with different gateways in one vlan.

it works fine as long as i use one ip from one vlan on one virtual interface. two wont work.

creating vlan31 as example and using the second ip from the vlan30 ( bb.bb.bb.bb ) doesnt work because the switchport is configured as trunk and the system decompress the ip paket. for sure im using different tables  :Wink: 

what i need is this:

```
# If you need more than one address, you can use something like this

# NOTE: ifconfig creates an aliased device for each extra IPv4 address

#       (eth0:1, eth0:2, etc)
```

one line later in the net.example

```
#       iproute2 does not do this as there is no need to
```

 :Sad: 

.. one step forward, two steps backwards   :Mad: 

Any more ideas how i can handle this?

Edit:

Even if i would use two nics, i cant configure a vlan two times on different nics.

```
*   Bringing up eth1                                                                                                                                  [ ok ]

 *   Adding VLAN 30 to eth1

 *   ERROR: trying to add VLAN #30 to IF -:eth1:-  error: File exists
```

----------

## nativemad

Hmm... i'm not sure if it isn't the same through /etc/conf.d/net and the commandline....  :Rolling Eyes: 

I have servers with about a hundred virtual IP's on it, started through a shell script.

I have a vlan named 3 with a normal nic on it

```
eth2.3    Link encap:Ethernet  HWaddr 00:0d:60:eb:48:42

          inet addr:10.0.0.99  Bcast:10.255.255.255  Mask:255.0.0.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:3698703 errors:0 dropped:0 overruns:0 frame:0

          TX packets:2328487 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:438921021 (418.5 MiB)  TX bytes:2136310325 (1.9 GiB)
```

and some more ip's (i just tested it with another subnet-class [eth2.3:99] than eth2.3 and it worked with my hp procurve switches)

```
eth2.3:92 Link encap:Ethernet  HWaddr 00:0d:60:eb:48:42

          inet addr:10.0.3.92  Bcast:10.255.255.255  Mask:255.0.0.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth2.3:93 Link encap:Ethernet  HWaddr 00:0d:60:eb:48:42

          inet addr:10.0.3.93  Bcast:10.255.255.255  Mask:255.0.0.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth2.3:99 Link encap:Ethernet  HWaddr 00:0d:60:eb:48:42

          inet addr:192.168.99.99  Bcast:192.168.99.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

```

i start them like

```
ifconfig eth2.3:99 192.168.99.99 netmask 255.255.255.0
```

But for the gateway declaration you will still need iproute2!

----------

## Raze

 *nativemad wrote:*   

> 
> 
> i start them like
> 
> ```
> ...

 

Didnt try that before because i would definitly prefer the solution via a config-file.

But that worked like a charm in combination with iproute.

Thanks a lot  :Cool: 

----------

