1 | Network Management & Monitoring |
---|
2 | |
---|
3 | Using syslog-ng |
---|
4 | --------------- |
---|
5 | |
---|
6 | Notes: |
---|
7 | ------ |
---|
8 | * Commands preceded with "$" imply that you should execute the command as |
---|
9 | a general user - not as root. |
---|
10 | * Commands preceded with "#" imply that you should be working as root. |
---|
11 | * Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>") |
---|
12 | imply that you are executing commands on remote equipment, or within |
---|
13 | another program. |
---|
14 | |
---|
15 | Exercises |
---|
16 | --------- |
---|
17 | |
---|
18 | Please find your classmates that are using the same router as you. Get in to |
---|
19 | a group and do the following exercise together. That is, pick one person who will |
---|
20 | log in to your group's router, but all of you should assist with the actual |
---|
21 | configuration. |
---|
22 | |
---|
23 | 1. Configure your virtual routers to send syslog messages to your server: |
---|
24 | |
---|
25 | The routers are able to send syslog messages to multiple destinations, |
---|
26 | so that 1 router can send messages to 4 or even 5 destinations. |
---|
27 | We therefore need to configure the router to send messages to each of |
---|
28 | the PCs in the group. |
---|
29 | |
---|
30 | You will SSH to your group's router and do the following: |
---|
31 | |
---|
32 | $ ssh cisco@10.10.X.254 |
---|
33 | rtrX> enable |
---|
34 | rtrX# config terminal |
---|
35 | |
---|
36 | Repeat the next command "logging 10.10.X.X" for each PC in your group. That is, |
---|
37 | if your group is on router 6 and you are using pcs 21, 22, 23 and 24 you would |
---|
38 | repeat the command four times with the ip of each machine (10.10.6.21, |
---|
39 | 10.10.6.22, and so forth). |
---|
40 | |
---|
41 | rtrX# logging 10.10.X.X |
---|
42 | |
---|
43 | rtrX(config)# logging facility local0 |
---|
44 | rtrX(config)# logging userinfo |
---|
45 | rtrX(config)# exit |
---|
46 | rtrX# write memory |
---|
47 | |
---|
48 | Now run 'show logging' to see the summary of the logging configuration. |
---|
49 | |
---|
50 | rtrX# show logging |
---|
51 | |
---|
52 | Logout from the router (exit) |
---|
53 | |
---|
54 | rtrX# exit |
---|
55 | |
---|
56 | That's it. The router should now be sending UDP SYSLOG packets to your PC on port 514. |
---|
57 | To verify this log in on your PC and do the following: |
---|
58 | |
---|
59 | $ sudo -s |
---|
60 | # apt-get install tcpdump (don't worry if it's already installed) |
---|
61 | # tcpdump -e -s0 -ni eth0 port 514 |
---|
62 | |
---|
63 | Then have one person in your group log bck in on the router and do the following: |
---|
64 | |
---|
65 | $ ssh cisco@10.10.X.254 |
---|
66 | rtrX.ws.nsrc.org> enable |
---|
67 | rtrX.ws.nsrc.org# config terminal |
---|
68 | rtrX.ws.nsrc.org(config)# exit |
---|
69 | rtrX.ws.nsrc.org> exit |
---|
70 | |
---|
71 | You should see some output on your PC's screen from TCPDUMP. It should look something like: |
---|
72 | |
---|
73 | 02:20:24.942289 ca:02:0d:b3:00:08 > 52:54:4a:5e:68:77, ethertype IPv4 (0x0800), length 144: 10.10.0.6.63515 > 10.10.0.250.514: SYSLOG local0.notice, length: 102 |
---|
74 | 02:20:24.944376 ca:02:0d:b3:00:08 > c4:2c:03:0b:3d:3a, ethertype IPv4 (0x0800), length 144: 10.10.0.6.53407 > 10.10.0.241.514: SYSLOG local0.notice, length: 102 |
---|
75 | |
---|
76 | Now you can configure the logging softeware on your PC to receive this information and log |
---|
77 | it to a new set of files: |
---|
78 | |
---|
79 | |
---|
80 | 2. Install syslog-ng |
---|
81 | |
---|
82 | These exercises are done as root. If you are not root on your machine then become |
---|
83 | root by typing: |
---|
84 | |
---|
85 | $ sudo -s |
---|
86 | |
---|
87 | # apt-get install syslog-ng |
---|
88 | |
---|
89 | 2. Edit /etc/syslog-ng/syslog-ng.conf |
---|
90 | |
---|
91 | Find the lines: |
---|
92 | |
---|
93 | source s_src { |
---|
94 | system(); |
---|
95 | internal(); |
---|
96 | }; |
---|
97 | |
---|
98 | and change them to: |
---|
99 | |
---|
100 | source s_src { |
---|
101 | system(); |
---|
102 | internal(); |
---|
103 | udp(); |
---|
104 | }; |
---|
105 | |
---|
106 | Save the file and exit. |
---|
107 | |
---|
108 | Now, create a config section for our network logs: |
---|
109 | |
---|
110 | # cd /etc/syslog-ng/conf.d/ |
---|
111 | |
---|
112 | # editor 10-network.conf |
---|
113 | |
---|
114 | In this file, copy and paste the following: |
---|
115 | |
---|
116 | |
---|
117 | filter f_routers { facility(local0); }; |
---|
118 | |
---|
119 | log { |
---|
120 | source(s_src); |
---|
121 | filter(f_routers); |
---|
122 | destination(routers); |
---|
123 | }; |
---|
124 | |
---|
125 | destination routers { |
---|
126 | file("/var/log/network/$YEAR/$MONTH/$DAY/$HOST-$YEAR-$MONTH-$DAY-$HOUR.log" |
---|
127 | owner(root) group(root) perm(0644) dir_perm(0755) create_dirs(yes) |
---|
128 | template("$YEAR $DATE $HOST $MSG\n")); |
---|
129 | }; |
---|
130 | |
---|
131 | |
---|
132 | Save the file and exit. |
---|
133 | |
---|
134 | 3. Create the directory /var/log/network/ |
---|
135 | |
---|
136 | # mkdir /var/log/network/ |
---|
137 | |
---|
138 | 4. Restart syslog-ng: |
---|
139 | |
---|
140 | # service syslog-ng restart |
---|
141 | |
---|
142 | 5. Test syslog |
---|
143 | |
---|
144 | To be sure there are some logging messages log back in to the router, and run |
---|
145 | some "config" commands, then logout. e.g. |
---|
146 | |
---|
147 | # ssh cisco@10.10.X.254 |
---|
148 | rtrX> enable |
---|
149 | rtrX# config terminal |
---|
150 | rtrX(config)# exit |
---|
151 | rtrX> exit |
---|
152 | |
---|
153 | Be sure you log out of the router. If too many people log in without logging out |
---|
154 | then others cannot gain access to the router. |
---|
155 | |
---|
156 | 6. On your PC, See if messages are starting to appear under |
---|
157 | /var/log/network/2013/.../ |
---|
158 | |
---|
159 | $ cd /var/log/network |
---|
160 | $ ls |
---|
161 | $ cd 2013 |
---|
162 | $ ls |
---|
163 | ... this will show you the directory for the month |
---|
164 | ... cd into this directory |
---|
165 | $ ls |
---|
166 | ... repeat for the next level (the day of the month) |
---|
167 | $ ls |
---|
168 | |
---|
169 | Troubleshooting |
---|
170 | |
---|
171 | If no files are appearing under the /var/log/network directory, then |
---|
172 | another command to try while logged into the router, in config mode, is |
---|
173 | to shutdown / no shutdown a Loopback interface, for example: |
---|
174 | |
---|
175 | $ ssh cisco@rtrX |
---|
176 | |
---|
177 | rtrX> enable |
---|
178 | rtrX# conf t |
---|
179 | rtrX(config)# interface Loopback 999 |
---|
180 | rtrX(config-if)# shutdown |
---|
181 | |
---|
182 | wait a few seconds |
---|
183 | |
---|
184 | rtrX(config-if)# no shutdown |
---|
185 | |
---|
186 | Then exit, and save the config ("write mem"): |
---|
187 | |
---|
188 | rtrX(config-if)# exit |
---|
189 | rtrX(config)# exit |
---|
190 | rtrX# write memory |
---|
191 | rtr1# exit |
---|
192 | |
---|
193 | Check the logs under `/var/log/network` |
---|
194 | |
---|
195 | # cd /var/log/network |
---|
196 | # ls |
---|
197 | |
---|
198 | ...follow the directory trail |
---|
199 | |
---|
200 | Still no logs? |
---|
201 | |
---|
202 | Try the following command to send a test log message locally: |
---|
203 | |
---|
204 | # logger -p local0.info "Hello World\!" |
---|
205 | |
---|
206 | If a file has not been created yet under `/var/log/network`, then check your |
---|
207 | configuration for typos. Don't forget to restart the syslog-ng service each |
---|
208 | time you change the configuration. |
---|
209 | |
---|
210 | What other commands can you think of that you can run on the router |
---|
211 | (BE CAREFUL!) that will trigger syslog messages? You could try logging in |
---|
212 | on the router and typing an incorrect password for "enable". |
---|
213 | |
---|
214 | Be sure that you do an "ls" command in your logging directory to see if a new |
---|
215 | log file has been created at some point. |
---|
216 | |
---|