$ sudo -s
# editor /etc/rsyslog.d/30-routerlogs.conf
local0.* -?RouterLogs
... and add a new line below:
local0.* /var/log/network/everything
... this will enable logging of ALL messages to a single file, so that we can run a monitoring script on the messages.
# service rsyslog restart
grow too big:
# editor /etc/logrotate.d/everything
/var/log/network/everything {
daily
copytruncate
rotate 1
postrotate
/etc/init.d/swatch restart
endscript
}
# apt-get install swatch
# editor /etc/swatch.conf
watchfor /PRIV_AUTH_PASS/
mail=sysadm,subject=Enable mode entered
threshold type=limit,count=1,seconds=3600
watchfor /CONFIG_I/
mail=sysadm,subject=Router configuration
threshold type=limit,count=1,seconds=3600
watchfor /LINK/
mail=sysadm,subject=Link state change
threshold type=limit,count=1,seconds=3600
watchfor /SSH/
mail=sysadm,subject=SSH connection
threshold type=limit,count=1,seconds=3600
Save the file and exit
# swatch -c /etc/swatch.conf --daemon -t /var/log/network/everything
Check that it is running:
# ps ax | grep swatch
# telnet 10.10.X.254 [where "X" is your router number]
rtrX> enable
Password: <password>
rtrX# config terminal
rtrX(config)# int FastEthernet0/0
rtrX(config-if)# description Description Change for FastEthernet0/0 for Swatch
rtrX(config-if)# ctrl-z
rtrX# write memory
rtrX# exit
Just as in the previous exercise, attempt to shutdown / no shutdown a loopback interface
$ su - sysadmn
$ mutt -f /var/mail/sysadm
rtrX# conf t
rtrX(config)# access-list 123 deny tcp any host 10.10.X.254 eq 23 log
rtrX(config)# access-list 123 permit ip any any
rtrX(config)# interface fastEthernet 0/1
rtrX(config-if)# ip access-group 123 in
rtrX(config-if)# exit
rtrX(config)# exit
(remember, X is the number of your group)
Explanation: we are now filtering Telnet to the router, on the inside interface, explicitly, but we allow anything else. The "permit" statement is required or we will be disabling all IP access to the router!
From your PC:
$ telnet 10.10.X.254
Trying 10.10.X.254...
telnet: Unable to connect to remote host: No route to host
$
Notice that it says "No route to host" instead of "Connection refused"
This is because, although we have disabled Telnet already by enabling SSH on the routers, an active ACL will respond differently than a closed port (TCP RST vs. ICMP Host Unreachable)
Now look at the logfile:
$ tail /var/log/network/everything
Jun 2 13:46:14 rtrX 6133: *Jun 2 15:46:13.552: %SEC-6-IPACCESSLOGP: list 123 denied tcp 10.10.X.37(43523) -> 10.10.X.254(23), 1 packet
Hint: if your log is filled with "SSH-5-*" messages, ignore them like this:
$ grep -v SSH-5 /var/log/network/everything | tail
... you should see SEC-6-IPACCESSLOGP messages
# editor /etc/swatch.conf
Add the following lines
watchfor /SEC-6-IPACCESS/
mail=sysadm,subject=Blocked connection
threshold type=limit,count=1,seconds=3600
# ps ax |grep swatch | grep -v grep
\12345 ? Ss 0:00 /usr/bin/swatch -c /etc/swatch.conf --daemon -t /var/log/network/everything
The number on the LEFT is the number you need to kill - here 12345
# kill 12345 (the number YOU got!!)
# swatch -c /etc/swatch.conf --daemon -t /var/log/network/everything