Skip to contentSkip to conversation

How to change source port in MASQUERADE mode?

DISCUSSION Richard Liu 2 participants 3 messages Sep 30, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

Hi,
I have a question about change tuple source port.
I have a nat device, and I want this device can change tuple source port in some special conditions (not always).

I want change tuple source port in MASQUERADE module.

for example:
Destination Gateway Source
DA(Ipaddr):Port GA:Port SA:Port

In Masquerade modules

                                    src:GA:1000           src:SA:1000
                                    dst:DA:23               dst:DA:23

But I want to the src port be changed in some conditions like this.

                                    src:GA:50000+1000  src:SA:1000
                                    dst:DA:23               dst:DA:23

I am tracing source few days, but I still don't know which function allocate tuple source port.
Does anyone can give me some hints, I am very appreciate.

#1 lore raw
Quoted 1 line · Richard Liu

I want change tuple source port in MASQUERADE module.

--to-ports option to MASQUERADE (or SNAT if not dynamic IP assignment).

Quoted 3 lines

But I want to the src port be changed in some conditions like this.

                                   src:GA:50000+1000  src:SA:1000
                                   dst:DA:23               dst:DA:23

Then you simply need rules matching your conditions.

Regards
Henrik

#2 lore raw

Henrik Nordstrom 提到:

Thanks for your mail,

But --to-port parameter cannot get tuple port result like "50000+1000"

I found a way for this situation.

in file ip_MASQUERADE.c
we can change
mr->range[0].min,
mr->range[0].max
and set
mr->range[0].flags = IP_NAT_RANGE_PROTO_SPECIFIED; for some special purposes.

but I don't know does it have other effects to the netfilter?

Quoted 12 lines · Richard Liu
Quoted 2 lines

I want change tuple source port in MASQUERADE module.

--to-ports option to MASQUERADE (or SNAT if not dynamic IP assignment).

Quoted 3 lines

But I want to the src port be changed in some conditions like this. src:GA:50000+1000 src:SA:1000
dst:DA:23 dst:DA:23