Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've got two network interfaces on an Ubuntu machine which go out to two different networks but both have internet gateways.

I need to limit it so that any outgoing http requests it makes (ie through wget) only go through eth0 and all other traffic goes through eth1.

I dare say the solution might have something to do with iptables but I've no experience with it so would appreciate all help.

share|improve this question
    
Would this fit in better on Server Fault? –  Aren B Jun 3 '10 at 0:22
2  
Not really, this isn't a server question. –  Daisetsu Jun 3 '10 at 0:39
    
@Daisetsu: mhh .. not sure. I have seen questions for bandwith sharing and bandwidth load balancing on serverfault.com already. –  akira Jun 3 '10 at 3:49
    
@Oli: can you clarify the difference between what my browser creates in "outgoing" traffic and what wget creates in "outgoing" traffic? –  akira Jun 3 '10 at 3:51
    
akira: No difference at all. The only reason I specify wget is because the computer is a headless server. Certain scripts make requests to other servers through wget and I basically need to restrict which interface it uses for certain outbound jobs. –  Oli Jun 3 '10 at 22:04
show 1 more comment

4 Answers

You can do this with IPTables. You need to specify a prerouting (or was it forwarding) rule which says anything which is on port 80 should be routed to eth0, and then in the regular routing rules default to eth1.

It's been a while since I have constructed IPTables rules so I can't come up with the exact rules.

share|improve this answer
    
it is possible but i think its bad style. routing tables are the way to go. –  matthias krull Jun 23 '10 at 16:37
add comment

If it's enough that just wget traffic goes to the other interface, you can do this:

First, learn about routing tables and multiple default routes: http://lartc.org/howto/lartc.rpdb.multiple-links.html

Set up your networking so that the default routing table puts traffic via eth1. Then add a rule that traffic originating from eth0 ip address uses the routing table for eth0. Then use the wget option --bind-address to bind to the eth0 ip address.

If you're not using wget which can specify the binding address, an alternative is to set up a www proxy and bind that (only) to the eth0 address, then use that proxy.

share|improve this answer
add comment

I would say edit Apache, to "listen" to a specific IP address. By Default, Apache listens to all IP addresses that your machine may have.
Look in /etc/apache2/sites-enabled/xxx and check for the Listen Directive. I'm afraid I don't use Ubunutu, so take a look at

grep -r -i "listen" /etc/apache2/

Find the file, and change it to:

# Listen <IP ADDRESS>:<PORT>  
Listen 10.2.3.4:80
share|improve this answer
1  
I'm talking about outbound traffic (ie the computer in question making a request to another server). You could think of it as a desktop if you wanted. Nothing to do with Apache or any other httpd. –  Oli Jun 3 '10 at 22:02
add comment

Look at shorewall. Documentation for the masq file seems to cover what you want. You will need to ensure that you don't route between the two interfaces.

share|improve this answer
    
Sorry, that's DNS and nothing to do with outbound traffic routing. –  Oli Jun 3 '10 at 22:06
    
Shorewall is not DNS and all about iptables. You need to ensure request are addressed from the appropriate interface which is what Shorewall can do for you fairly easily. –  BillThor Jun 3 '10 at 23:42
add comment

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.