1

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,

1
  • 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, 2011 at 22:08

1 Answer 1

2

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

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

You must log in to answer this question.