Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
please draw a small chart and elaborate a bit more on what you're trying to accomplish. I can't see where you are heading the way it is written right now. –  the-wabbit Dec 11 '11 at 13:08
    
I updated my question. –  nixnotwin Dec 11 '11 at 13:59
    
I still don't get it - why do you need different default routes for the separate networks? And why in heaven don't you just buy a managed switch and run VLANs where you would get proper separation and virtual interfaces all along? –  the-wabbit Dec 11 '11 at 21:53
    
Managed switches are very expensive. My ISP has given a /29 network. I want Ubuntu server to be a NAT router and a webserver. If I use a single public ip for NAT and webserver, then if any of my users on NAT network visit dodgy sites, then law enforcers just have to put my public ip in the browser to see my website. So, my plan is to use two public ips from /29 subnet, one for NAT and another for webserver. Presently I use this setup with multiple LAN cards, and it is working fine. My cards are 1 gbps but I have 5 mbps WAN connection, which is a sheer waste of resources. –  nixnotwin Dec 12 '11 at 1:00

5 Answers 5

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:

    route add 172.16.1.0/24 172.26.1.250

or

    ip route add 172.16.1.0/24 via 172.26.1.250 dev eth0:1

These commands can be added to /etc/network/interfaces.

share|improve this answer
    
It is possible to have many default routes either for load balancing or for policy routing –  nixnotwin Dec 11 '11 at 10:48
    
Interesting, that's a new one on me. It sounds like you've answered your own question, though. –  James O'Gorman Dec 11 '11 at 10:56
    
No, that wasn't an answer to my question. I have setup multiple gateways with multiple network cards. But, in this case, I want to use multiple ip's and multiple default gateways with only one physical interface. –  nixnotwin Dec 11 '11 at 12:24

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:

sudo apt-get install vde2

Create a virtual switch:

sudo vde_switch -s /tmp/switch1 -daemon

Create a tap device:

sudo vde_switch -tap tap0 -daemon

Create another tap device (the new socket file needs to be specified):

sudo vde_switch -tap tap1 -sock /var/run/vde.ctl/ctl1 -daemon

Any number of tap devices can be created provided each gets a new socket file.

Connect your pysical device to vde switch:

sudo vde_pcapplug -d eth0

Assign ip addresses to both the tap devices (my eth0 is on 192.168.1.10/24):

sudo ifconfig tap0 192.168.1.80 netmask 255.255.255.0
sudo ifconfig tap1 192.168.1.90 netmask 255.255.255.0

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 and 192.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:

ping -I tap0 192.168.1.1

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.

share|improve this answer
    
This works in certian situations, sometimes it doesn't work at all. –  nixnotwin Dec 12 '11 at 1:10

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.

iface eth0:1 inet static
    address 192.0.2.6
    netmask 255.255.255.0
    post-up route add -net 198.51.100.0/24 netmask 255.255.255.0 gw 192.0.2.1

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.

share|improve this answer

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.

share|improve this answer

why don't you use simple tuctl utility in linux:

tunctl -u root -i eth5

This will create new interface eth5, assing it IP/MASK and voila, configure just like anyother interface, should work just fine.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.