how to change masquerade "to-addresses" or route pref-src

Hello there,

I have a peculiar requirement (at least, its peculiar in that I haven’t been able to find a solution myself!!!).

I have a dhcp-client running on a port, it is bridged to other ports connected to devices which we also need to get an IP address from the upstream router.

I also have a couple of WAN aliases on the port on the same subnet as the dhcp-client.

I have NAT masquerading set-up for the LAN (including the bridged clients).

This was set-up in the following order :

  1. dhcp-client
  2. additional aliases

For a while the masquerade rule performed as expected, masquerading all outbound traffic to the address obtained via dhcp.

Since a power cut and a subsequent router reboot, one of the aliases has now become the forwarding address.

I’ve tried adding a “to-addresses” value to the masquerade rule which is (probably quite rightly) ignored.

I’ve tried adding a static route to the subnet on the output side, but as there is a dynamic route it takes preference and so the static route is not active.

Some config follows :

 #   ADDRESS            NETWORK         BROADCAST       INTERFACE                                                          
 3   192.168.2.101/24   192.168.2.0     192.168.2.255   ether1                                                                     
 4   192.168.2.102/24   192.168.2.0     192.168.2.255   ether1                                                                     
 7 D 192.168.2.242/24   192.168.2.0     192.168.2.255   ether1

and routes as follows :

 #      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE
 0 ADS  0.0.0.0/0                          192.168.2.1        0             
 4 ADC  192.168.2.0/24     192.168.2.101   techmedia          0       
 5   S  192.168.2.0/24     192.168.2.242   ether1             1

I need the forwarded traffic to appear from the source 192.168.242.2 instead of the 192.168.2.101 currently - any ideas how to achieve this?

Many thanks!

Cheers./C.

Use action=src-nat

Thanks for the reply!

Is action=masquerade doing anything else that src-nat won’t do - i.e. does it need any further options (apart from the dst-address I need to add) that masquerade “assumes”?

Thanks again!

Thanks again,

Worked like a charm, and, of course, in my reply above I meant “to-addresses” instead of “dst-address” :wink:

Action masquerade is the same action src-nat only with one additional feature - it doesn’t require “to-address” option (it ignores this option) - this is very useful when your Public IP is dynamic and might change periodically

So masquerade for dynamic public IPs, src-nat for static. :wink:

Excellent, that’s exactly what I didn’t know!!