Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
1  
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
1  
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

2 Answers 2

INTERFACE=Device-Name for your second IP

HOSTNAME=Your target host

route add -host $HOSTNAME dev $INTERFACE

share|improve this answer

You can always try:

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

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.