Is there any posible way to log connections i mean time, src address, src port, destination address, destination port with ip tables?
Thankyou.
Is there any posible way to log connections i mean time, src address, src port, destination address, destination port with ip tables?
Thankyou.
Here is an example to log inbound tcp connections:
You should put it in the top of the chain to log all incoming tcp traffic.Code:iptables -A INPUT -p tcp -j LOG --log-prefix ' INPUT TCP ' --log-level 4
BTW, I think the easiest way to log all the stuff is to create a new chain:
Then instead of using ACCEPT, redirect all traffic that should be accepted to the INBOUND chain. For example:Code:iptables -N INBOUND
Then log and accept every connection on the INBOUND chain:Code:iptables -A INPUT -i eth0 -p tcp -m state --state ESTABLISHED,RELATED -j INBOUND
Code:iptables -A INBOUND -p tcp -j LOG --log-prefix ' INBOUND TCP ' --log-level 4 iptables -A INBOUND -p tcp -j ACCEPT
I guess you only want to log the initial connection rather than every packet. So I would suggest accepting packets on established connections without logging. Something like this:
Code:# Create a chain that logs new connections: iptables -N LOGNEW iptables -A LOGNEW -j LOG --log-prefix ' INBOUND TCP ' --log-level 4 iptables -A LOGNEW -j ACCEPT # Accept packets on existing connections without any fuss: iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT # Log incoming packets on new conections: iptables -A INPUT -p tcp -j LOGNEW
Code:iptables -I INPUT -m state --state NEW -j LOG --log-prefix "New Connection: " iptables -I OUTPUT -m state --state NEW -j LOG --log-prefix "New Connection: "![]()
I don't think NEW works for UDP packets. I think all packets will be logged in the UDP case. UDP are stateless. I checked my iptables script and it has UDP packets with a NEW flag. I'm not sure if the ESTABLISHED path even works for UDP. All UDP packets may go through the NEW path.
ICMP packets are generally stateless too.
Last edited by lensman3; May 14th, 2009 at 05:20 AM.
uljanow: you da man!![]()
Bookmarks