问题原文
原帖链接 · RedScourge · CC BY-SA 4.0
Is there a way to alter the Logwatch settings such that it stops performing reverse dns name resolution on all the hosts which tried to probe the server or were blocked?
These URLs are causing the emails to be blocked, particularly by Gmail, and thereby making Logwatch unusable as a sysadmin tool.
I'd prefer an answer which uses pre-existing config files on Ubuntu or Debian but I'll take whatever I can get.
已采纳解答
原帖链接 · MDMower · CC BY-SA 4.0
This answer is heavily inspired by @RedScourge's original answer, but disables LookupIP via config and makes minimally invasive changes to the sshd script only if necessary.
In response to a user asking about the ability to selectively disable hostname hostname lookups for certain services, a patch was committed to logwatch that enables this feature for SSHD. As of this writing, the patch is not part of a tagged release, but it is easy to apply locally. As an added bonus, this speeds up log generation significantly if there are lots of SSH attempts on your server.
Step 1: Make sure flag sshd_ip_lookup is handled by your local version of logwatch.
Open
/usr/share/logwatch/scripts/services/sshdand search forsshd_ip_lookup.If you don't find any references to this flag, then...
a. Copy
sshdscript to/etcso that it won't be overwritten iflogwatchis updatedsudo cp /usr/share/logwatch/scripts/services/sshd /etc/logwatch/scripts/services/sshdb. Open
/etc/logwatch/scripts/services/sshdwith your preferred editorsudo nano /etc/logwatch/scripts/services/sshdc. Modify script with changes from this commit.
i.e. paste the following, just beforemy $DebugCounter = 0;(or anywhere near the top):$main::DoLookup = $ENV{'sshd_ip_lookup'};
Step 2: Set flag sshd_ip_lookup to No
- Create/Open
/etc/logwatch/conf/services/sshd.confusing your preferred editor. - Add the following contents:
# Set to No to disable IP lookups $sshd_ip_lookup = No
Try running logwatch again!
Addendum: Google Mail (GMail) spam detection
I experienced Google blocking logwatch emails as well. They never made it to the recipient's spam folder; Google blocked the email on the way out. @RedScourge's analysis that this is due to the large number of domain names in the logwatch report appears correct. The email must look like it's full of URLs to Google's spam filters.
I believe there is a correlation between IP addresses that Google Mail links when displaying an email and those that its spam filter considers a link before an email is sent. I noticed that Google Mail linked the IP in 123.123.123.123: X Time(s) but it did not link the IP in 123.123.123.123 : X Time(s). With this in mind, I included a space after the IP and before the colon in the "Negotiation failed" and "Illegal users from" sections. Since doing this – a few weeks ago, now – I have not had any logwatch emails blocked by Google Mail.
The changes to /etc/logwatch/scripts/services/sshd include:
- Within section
if (keys %NegotiationFailed) { ... }, modify:
to:print " $Host: " . timesplural($HostTotal);print " $Host : " . timesplural($HostTotal); - Within section
if (keys %IllegalUsers) { ... }, modify:
to:print " $name: " . timesplural($totcount);print " $name : " . timesplural($totcount);
A gist showing these changes is available here.
Notes
I've submitted a wishlist request to add the upstream logwatch patch to LTS releases of Ubuntu. I'm not sure that it will be approved, but you can subscribe to it here to track its status: https://bugs.launchpad.net/ubuntu/+source/logwatch/+bug/1904362
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
