# Adding multiple IPs on a VLAN tagged interface in Linux?



## ToeClaws (Jan 13, 2010)

So here's the issue... I have a Linux system that has multiple VLANs on one physical interface, done via tagging in it's interfaces setup (there's around 30 of them).

What I need to do in a couple VLANs is create secondary IPs within the same VLAN/subnet.  I tried doing this via the method of creating sub-interfaces on a NIC, but it just seems to overwrite the first VLAN interface.  So how does (or can) one go about this?


----------



## ArielMT (Jan 13, 2010)

Which distro are you using?

I found a half-decent explanation of IP aliasing at http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch03_:_Linux_Networking

Red Hat way:
http://www.linuxhomenetworking.com/...working#Multiple_IP_Addresses_on_a_Single_NIC

Debian way:
http://www.linuxhomenetworking.com/...:_Linux_Networking#Creating_Interface_Aliases


----------



## ToeClaws (Jan 13, 2010)

Basic IP aliasing I can do - the tricky thing here is that I need to do it on a VLAN interface, not just a normal eth0 type one.  Distribution in use on this system is Devil Linux.

Interface config files in DL are located in /etc/sysconfig/nic and look pretty much like other distros in that they're all "ifcfg-<interface name>" in name format and contain the appropriate contents.  For VLANs, it would be something like "ifcfg-vlan274", and contain something like this:


```
#
# VLAN 274 10.50.3.64/26 Interface config.
#
DHCP=no
ONBOOT=yes
DEVICE=eth0
VLANID=274
IP=10.50.3.68
NETMASK=255.255.255.192
ROUTE="$ROUTE 0.0.0.0/0:10.50.3.65"
```

I have tried creating a file like "ifcfg-vlan274:1", which was a no-go, and tried also creating a different named file in which I changed the Device line to read "DEVICE=eth0:0" to try and bind the second IP to a sub interface without any luck either.

Out of the 30+ VLAN interfaces on the box, I only need to add a second IP to a couple of them to make things work for a box migration.  Looks like it's turning out to be easier said than done though. :/


----------



## ToeClaws (Jan 13, 2010)

Nevermind - figured it out.  Was a matter of _how _the "network" script feeds things to ifconfig and vconfig.  To do it, I did have to create a second interface file, but in that file, I bind the Device as a sub-interface to the first one, and don't use a VLANID since it's already within a tagged vlan - example:

file "ifcfg-vlan274":

```
#
# VLAN 274 10.50.3.64/26 Interface config.
#
DHCP=no
ONBOOT=yes
DEVICE=eth0
VLANID=274
IP=10.50.3.68
NETMASK=255.255.255.192
ROUTE="$ROUTE 0.0.0.0/0:10.50.3.65"
```

file "ifcfg-vlan274:0":

```
#
# VLAN 274 10.50.3.64/26 Sub-Interface config.
#
DHCP=no
ONBOOT=yes
DEVICE=vlan274:0
IP=10.50.3.74
NETMASK=255.255.255.192
```

w00t... this will make life easier for a migration project.


----------



## Carenath (Jan 13, 2010)

That sounds like the Red Hat way of doing things.. honestly I preferred Debian's networking configuration setup, it seemed less of a pain to work with. Great that you figured it out though.


----------



## ToeClaws (Jan 13, 2010)

Carenath said:


> That sounds like the Red Hat way of doing things.. honestly I preferred Debian's networking configuration setup, it seemed less of a pain to work with. Great that you figured it out though.



Devil Linux is a bit of distro-soup, taking aspects from several major releases.  I totally agree on its network design, but ah well. 

*looks at your avatar* Dawwwwww.


----------

