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

On my server I want to route my internet traffic over my eth0:2 alias. When I use this command:

sudo iptables -t nat -A POSTROUTING -s -o eth0:2 -j MASQUERADE

It returns this:

Warning: weird character in interface `eth0:2' (No aliases, :, ! or *).

Is there any way to route only traffic from openvpn ip over that single ip?

Thanks for you help,

share|improve this question

migrated from Apr 10 '11 at 5:54

This question came from our site for professional and enthusiast programmers.

I don't think it really makes sense to specify an interface alias here; the packets are going out over the same physical card either way, you just need to make sure they have the correct source / destination IPs and ports. – sarnold Apr 9 '11 at 22:08

You should use SNAT instead of MASQUERADE here.

   This target is only valid in the nat table, in the  POSTROUTING  chain.
   It  should  only  be used with dynamically assigned IP (dialup) connec‐
   tions: if you have a static IP address, you should use the SNAT target.

Assuming you want to SNAT any traffic coming from, exiting via eth0, onto whatever IP address is bound to eth0:2 (I'm going to say "w.x.y.z" here), try the following:

sudo iptables -t nat -A POSTROUTING -s -o eth0 -j SNAT --to-source w.x.y.z

where w.x.y.z is the IP bound to eth0.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.