Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a server with two public IPs. Both IPs are added to eth0 using ip addr add. Now I'd like to contact a server which uses IP address filtering. Only requests are allowed which use the second IP address. Is there are way to set this up using the standard route command in Linux? I guess that's not the case.

So the only solution I see right now: Setup a virtual device let's say eth0:0 and bind the second IP address to it. Then I can reference the device in the route command.

Edit: I can't use the second IP as primary one easily as this IP is used as failover IP.

share|improve this question
Why route? Why not setup a SNAT? As in have iptables adjust the source address? – Zoredache Sep 24 '12 at 15:38
Good point. I'll look into this... – spa Sep 24 '12 at 15:43
Whatever application you are connecting from should bind to the IP you want for it's outbound connection. It's not terribly common for user applications to support this, but many server and diagnostic programs do. – Chris S Sep 24 '12 at 15:56

You can always try:

# ip r add <dest server>/32 via <default gateway of second IP>
share|improve this answer

INTERFACE=Device-Name for your second IP

HOSTNAME=Your target host

route add -host $HOSTNAME dev $INTERFACE

share|improve this answer

Your Answer


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.