I need to send the packets of specific port to different gateway. This is the situation:

The server has different services, like http, dns, and mail (smtp,pop,imap), and it has two gateways.

eth2: Gateway1 (Default gw)

ppp0: Gateway2

All the services run ok on the default gw (eth2), but I need to send all the packets that the server generate to send email (dest port 25) to go out to the Gateway2 (ppp0).

It isn´t possible with prerouting because there are packets that are locally generated.


I think you could control DNS and SMTP at least by installing specific routes. You could put in a route for the SMTP's "smart server" or mail relay, and the "nameserver" IP address using ip. You'd have to know the PPP IP address on the inside however. Supposing you use Google's public DNS server, and ppp0 has IP address

ip route add via

That would install a "static route" to Google's public DNS via the PPP IP address. You cold do the same with your mail relay(s).

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