My Ubuntu Server has one physical interface eth0
. I want to assign 3 ip's (different subnets) to the server. I cannot use the default virtual interface creation tools like ifconfig
or ip addr add
(e.g. eth0:0
) because for each of those 3 ip's I need to specify a default gateway. So, whether it is possible to have a bridge to which I can attach eth0
( and multiple tap or tun interfaces with ips that I want), but each of the virtual devices can connect to subnets accessbile over eth0
.
EDIT1:
Imagine I want 5 ethernet interfaces to connect to 5 different networks. But I can't afford to have 5 interfaces. So I buy an unmanaged switch, and connect cat5 cables from all the 5 networks to that switch and one port of that switch in connected to eth0
of Ubuntu server. In order to deal with all 5 networks on Ubuntu server, I create 5 virtual interfaces that behave like physical interfaces (eth1, eth2, so on ..), that traverse through eth0
and end up at the switch. I don't mind if all those seperate networks traverse through one unmanaged switch. But I want my Ubuntu server to treat those networks as if they are attached to 5 physical interfaces.
You can only have one default route on a system.
You can add static routes in to force some traffic to go via a different router:
or
These commands can be added to /etc/network/interfaces.
What you want is to influence routing decisions in the kernel. This is typically called policy routing: in your case, I assume you want a policy that acts on the source address to route back to that interface. Net traffic that arrives on one interface should exit on that interface and packets on a certain interface should use rules specified for that interface rather than the default table. The command you want is
ip rule
.Having said that, there is not enough information in OP to say for certain that policy routing is needed.
After googling for many months I think I have found the answer. It can be done with vde tool that is used to create interfaces for guest OS's in KVM. Here are the steps:
Install the software:
Create a virtual switch:
Create a tap device:
Create another tap device (the new socket file needs to be specified):
Any number of
tap
devices can be created provided each gets a new socket file.Connect your pysical device to vde switch:
Assign ip addresses to both the tap devices (my
eth0
is on192.168.1.10/24
):I have put all the interfaces on same network so that I can ping each other and test if the setup works well.
Now ping the ip's
192.168.1.80
and192.168.1.90
from a different host which is on the same network (probably with your windows machine).From Ubuntu other hosts on the network can be pinged from the new
tap
devices like so:Now
ifconfig
can be used to re-assign ip addresses that belong to seperate networks to tap devices.Thats it. Seperate virtual interfaces that act like seperate interfaces.
I have not found any howto/tutorial which explains this procedure. May be someone could test it under various situations to see if it is a feasible solution to be implemented in a production environment.
You can use the
eth0:x
format to add the additional IP addresses. Just be sure to add the appropriate netmask to each network. You can route additional networks on each interface as shown.When routing additional networks you need to know the gateway address for the network that you connected to. This will be the gateway address for any networks you want to route using that interface.
Unless you are using policy routing or similar connection load sharing you should only have one default route.
why don't you use simple tuctl utility in linux:
This will create new interface eth5, assing it IP/MASK and voila, configure just like anyother interface, should work just fine.