Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

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 dev eth0:0

But when I see the routing table it says:

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface   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

wget --bind-address= 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
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

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

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




/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

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.