Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have an Ubuntu 12.04 server with 4 Network adapters in it. I need to use each NIC for a separate function. Here is a description of my setup:

etho = 10.234.0.2 netmask = 255.255.255.252 gw = 10.234.0.1 This is on vlan 234
eth1 = 10.235.0.2 netmask = 255.255.255.252 gw = 10.235.0.1 This is on vlan 235
eth2 = 10.236.0.2 netmask = 255.255.255.252 gw = 10.236.0.1 This is on vlan 236
eth3 = 10.237.0.2 netmask = 255.255.255.252 gw = 10.237.0.1 This is on vlan 237

I need to be able to direct traffic to and from the individual IP addresses for separate web services. ie 10.235.0.2 is a website, 10.236.0.2 is a different site, and 10.237.0.2 is a third site. The 1st IP is for management of the server.

I think the issue is a routing issue, but I am new enough to Linux to not have a full understanding of the ins and outs of the routing capabilities.

Here is what is in my /etc/network/interfaces file:

auto lo
iface lo inet loopback

# WWW Management
auto eth0
iface eth0 inet static
address 10.234.0.2
netmask 255.255.255.252
gateway 10.234.0.1
nameseervers 10.230.1.103, 10.230.70.70

# WWW
auto eth1
iface eth1 inet static
address 10.235.0.2
netmask 255.255.255.252
gateway 10.235.0.1

# WTB
#auto eth2
#iface eth2 inet static
#address 10.236.0.2
#netmask 255.255.255.252
#gateway 10.236.0.1

# Moodle
#auto eth3
#iface eth3 inet static
#address 10.237.0.2
#netmask 255.255.255.252
#gateway 10.237.0.1

I have disabled the last two networks just to ease confusion.

Thanks in advance for all of the help and comments and suggestions.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

After doing a normal configuration of just eth0, I came back around and added config for eth1. With just eth0 up, the route table was:

# ip route show
192.168.0.96/27 dev eth0 proto kernel scope link src 192.168.0.126
default via 192.168.0.97 dev eth0 metric 100

But once I brought up eth1, the order of the default route statements determined which interface was always used. As shown below, it happens to choose the eth1 route to the 192.168.1.65 gateway.

# ip route show
192.168.0.96/27 dev eth0 proto kernel scope link src 192.168.0.126
192.168.1.64/27 dev eth1 proto kernel scope link src 192.168.1.93
default via 192.168.1.65 dev eth1 metric 100
default via 192.168.0.97 dev eth0 metric 100

only one gateway statement

The first problem can be the extra 'via 192.168.1.65' default route. It appears there if the eth1 definition in /etc/network/interfaces has a "gateway 192.168.1.65" statement. So remove any extra gateway statement, and bounce the interface:

# ifdown eth1
# ifup eth1
# ip route show
192.168.0.96/27 dev eth0 proto kernel scope link src 192.168.0.126
192.168.1.64/27 dev eth1 proto kernel scope link src 192.168.1.93
default via 192.168.0.97 dev eth0 metric 100

setup new routing table

Create a new, seperate routing table containing a default route appropriate for all traffic flowing out of eth1. The table number here is not important; 101 is simply not the main routing table. Do this with a 'post-up' command on the eth1 configuration in /etc/network/interfaces. Add only one post-up on eth1; Do not add it to any of the eth1: sub-interfaces.

post-up ip route add default via 192.168.1.65 dev eth1 table 101

Bounce eth1. The main routing table is unchanged, and table 101 will contain the via 192.168.1.65 default route if eth1 is up.

# ifdown eth1
# ip route show
192.168.0.96/27 dev eth0 proto kernel scope link src 192.168.0.126
default via 192.168.0.97 dev eth0 metric 100

# ip route show table 101   (ie, table is empty, no output)
# ifup eth1
# ip route show
192.168.0.96/27 dev eth0 proto kernel scope link src 192.168.0.126
192.168.1.64/27 dev eth1 proto kernel scope link src 192.168.1.93
default via 192.168.0.97 dev eth0 metric 100

# ip route show table 101
default via 192.168.1.65 dev eth1

new routing rule

Add a routing rule to use table 101 to select a default route for packets which should go out eth1.

# ip rule add from 192.168.1.64/27 lookup 101
# ip rule show
0:     from all lookup local
32765: from 192.168.1.64/27 lookup 101
32766: from all lookup main
32767: from all lookup default

Add the rule to the /etc/network/interfaces file as well:

post-up ip rule add from 192.168.1.64/27 lookup 101

Now make sure to add cleanup to remove the route and rule when the interface goes down:

post-down ip rule del from 192.168.1.64/27
post-down ip route del default via 192.168.1.65 table 101
share|improve this answer
    
Nice, but I don't like to use rc.local .. looking for a more elegant final step .. –  AlberT Oct 1 '13 at 12:06
    
It was edited I suppose :) .. –  AlberT Jan 10 at 10:28
    
Is there actually an /etc/interfaces file, or is that a typo? –  user100464 May 18 at 20:09
    
@user100464 /etc/network/interfaces –  Zenexer May 21 at 0:56
    
There is a ref to the former in the answer. I can't edit it. –  user100464 May 21 at 2:42

did you using apache? if you do, then you need to create virtual host

u can use one ip to different sites/hosts

u can use one ip to one site/host

u can use multiple ip to one site/host

i hope this will helps you

Clisk here to Apache Virtual Hosts Example

"sorry for my bad english"

share|improve this answer
    
Thanks for your answer. I have established the virtual sites, and have specified which ip's each site should answer to, my problem is I cannot get traffic to flow in and out from each interface. I can get traffic into each interface, but all traffic goes out eth0 instead of the correct interface. –  user168645 Jun 20 '13 at 3:48
    
as long as eth0 can ping the client it will use the eth0, you can set your router to manage this connection. –  astrajingga Jun 20 '13 at 3:53
    
The router doen't matter .. it is a server routing issue for outcoming packets .. using apache vhosts you solve the problem to assign a service to a given IP (and so to a NIC), but you need to handle outgoing routing to assure you don't send the response via the default GW (so the default GW NIC) Not enough reputation to vote down ;) –  AlberT Jan 10 at 11:13

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.