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.

link|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
feedback

3 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.

link|improve this answer
it is possible but i think its bad style. routing tables are the way to go. – mugen kenichi Jun 23 '10 at 16:37
feedback

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
link|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
feedback

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.

link|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
feedback

Your Answer

 
or
required, but never shown

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