Skip to contentSkip to conversation

How to log NAT translations

DISCUSSION Italo Valcy 4 participants 6 messages Sep 14, 2010 – Sep 21, 2010

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi guys!

I'm a newbie in this mainling list, so I'm sorry if this question was already asked.

I'd like to have more specific logging output of NAT translation in iptables. Is there an way to logging of ORIGINAL_IP/ORIGINAL_PORT + TRANSLATED_IP/TRANSLATED_PORT?

I know that I can put a logging rule before my NAT rule, but this way I haven't the TRANS_IP/TRANS_PORT... for instance:

iptables -t nat -I POSTROUTING -s 10.0.0.0/24 -j SNAT --to 172.16.0.1 iptables -t nat -I POSTROUTING -s 10.0.0.0/24 -j LOG

In the above example I don't know how to get the TRANS_PORT...

I also know that we can access this information through /proc/net/ip_conntrack (or using netstat-nat), but to get all translation of a whole day its a big overhead to parse that file all the time...

Thanks for any help!

- --
Saudações,

Italo Valcy :: http://wiki.dcc.ufba.br/~ItaloValcy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyPr98ACgkQfidLqjN6RNGWAgCgjLgYUkPiAEp+C2znpRqUskoU FAQAoIeWZQEXFS9LY2RSnxlSKjrmtkNL
=WLWD
-----END PGP SIGNATURE-----

#1 lore raw
Quoted 11 lines · Italo Valcy

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi guys!

I'm a newbie in this mainling list, so I'm sorry if this question was already asked.

I'd like to have more specific logging output of NAT translation in iptables. Is there an way to logging of ORIGINAL_IP/ORIGINAL_PORT + TRANSLATED_IP/TRANSLATED_PORT?

conntrack -E

#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Jan,

Em 14-09-2010 14:54, Jan Engelhardt escreveu:

Quoted 7 lines · Italo Valcy
Quoted 6 lines

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi guys!

Quoted 8 lines
Quoted 6 lines

I'm a newbie in this mainling list, so I'm sorry if this question was already asked.

I'd like to have more specific logging output of NAT translation in iptables. Is there an way to logging of ORIGINAL_IP/ORIGINAL_PORT + TRANSLATED_IP/TRANSLATED_PORT?

conntrack -E

Thank you for the reply.

Actually, I wanna something more simple and specific than the command above. Using 'conntrack -E', I still have to parse the package events NEW, UPDATE and DESTROY if I wanna know the of a NAT, for example. Furthermore, with 'conntrack -E', in my opinion, we have an important overhead of the output (it's so many messages to write to stdout - or even redirect to a file)...

My ideia is to write a NAT (or conntrack) helper (as a kernel module) that monitors the DESTROY event of a DNAT and try to find out when was the NEW event of the same connection (maybe we have this information in some struct..); then we write a log message (like LOG target does) which contains ip_src-orig/port_src-orig, ip_src-translated/port_src-translated, ip_dst/port_dst, duration of the NAT (a little bit similar to Cisco/Asa NAT logging..). What do you think? Where can I find some documentation to read?

Thank you so much for any help!

- --
Saudações,

Italo Valcy :: http://wiki.dcc.ufba.br/~ItaloValcy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyYF4kACgkQfidLqjN6RNGBrgCdGeGdZe4jzY7cR9xM5zNqV/RJ k20AnRl6VKzz31k2vSqgQmL5Tafm931s
=bUcw
-----END PGP SIGNATURE-----

#3 lore raw
Quoted 3 lines · Italo Valcy

Actually, I wanna something more simple and specific than the command above. Using 'conntrack -E', I still have to parse the package events NEW, UPDATE and DESTROY if I wanna know the of a NAT

So use conntrack -Ee NEW to limit the output :)
If that is still too much overhead, I'm sure you can directly use libnetfilter_conntrack's library interface to get at these events.

#4 lore raw
Quoted 9 lines · Jan Engelhardt
Quoted 3 lines · Italo Valcy

Actually, I wanna something more simple and specific than the command above. Using 'conntrack -E', I still have to parse the package events NEW, UPDATE and DESTROY if I wanna know the of a NAT

So use conntrack -Ee NEW to limit the output :)
If that is still too much overhead, I'm sure you can directly use libnetfilter_conntrack's library interface to get at these events.

You can refine this a bit more with:

`conntrack -Ee NEW --any-nat'

It was introduced in conntrack-tools-0.9.15.

#5 lore raw
Quoted 7 lines · Pablo Neira Ayuso
Quoted 6 lines · Jan Engelhardt
Quoted 3 lines · Italo Valcy

Actually, I wanna something more simple and specific than the command above. Using 'conntrack -E', I still have to parse the package events NEW, UPDATE and DESTROY if I wanna know the of a NAT

Quoted 7 lines
Quoted 3 lines

So use conntrack -Ee NEW to limit the output :)
If that is still too much overhead, I'm sure you can directly use libnetfilter_conntrack's library interface to get at these events.

You can refine this a bit more with:

`conntrack -Ee NEW --any-nat'

Yes, but it's strange to use 'conntrack' for logging. Isn't it simpler to use ulogd2 and the ulogd_inpflow plugin?

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary