# IP Aliases on different subnets

## phzi

I'm trying to configure a machine that has 4 assigned IP address on separate subnets, linked to one interface.

Here is my attempt at /etc/conf.d/net :

```

config_eth0=( "<IP1>/24 brd <BRD1>"

        "<IP2>/24 brd <BRD2>"

        "<IP3>/24 brd <BRD3>"

        "<IP4>/24 brd <BRD4>" )

routes_eth0=( "default gw <GW1>"

        "default gw <GW2>"

        "default gw <GW3>"

        "default gw <GW4>")

```

/etc/init.d/net.eth0 restart yields:

```
 * Bringing down interface eth0

 * Bringing up interface eth0

 *   <IP1>/24 ...                                                                   [ ok ]

 *   <IP2>/24 ...                                                                   [ ok ]

 *   <IP3>/24 ...                                                                     [ ok ]

 *   <IP4>/24 ...                                                                    [ ok ]

 *   Adding routes

 *     default gw <GW1> ...                                                        [ ok ]

 *     default gw <GW2> ...                                                        [ ok ]

 *     default gw <GW3> ...                                                         [ ok ]

 *     default gw <GW4> ...                                                         [ ok ]

 *   Waiting for IPv6 addresses ...                                                         [ ok ]

 * Starting named ...

 * Checking named configuration ...                                                         [ ok ]
```

However, ifconfig only shows the main eth0 IP, there are no sub-interfaces e.g. eth0:1

2.6.38.2-grsec-xxxx-grs-ipv6-32 #1 SMP

ifconfig eth0:0 <IP2> netmask 255.255.255.0 up

works fine btw

Any suggestions?

----------

## loisl

I am wondering that this works. 

When You have more than one default route, the routing load balances between these default routes ....

----------

## Yuu

Hi,

since openrc/baselayout2, it's like that; or at least, I just noticed after my migration. However, and for me, the aliases don't show with ifconfig, but with ip address show from sys-apps/iproute2.

Example :  *Quote:*   

> # ip address show lo
> 
> 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
> 
>     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
> ...

 

Why ? I don't know. But I'm also interested to display the interfaces aliases with ifconfig or to choose the 'interface handlers'.

----------

## NeddySeagoon

phzi,

You cannot usefully have more than one default net. Consider a nice simple routing table.

```
$ /sbin/route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

default         bloodnoc        0.0.0.0         UG    3      0        0 eth0

loopback        localhost.local 255.0.0.0       UG    0      0        0 lo

192.168.10.0    bloodnoc        255.255.255.0   UG    3      0        0 eth0

192.168.100.0   *               255.255.255.0   U     0      0        0 eth0
```

The kernel matches packets from the bottom of the routing table working up.

Anything destined for 192.168.100.0/24 is sent out of eth0, no gateway is required

Anything destined for 192.168.10.0/24 is sent to bloodnoc, its bloodnocs problem to pass it on.

...

Lastly, any packets that have not yet been matched are sent via the default route ... thus that matches any and all packets.

Only the first default route in the routing table will ever be used.

----------

## phzi

That doesn't quite fulfill my needs unfortunately.

I need eth0:0, eth0:1 etc so that I can arbitrarily route various traffic through a specific IP.  I don't want specific ranges to be routed via a specific method, rather intend to route specific programs or users via a specific outgoing IP.

----------

## NeddySeagoon

phzi,

Routing alone does not do want you want.  You need to look into iptables and setting things up.

I've never tried routing for programs or users.

Instead of asking about your proposed solution, tell us your problem ... maybe there is a solution waiting for you, just not the one you are thinking of right now.

----------

## AngelKnight

 *phzi wrote:*   

> That doesn't quite fulfill my needs unfortunately.
> 
> I need eth0:0, eth0:1 etc so that I can arbitrarily route various traffic through a specific IP.  I don't want specific ranges to be routed via a specific method, rather intend to route specific programs or users via a specific outgoing IP.

 

It isn't clear why 4 defaultroutes installed in the FIB help for this.  Maybe "ip rule" is what you're after?

----------

## phzi

So I have come back to this problem and am looking for a solution again.

Here is the idea of what I am trying to accomplish (with IP tables and network configuration):

- Establish four seperate IPs on distinct subnets that I can use on one interface

- Have four users, each which who's outgoing traffic is routed out ONLY via a single specified IP.

I think I can see how to do this if each outgoing IP has a separate interface assigned, e.g. ETH0:0, ETH0:1, but can't think of how to possibly do this otherwise.

Any suggestions?

----------

## Hu

Why do you need each user to come from a different address?  Why do you need each address to be on a separate subnet?

----------

## phzi

 *Hu wrote:*   

> Why do you need each user to come from a different address?  Why do you need each address to be on a separate subnet?

 

Because I do... the machine has multiple IPs assigned to it, which happen to be on different subnets.  Users are intended to have a unique outgoing IP address.

----------

## gentoo_ram

How about virutalization?  Set up a separate virtual machine for each user and you can put whatever IP addresses you want on the virtual machines.  On your host, you can set up different virtual interfaces which connect with each of the virtual machines.  Theoretically, the linux kernel "namespace" functionality can do what you want without virtualization, I think.  But I don't know of any distribution that utilizes it.Last edited by gentoo_ram on Thu Sep 22, 2011 3:57 am; edited 1 time in total

----------

## Hu

You restated the intended solution without resolving any of my questions.  I asked those questions because it is very often the case that people who request help implementing a difficult solution would be just as well served by a simpler solution, but we cannot help them find that simpler solution until we know the true nature of the problem to solve.

----------

