Skip to contentSkip to conversation

private to public IP

DISCUSSION Wennie V. Lagmay 3 participants 6 messages Jul 2, 2006 – Jul 3, 2006

lore
Share & tools
lore
#0 lore raw

Hi all,
I want to create a log on Iptables wherein to store and to identify which private Ip is connected on public Ip on a certain date and time. Can you help me on this

Thanks,

Wennie

#1 lore raw

Dnia 02-07-2006, nie o godzinie 14:35 +0300, Wennie V. Lagmay napisa³(a):

Quoted 10 lines

Hi all,
I want to create a log on Iptables wherein to store and to identify which private Ip is connected on public Ip on a certain date and time. Can you help me on this

Thanks,

Wennie

the easiest way:

iptables -I FORWARD -s PRIVATE_IP -m state --state NEW \
-j LOG --log-level info

robee

#2 lore raw

Hi Robee,

Thank you very much for your reply, just want to confirn something.

1. Based on the script you've sent to me does it mean that I have to input all my private subnets example

iptables -I  FORWARD  -s 192.168.1.0/24 -m state --state NEW -j LOG --log-level info
iptables -I  FORWARD  -s 192.168.2.0/24 -m state --state NEW -j LOG --log-level info
iptables -I  FORWARD  -s 192.168.3.0/24 -m state --state NEW -j LOG --log-level info
iptables -I  FORWARD  -s 192.168.4.0/24 -m state --state NEW -j LOG --log-level info

and so on

2. With this script I can identify a certain Private IP, which public IP address it use and which remote IP it is connected? example

Private IP = 192.168.2.56
Public IP = 203.174.11.8
Remote IP = 65.67.87.9 (www.yahoo.com)

3. Are all the log are stored in /var/log/messages?

Thank you very much for you support,

Wennie

----- Original Message ----- From: "robee" <[email protected]>
To: <[email protected]>
Sent: Sunday, July 02, 2006 7:03 PM
Subject: Re: private to public IP

Dnia 02-07-2006, nie o godzinie 14:35 +0300, Wennie V. Lagmay napisa³(a):

Quoted 10 lines

Hi all,
I want to create a log on Iptables wherein to store and to identify which private Ip is connected on public Ip on a certain date and time. Can you help me on this

Thanks,

Wennie

the easiest way:

iptables -I FORWARD -s PRIVATE_IP -m state --state NEW \
-j LOG --log-level info

robee

#3 lore raw
Quoted 6 lines · Wennie V. Lagmay

Hi Robee,

Thank you very much for your reply, just want to confirn something.

Quoted 11 lines

1. Based on the script you've sent to me does it mean that I have to input all my private subnets example
iptables -I FORWARD -s 192.168.1.0/24 -m state --state NEW -j LOG --log-level info
iptables -I FORWARD -s 192.168.2.0/24 -m state --state NEW -j LOG --log-level info
iptables -I FORWARD -s 192.168.3.0/24 -m state --state NEW -j LOG --log-level info
iptables -I FORWARD -s 192.168.4.0/24 -m state --state NEW -j LOG --log-level info
and so on

Yes. But you can script that to save yourself some work if you have a lot or these.
You do know that when you are using "-I" that you are inserting the rules on top of each other, instead of appending them..? In this case it doesn't matter but you may get unexpected results if you are not aware of it.

Quoted 6 lines

2. With this script I can identify a certain Private IP, which public IP address it use and which remote IP it is connected? example

Private IP = 192.168.2.56
Public IP = 203.174.11.8
Remote IP = 65.67.87.9 (www.yahoo.com)

No. Only the source (private) IP and the remote (destination) IP (and more, like [s|d]port, etc). A logging line would look something like this:

Jul  3 12:55:35 fw INPUT:  IN=eth0 OUT=

MAC=00:a0:27:a0:6b:00:00:b0:d0:db:aa:3a:08:00 SRC=60.11.125.36 DST=1.2.3.4 LEN=485 TOS=00 PREC=0x00 TTL=40 ID=0 DF PROTO=UDP SPT=40867 DPT=1026 LEN=465

Jul  3 12:55:35 fw INPUT:  IN=eth0 OUT=

MAC=00:a0:27:a0:6b:00:00:b0:d0:db:aa:3a:08:00 SRC=60.11.125.36 DST=1.2.3.4 LEN=485 TOS=00 PREC=0x00 TTL=40 ID=0 DF PROTO=UDP SPT=40867 DPT=1027 LEN=465

(This is a DROP rule in the INPUT chain so there's no private source IP.)

Quoted 1 line

3. Are all the log are stored in /var/log/messages?

That depends on your syslog config. Normally, I think: yes.
If you want to log more specific, you can setup ulogd and use the ULOG target.

Gr,
Rob

#4 lore raw

Thanks you very much Rob, I will take note that It is better to use -A rather than -I on this situation, however I have a follow up question.what is the difference between implemeting these rules on FOWRARD chain, rather than POSTROUTING and is it important to put DROP after the rules?

Wennie

----- Original Message ----- From: "Rob Sterenborg" <[email protected]>
To: <[email protected]>
Sent: Monday, July 03, 2006 2:17 PM
Subject: Re: private to public IP

Quoted 6 lines · Wennie V. Lagmay

Hi Robee,

Thank you very much for your reply, just want to confirn something.

Quoted 11 lines

1. Based on the script you've sent to me does it mean that I have to input all my private subnets example
iptables -I FORWARD -s 192.168.1.0/24 -m state --state NEW -j LOG --log-level info
iptables -I FORWARD -s 192.168.2.0/24 -m state --state NEW -j LOG --log-level info
iptables -I FORWARD -s 192.168.3.0/24 -m state --state NEW -j LOG --log-level info
iptables -I FORWARD -s 192.168.4.0/24 -m state --state NEW -j LOG --log-level info
and so on

Yes. But you can script that to save yourself some work if you have a lot or these.
You do know that when you are using "-I" that you are inserting the rules on top of each other, instead of appending them..? In this case it doesn't matter but you may get unexpected results if you are not aware of it.

Quoted 6 lines

2. With this script I can identify a certain Private IP, which public IP address it use and which remote IP it is connected? example

Private IP = 192.168.2.56
Public IP = 203.174.11.8
Remote IP = 65.67.87.9 (www.yahoo.com)

No. Only the source (private) IP and the remote (destination) IP (and more, like [s|d]port, etc). A logging line would look something like this:

Jul  3 12:55:35 fw INPUT:  IN=eth0 OUT=

MAC=00:a0:27:a0:6b:00:00:b0:d0:db:aa:3a:08:00 SRC=60.11.125.36 DST=1.2.3.4 LEN=485 TOS=00 PREC=0x00 TTL=40 ID=0 DF PROTO=UDP SPT=40867 DPT=1026 LEN=465

Jul  3 12:55:35 fw INPUT:  IN=eth0 OUT=

MAC=00:a0:27:a0:6b:00:00:b0:d0:db:aa:3a:08:00 SRC=60.11.125.36 DST=1.2.3.4 LEN=485 TOS=00 PREC=0x00 TTL=40 ID=0 DF PROTO=UDP SPT=40867 DPT=1027 LEN=465

(This is a DROP rule in the INPUT chain so there's no private source IP.)

Quoted 1 line

3. Are all the log are stored in /var/log/messages?

That depends on your syslog config. Normally, I think: yes.
If you want to log more specific, you can setup ulogd and use the ULOG target.

Gr,
Rob

#5 lore raw
Quoted 4 lines · Wennie V. Lagmay

Thanks you very much Rob, I will take note that It is better to use -A rather than -I on this situation, however I have a follow up question.what is the difference between implemeting these rules on FOWRARD chain, rather than POSTROUTING and is it important to put DROP after the rules?

If we're only talking about LOG rules then just use the FORWARD chain with "-m state --state NEW". I don't think that, in this case, it differs much because the only thing you want to do is to log and the information would be the same (I didn't try, but of course you are free to do so).

You say you only want to log what source IP is connected to which destination IP, not that you also want to DROP it. So, you don't want to use the DROP target as those packets would get DROPped and a connection cannot be made. AFAIK you cannot see what public IP it used, but if you used SNAT and/or have only 1 public IP, you already know that.
The log output I showed is an example only and is recorded in the INPUT chain just before the packets are dropped: it has nothing to do with your situation.

You can find more information in Oskars iptables tutorial. I posted the link in a previous post.

Gr,
Rob