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.

This is probably a silly question.
I'm doing some http requests using wget from the command line, and I want those connections to be made through one specific IP of the 4 IPs my server has.
Those http requests go to one specific range of IPs so I only want those to be routed differently.
The 4 interfaces in my server are eth0, eth0:0, eth0:1, eth0:2.

I tried with the following command:
route add -net 192.164.10.0/24 dev eth0:0

But when I see the routing table it says:

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.164.10.0    0.0.0.0         255.255.255.0   U         0 0          0 eth0

The interface is set to eth0 not eth0:0 as my command says.

What am I doing wrong?

share|improve this question
add comment

3 Answers

wget --bind-address=192.0.2.116 http://file from man wget

share|improve this answer
    
Ok, but that's a wget specific solution. How can I make the routing work? –  GetFree Apr 6 '13 at 3:53
2  
We aren't exactly talking about routing, because it's all about pseudo interfaces. You are using one interface and all requests go the same route - regardless of the source IP address which is defined in application code. Unless specifically designated, client TCP sockets are bound to an interface's default address. –  Lukas Apr 6 '13 at 4:00
    
You know it's a long day when you see a mod's answer auto-flagged for the LQP queue. –  Andrew B Apr 6 '13 at 4:19
    
I thought you could use the virtual interfaces like any other. Apparently you cannot. –  GetFree Apr 6 '13 at 7:28
add comment

If it's not wget, then there's this nifty little wrapper that you use LD_PRELOAD to insert before you run any command.

You can use that to specifically bind, say, a browser to a VLAN interface (speaking from experience).

share|improve this answer
add comment

You could try to setup PBR (policy base routing) if you need more flexible routing (instead of --bind-address)

IP1='xxx.xxx.xxx.62'
IF1='eth0'
GW1='xxx.xxx.xxx.61'
P1_NET='xxx.xxx.xxx.60/30'

IP2='yyy.yyy.yyy.10'
IF2='eth0:0'
GW2='yyy.yyy.yyy.9'
P2_NET='yyy.yyy.yyy.8/30'

IP3='zzz.zzz.zzz.239'
IF3='eth0:1'
GW3='zzz.zzz.zzz.254'
P3_NET='zzz.zzz.zzz.0/24'

/sbin/ip route add $P1_NET dev $IF1 src $IP1 table ISP1
/sbin/ip route add default via $GW1 table ISP1

/sbin/ip route add $P2_NET dev $IF2 src $IP2 table ISP2
/sbin/ip route add default via $GW2 table ISP2

/sbin/ip route add $P3_NET dev $IF3 src $IP3 table ISP3
/sbin/ip route add default via $GW3 table ISP3

/sbin/ip rule add from $IP1 table ISP1
/sbin/ip rule add from $IP2 table ISP2
/sbin/ip rule add from $IP3 table ISP3

/sbin/ip ru add fwmark 1 lookup ISP1 prio 100
/sbin/ip ru add fwmark 2 lookup ISP2 prio 200
/sbin/ip ru add fwmark 3 lookup ISP3 prio 300

/sbin/ip route add default via $GW1
/sbin/ip route flush cache

And then use something like following

iptables -t mangle -I OUTPUT -p tcp --dport 80 -j MARK --set-mark 1
share|improve this answer
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.