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.

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 10.8.0.4 -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 10.8.0.4 over that single ip?

Thanks for you help,

share|improve this question
    
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
add comment

migrated from stackoverflow.com Apr 10 '11 at 5:54

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

1 Answer

You should use SNAT instead of MASQUERADE here.

MASQUERADE
   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 10.8.0.4, 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 10.8.0.4 -o eth0 -J SNAT --to-source w.x.y.z
share|improve this answer
add comment

Your Answer

 
discard

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