You can use two iptables rules: The first to log the event; And the second to drop the packet.
Method 1, per port:
sudo iptables -A INPUT -p tcp --dport 25 -j LOG --log-prefix "EMAIL:" --log-level info
sudo iptables -A INPUT -p tcp --dport 25 -j DROP
sudo iptables -A INPUT -p udp --dport 33434 -j LOG --log-prefix "PORT33434:" --log-level info
sudo iptables -A INPUT -p udp --dport 33434 -j DROP
Method 2, multiport:
sudo iptables -A INPUT -p udp -m multiport --dport 33434:33448 -j LOG --log-prefix "MULTIUDP:" --log-level info
sudo iptables -A INPUT -p udp -m multiport --dport 33434:33448 -j DROP
sudo iptables -A INPUT -p tcp -m multiport --dport 23,2323 -j LOG --log-prefix "MULTITCP:" --log-level info
sudo iptables -A INPUT -p tcp -m multiport --dport 23,2323 -j DROP
The log entries will be in /var/log/syslog
. Example from my system for these rules (where I use a script, and it is a source port filter):
$IPTABLES -A INPUT -i $EXTIF -p tcp -m multiport --sport 80,443 -j LOG --log-prefix "BAD80:" --log-level info
$IPTABLES -A INPUT -i $EXTIF -p tcp -m multiport --sport 80,443 -j DROP
doug@s15:~$ grep BAD80 /var/log/syslog | head
Aug 1 00:02:17 s15 kernel: [456814.408209] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC=23.2.106.84 DST=173.180.45.4 LEN=44 TOS=0x08 PREC=0x20 TTL=52 ID=0 DF PROTO=TCP SPT=80 DPT=51602 WINDOW=64240 RES=0x00 ACK SYN URGP=0
Aug 1 00:08:37 s15 kernel: [457195.250598] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC=130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=26786 WINDOW=0 RES=0x00 RST URGP=0
Aug 1 00:08:40 s15 kernel: [457198.217675] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC=130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=18153 WINDOW=0 RES=0x00 RST URGP=0
Aug 1 00:09:02 s15 kernel: [457220.036071] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC=23.2.106.84 DST=173.180.45.4 LEN=44 TOS=0x08 PREC=0x20 TTL=52 ID=0 DF PROTO=TCP SPT=80 DPT=59130 WINDOW=64240 RES=0x00 ACK SYN URGP=0
Aug 1 00:09:08 s15 kernel: [457226.325411] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC=130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=24461 WINDOW=0 RES=0x00 RST URGP=0
Aug 1 00:15:34 s15 kernel: [457612.178539] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC=130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=31895 WINDOW=0 RES=0x00 RST URGP=0
Aug 1 00:16:54 s15 kernel: [457691.594480] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC=23.2.106.84 DST=173.180.45.4 LEN=44 TOS=0x08 PREC=0x20 TTL=52 ID=0 DF PROTO=TCP SPT=80 DPT=52192 WINDOW=64240 RES=0x00 ACK SYN URGP=0
Aug 1 00:22:29 s15 kernel: [458026.722346] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC=130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=20888 WINDOW=0 RES=0x00 RST URGP=0
Aug 1 00:23:12 s15 kernel: [458069.616810] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC=23.2.106.84 DST=173.180.45.4 LEN=44 TOS=0x08 PREC=0x20 TTL=52 ID=0 DF PROTO=TCP SPT=80 DPT=52324 WINDOW=64240 RES=0x00 ACK SYN URGP=0
Aug 1 00:23:35 s15 kernel: [458093.252954] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC=130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=20218 WINDOW=0 RES=0x00 RST URGP=0
See this old answer for help with understanding the log entries.