3
sudo  iptables -A INPUT -p tcp  --sport 80 -j LOG --log-ip-options 

To check the format of iptables log info.

Feb  6 20:01:32 hwy kernel: [13004.628960] IN=eth0 OUT= MAC=00:30:40:50:40:d0:f8:32:e4:96:96:b4:08:00 SRC=183.232.24.111 DST=192.168.1.176 LEN=52 TOS=0x04 PREC=0x00 TTL=56 ID=48659 PROTO=TCP SPT=80 DPT=33751 WINDOW=114 RES=0x00 ACK FIN URGP=0 

How can i customize the format of iptables log info such as :

Feb  6 20:01:32 hwy kernel: [13004.628960] SRC=183.232.24.111 

Only source ip left in the log file.

3

You can't change the log format that is generated by iptables' LOG target. The format is fixed in the kernel xt_LOG module.

An alternative could be to use the NFLOG target, which sends the packet through a netlink socket to a multicast group. You then need a usespace process that subscribes to the group and processes the received packets to generate your required log format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.