# How do I setup a permanent virtual ethernet iface?

## tylerd75

I'm trying to setup a virtual interface to expand my LAN to cover 2 subnets.

The actual setup is easy (with ipconfig eth0:0 <IP> netmask <netmask>... and the route is correct.

But how do I create something like that in /etc/conf.d/net?

If I create a virtual interface in net I get the error: eth00 does not exist (I couldn't use ":" in the iface name, so I called it eth00 instead...)

Any ideas?

Cheers,

TylerD

----------

## nms

This is how my IPv6 interface is set up on my server, but I haven't touched the configuration in a few months so I'm not quite sure if I remember it all correctly. The concept should be somewhat in the right direction, though. General waiver of liability applies.

Install iproute2:

```
emerge iproute2
```

Instruct the rc scripts to use iproute2 in /etc/conf.d/net:

```
modules=( "iproute2" )
```

Add your interface to /etc/conf.d/net:

```
config_mynewinterface=( "172.16.43.4/24" )

routes_mynewinterface=( "172.16.0.0/16 via 172.16.43.1" )
```

(The routes_ line is only required if you need to route the traffic to the secondary network through another gateway than your default.)

Create an rc script to start your new interface:

```
cd /etc/init.d/

ln -s net.lo net.mynewinterface
```

Now all you should have to do is run the script:

```
/etc/init.d/net.mynewinterface start
```

And if that works and you want the interface to start at boot:

```
rc-update add net.mynewinterface default
```

----------

## CriminalMastermind

 *tylerd75 wrote:*   

> I'm trying to setup a virtual interface

 

i believe what you are looking for is often called an alias.  hope this helps you out.

----------

## nms

After a few hours of sleep I realised that my example above is totally useless since I'm using tunneling for my extra interfaces. This is the way to do it for aliases:

```
config_eth0=(

    "192.168.0.4/24"

    "10.3.25.6/16"

)

routes_eth0=(

    "default via 192.168.0.1"

    "10.0.0.0/8 via 10.3.0.1"

)
```

All according to http://www.gentoo.org/doc/en/handbook/2005.1/handbook-x86.xml?part=4&chap=2.

----------

## tylerd75

Thanks nms and CriminalMastermind!

This solved my problem, and gave me some insight into how flexible the /etc/conf.d/net file can be (just like the rest of Gentoo!)!

Cheers!

TylerD

----------

## faemin

...Last edited by faemin on Sun Dec 02, 2012 9:47 pm; edited 1 time in total

----------

## khayyam

 *faemin wrote:*   

> The solution above kind of works for me, but I am not happy with the Gentoo solution, as the virtual interfaces are not named like eth0:0, eth0:1, etc.

 

faemin ... by default openrc will use iproute2 to configure network interfaces, and iproute2 doesn't create virtual interfaces in the same way as ifconfig, they are not 'labeled', and as ifconfig expects them to be labeled it doesn't show them in its output. 

 *faemin wrote:*   

> I use one of the two methods to declare the addresses, but it gives me a different result then if I do 
> 
> ```
> ifconfig eth0:0 192.168.0.5 up
> ```
> ...

 

... and the following should do the same (using iproute2)

```
# ip addr add local 192.168.0.1/32 dev eth0 label eth0:1

# ip addr add local 192.168.0.2/32 dev eth0 label eth0:2
```

If you want to use 'ifconfig' to configure your interfaces then you should set 'modules=' so that ifconfig is used in perference to iproute2:

/etc/conf.d/net

```
modules_eth0="ifconfig"

config_eth0="192.168.0.1/24 192.168.0.2/24"
```

best ... khay

----------

## faemin

...Last edited by faemin on Sun Dec 02, 2012 9:46 pm; edited 1 time in total

----------

## khayyam

 *faemin wrote:*   

> OK thanks, I will try that.

 

faemin ... actually I should have stated the modules preference this way:

```
modules_eth0="!iproute2"
```

Note that you might also want to read the section on "VLAN (802.1q support)" in /usr/share/doc/openrc-{version}/net.example.bz2 and also the examples provided for "pass[ing] parameters to go with an address", that is, if you were wondering how iproute2 would be similarly configured.

 *faemin wrote:*   

> Also, the second part of my question.  I want the Tor Relay running on one IP Address, and all traffic to/from to show that IP, including source address.  I want the same for the email server, for another ip address.

 

... and so you would set these services to 'listen' on the address provided for the respective virtual interfaces.

 *faemin wrote:*   

> Finally, I am a n00b, should this have bee a separate topic?

 

probably, yes :)

best ... khay

----------

## faemin

...Last edited by faemin on Sun Dec 02, 2012 9:45 pm; edited 1 time in total

----------

## khayyam

 *faemin wrote:*   

>  *khayyam wrote:*   ... and so you would set these services to 'listen' on the address provided for the respective virtual interfaces. 
> 
> OK, when I do that, it is still routing traffic for the gateway associated with the primary address on the primary interface. I put tor to "listen" on for ex. 192.168.0.2, and mail smtp on 192.168.0.1, but everything seems to show the source address for whatever address is listed first in the array list of conig_eth0="..."

 

faemin ... in which case don't assign an address to 'eth0'

```
config_eth0="null"
```

Again, see the section "VLAN (802.1q support)" in /usr/share/doc/openrc-{version}/net.example.bz2.

best ... khay

----------

## khayyam

dupe ... can't delete and so, ignore

----------

