Super User is a question and answer site for computer enthusiasts and power users. 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

On Linux, is it possible to have all requests done to a specific IP to be routed through a virtual interface, so that on the other end they appear with a different IP address that the host's main? Suppose that eth0 has the IP address while eth0:1 has the address How can I make all requests to appear as coming from eth0:1? I am trying the following but it doesn't seem to work:

route add dev eth0:1
share|improve this question
up vote 4 down vote accepted


One way to do this would be to use IPTABLES to rewrite the packets leaving the machine with multiple IP addresses to say they come from the virtual interface. Try

/sbin/iptables -t nat -I POSTROUTING -d DEST.IP -j SNAT --to VIRTUAL.IP

(You do, of-course, need to have the virtual IP set up as you contemplated, ie eth0:1 or equivalent needs to exist so traffic can find its way back to the machine)

share|improve this answer
Thanks, worked like a charm! – Georgios Gousios Feb 8 '13 at 19:12

It may be necessary to use the command

ip route add dev eth0:1 src

or route with a similar option. If that does not work as expected you may need advanced routing: Create an additional routing table for this target in /etc/iproute2/rt_tables, put the above entry as the only one into this table and activate this table:

ip rule add to priority 100 table to__1_2_3_4
ip route flush cache

The desperate last resort solution would be netfilter: You could use SNAT with iptables in the POSTROUTING chain to rewrite the source address for packets to this destination.

share|improve this answer
Unfortunately, I had to resort to SNAT (see answer above), tuning IP routing tables is not my strong point :-) Thanks! – Georgios Gousios Feb 8 '13 at 19:16

You should be able to add additional addresses to an interface, if that's what you are asking.

I know this is possible using iproute2's ip command:

ip addr add dev eth0
ip addr add dev eth0

ifconfig will only show the first one, IIRC. You can use ip addr show eth0 instead.

If that's not what you were looking for, try this similar question

share|improve this answer
This is not I asked. I already have mutliple virtual interfaces on my machine with different IPs. Thanks anyway! – Georgios Gousios Feb 8 '13 at 19:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .