14

Using Nginx, Wordpress and Ubuntu 16.

I am constantly bombarded with these messages in kern.log , syslog and ufw.log

Nov 28 21:02:28 kernel: [246817.450026] [UFW BLOCK] IN=eth0 OUT= MAC=xx.xx SRC=122.3.133.77 DST=xx.xx LEN=60 TOS=0x00 PREC=0x00 TTL=53 ID=22334 DF PROTO=TCP SPT=45750 DPT=23 WINDOW=5808 RES=0x00 SYN URGP=0 
Nov 28 21:02:31 kernel: [246820.443191] [UFW BLOCK] IN=eth0 OUT= MAC=xx.xx SRC=122.3.133.77 DST=xx.xx LEN=60 TOS=0x00 PREC=0x00 TTL=53 ID=22335 DF PROTO=TCP SPT=45750 DPT=23 WINDOW=5808 RES=0x00 SYN URGP=0 
Nov 28 21:02:33 kernel: [246822.448520] [UFW BLOCK] IN=eth0 OUT= MAC=xx.xx SRC=195.154.181.110 DST=xx.xx LEN=40 TOS=0x00 PREC=0x00 TTL=246 ID=6401 PROTO=TCP SPT=52845 DPT=8709 WINDOW=1024 RES=0x00 SYN URGP=0 
Nov 28 21:02:37 kernel: [246826.438721] [UFW BLOCK] IN=eth0 OUT= MAC=xx.xx SRC=122.3.133.77 DST=xx.xx LEN=60 TOS=0x00 PREC=0x00 TTL=53 ID=22336 DF PROTO=TCP SPT=45750 DPT=23 WINDOW=5808 RES=0x00 SYN URGP=0 
Nov 28 21:03:26 kernel: [246875.605969] [UFW BLOCK] IN=eth0 OUT= MAC=xx.xx SRC=89.163.146.88 DST=xx.xx LEN=444 TOS=0x00 PREC=0x00 TTL=59 ID=45590 DF PROTO=UDP SPT=5149 DPT=5060 LEN=424 
Nov 28 21:03:41 kernel: [246890.099144] [UFW BLOCK] IN=eth0 OUT= MAC=xx.xx SRC=82.81.171.85 DST=xx.xx LEN=44 TOS=0x00 PREC=0x00 TTL=56 ID=19683 PROTO=TCP SPT=63561 DPT=2323 WINDOW=58193 RES=0x00 SYN URGP=0 
Nov 28 21:03:46 kernel: [246895.517766] [UFW BLOCK] IN=eth0 OUT= MAC=xx.xx SRC=94.102.49.174 DST=xx.xx LEN=40 TOS=0x00 PREC=0x00 TTL=249 ID=2066 PROTO=TCP SPT=51511 DPT=8000 WINDOW=1024 RES=0x00 SYN URGP=0 
Nov 28 21:03:49 kernel: [246898.714239] [UFW BLOCK] IN=eth0 OUT= MAC=xx.xx SRC=61.240.144.65 DST=xx.xx LEN=40 TOS=0x00 PREC=0x00 TTL=236 ID=31567 PROTO=TCP SPT=46807 DPT=8009 WINDOW=1024 RES=0x00 SYN URGP=0 
Nov 28 21:04:14 kernel: [246923.959948] [UFW BLOCK] IN=eth0 OUT= MAC=xx.xx SRC=163.172.91.185 DST=xx.xx LEN=40 TOS=0x08 PREC=0x00 TTL=243 ID=54321 PROTO=TCP SPT=47175 DPT=22 WINDOW=65535 RES=0x00 SYN URGP=0 
Nov 28 21:04:31 kernel: [246940.250298] [UFW BLOCK] IN=eth0 OUT= MAC=xx.xx SRC=78.168.185.115 DST=xx.xx LEN=40 TOS=0x00 PREC=0x00 TTL=51 ID=62125 PROTO=TCP SPT=52008 DPT=7547 WINDOW=13555 RES=0x00 SYN URGP=0 
  1. Since these are already logged in ufw.log how can i stop them from appearing at kern.log and syslog ?

  2. Is there something I must do to prevent these attacks or is this normal for a server to experience?

JoaMika
  • 499
  • 2
  • 9
  • 21

1 Answers1

19

UFW configuration option only toggles logging on/off (and alternatively specifies custom logging level):

logging on|off|LEVEL

toggle logging. Logged packets use the LOG_KERN syslog facility. Systems configured for rsyslog support may also log to /var/log/ufw.log. Specifying a LEVEL turns logging on for the specified LEVEL. The default log level is low.

If you are using standard Ubuntu installation, you have rsyslogd extension, which can be (and by default is) configured to generate these separated log files.

In Ubuntu 16.04, UFW logging configuration should be in /etc/rsyslog.d/20-ufw.conf:

# Log kernel generated UFW log messages to file
:msg,contains,"[UFW " /var/log/ufw.log

# Uncomment the following to stop logging anything that matches the last rule.
# Doing this will stop logging kernel generated UFW log messages to the file
# normally containing kern.* messages (eg, /var/log/kern.log)
#& ~

As the comment describes, you should just uncomment the last line. If there isn't one, just add & ~.

Contrariwise, commenting out the other configuration line causes logging only to syslog / kern.log.


2: Using a firewall to block attacks, as you already do, is the correct way to handle the situation.

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • 3
    Thanks this worked for me! Just a quick note that you need to restart rsyslog for it to take effect: sudo service rsyslog restart – jacklin May 20 '17 at 17:18
  • My copy of 20-ufw.conf has a "& stop" directive instead. Any significant difference? It doesn't log to syslog or kern.log anymore with that. – icelava Sep 24 '19 at 09:25
  • @icelava must be newer version, I have the same on Ubuntu 20.04. It has the same effect. – Jean Monet Dec 16 '20 at 23:49
  • another way to get rid of annoying UFW-BLOCK lines in your log is to whitelist which IPs you want to allow connection, and add a last rule "denying from any to any", then there will be no log entry, as suggested here https://askubuntu.com/a/1383632/1179344. – ferdymercury Feb 02 '22 at 00:45