1 | PacNOG 10 |
---|
2 | Track 2 |
---|
3 | |
---|
4 | Postfix exercise |
---|
5 | ---------------- |
---|
6 | |
---|
7 | Notes |
---|
8 | ------ |
---|
9 | |
---|
10 | * Commands preceded with "$" imply that you should execute the command as |
---|
11 | a general user - not as root. |
---|
12 | * Commands preceded with "#" imply that you should be working as root using |
---|
13 | "sudo" |
---|
14 | * Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>") |
---|
15 | imply that you are executing commands on remote equipment, or within |
---|
16 | another program. |
---|
17 | |
---|
18 | |
---|
19 | 0. First, let's install postfix |
---|
20 | |
---|
21 | $ sudo -s |
---|
22 | |
---|
23 | # apt-get install postfix |
---|
24 | |
---|
25 | When asked what kind of configuration, choose: "Internet site" |
---|
26 | |
---|
27 | We'll also need telnet to manually connect to the port 25 |
---|
28 | |
---|
29 | # apt-get install telnet |
---|
30 | |
---|
31 | And, we'll also need a simple mail program to read the mail we receive, |
---|
32 | so let's install "mutt": |
---|
33 | |
---|
34 | # apt-get install mutt |
---|
35 | |
---|
36 | 1. Make sure that postfix is running: |
---|
37 | |
---|
38 | # ps ax | grep postfix |
---|
39 | |
---|
40 | You should see the "master" process for postfix running |
---|
41 | |
---|
42 | 2. Make sure your neighbour has started postfix, too, and try to send a mail |
---|
43 | manually via their machine. If you are pcX, and they are pcY, you will |
---|
44 | run "telnet pcY 25". |
---|
45 | |
---|
46 | Replace "myemailaddress@at.home" with your real email address. What YOU |
---|
47 | type is marked with -> (DON'T type "->", this is just to point the |
---|
48 | lines!). Remember to replace X and Y with the number of your PC and |
---|
49 | your neighbor's respectively. |
---|
50 | |
---|
51 | |
---|
52 | -> root@pcX:~# telnet pcY 25 |
---|
53 | Trying 10.10.0.Y... |
---|
54 | Connected to pcY.ws.nsrc.org. |
---|
55 | Escape character is '^]'. |
---|
56 | 220 pcY.ws.nsrc.org ESMTP Postfix (Ubuntu) |
---|
57 | -> HELO pcX.ws.nsrc.org |
---|
58 | 250 pctest.ws.nsrc.org |
---|
59 | -> MAIL From: <sysadm@pcX.ws.nsrc.org> |
---|
60 | 250 2.1.0 Ok |
---|
61 | -> RCPT To: <myemailaddress@at.home> |
---|
62 | 554 5.7.1 <myemailaddress@at.home>: Relay access denied |
---|
63 | |
---|
64 | |
---|
65 | Notice that your mail is rejected. Why ? |
---|
66 | |
---|
67 | Now, try and send mail to the sysadm user on pcY: |
---|
68 | |
---|
69 | -> root@pcX:~# telnet pcY 25 |
---|
70 | Trying 10.10.0.90... |
---|
71 | Connected to pcY.ws.nsrc.org. |
---|
72 | Escape character is '^]'. |
---|
73 | 220 pcY.ws.nsrc.org ESMTP Postfix (Ubuntu) |
---|
74 | -> HELO pcX.ws.nsrc.org |
---|
75 | 250 pcY.ws.nsrc.org |
---|
76 | -> MAIL From: <sysadm@pcX.ws.nsrc.org> |
---|
77 | 250 2.1.0 Ok |
---|
78 | -> RCPT To: <sysadm@pcY.ws.nsrc.org> |
---|
79 | 250 2.1.5 Ok |
---|
80 | -> DATA |
---|
81 | 354 End data with <CR><LF>.<CR><LF> |
---|
82 | -> Subject: A test mail for pcY |
---|
83 | -> From: sysadm@pcX.ws.nsrc.org |
---|
84 | -> To: sysadm@pcY.ws.nsrc.org |
---|
85 | -> |
---|
86 | -> Hello! |
---|
87 | -> . |
---|
88 | 250 2.0.0 Ok: queued as 818D07FE9C |
---|
89 | -> quit |
---|
90 | 221 2.0.0 Bye |
---|
91 | |
---|
92 | Repeat this with 2-3 difference neighbors around you. |
---|
93 | |
---|
94 | 3. If the above worked, your neighbor should have received mail. |
---|
95 | |
---|
96 | To check it, ask your neighbor, as the sysadm user, to run the "mutt" |
---|
97 | command: |
---|
98 | |
---|
99 | $ mutt |
---|
100 | |
---|
101 | (if it asks you to create "/home/sysadm/Mail", say 'yes') |
---|
102 | |
---|
103 | You are now using "mutt", a simple mail client. You can use the arrows |
---|
104 | to move up and down, and press <RETURN> on a mail you want to read. |
---|
105 | |
---|
106 | You should be able to see the mail you sent to the sanog user. |
---|
107 | |
---|
108 | To quit: press 'q', and 'q' again to leave the program. |
---|
109 | |
---|
110 | Note: If you are lost, you can always press the '?' key to get help |
---|
111 | on using mutt. |
---|
112 | |
---|
113 | Your neighbor should see one mail in the index - press SPACE or RETURN to |
---|
114 | see it. |
---|
115 | |
---|
116 | If they don't see the mail, double check that you sent the mail to the |
---|
117 | right PC! |
---|
118 | |
---|
119 | To quit, press i (index), then q (quit) or x (exit). |
---|
120 | |
---|
121 | You should check now, that YOU have received mail from one of your |
---|
122 | neighbors! |
---|
123 | |
---|
124 | 4. You saw in step 2 that you could only send mail to the local domain of the |
---|
125 | pcY when you connected to it with telnet. What if we want to use a mail |
---|
126 | server so that you can send mail to OTHER domains, on the internet ? |
---|
127 | |
---|
128 | Let's make some small changes to the config file for postfix, so that you |
---|
129 | can do this: |
---|
130 | |
---|
131 | # cd /etc/postfix/ |
---|
132 | |
---|
133 | # editor main.cf |
---|
134 | |
---|
135 | Take a look at some of the parameters, especially the last section, and |
---|
136 | find the line: |
---|
137 | |
---|
138 | mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 |
---|
139 | |
---|
140 | ... and add this to the end of it: |
---|
141 | |
---|
142 | 10.10.0.0/24 |
---|
143 | |
---|
144 | ... so that the line becomes: |
---|
145 | |
---|
146 | mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 10.10.0.0/24 |
---|
147 | |
---|
148 | Save and quit, and check the configuration: |
---|
149 | |
---|
150 | # postfix check |
---|
151 | |
---|
152 | 5. Restart postfix, and check that mail is working: |
---|
153 | |
---|
154 | # service postfix restart |
---|
155 | |
---|
156 | # ps ax | grep postfix |
---|
157 | |
---|
158 | 6. Ok, now we're going to send a mail to the outside world, using your |
---|
159 | neighbor's PC again, like we tried before in step 2 (to |
---|
160 | myemailaddress@at.home): |
---|
161 | |
---|
162 | -> root@pcX:~# telnet pcY 25 |
---|
163 | Trying 10.10.0.Y... |
---|
164 | Connected to pcY.ws.nsrc.org. |
---|
165 | Escape character is '^]'. |
---|
166 | 220 pcY.ws.nsrc.org ESMTP Postfix (Ubuntu) |
---|
167 | -> HELO pcX.ws.nsrc.org |
---|
168 | 250 pctest.ws.nsrc.org |
---|
169 | -> MAIL From: <sysadm@pcX.ws.nsrc.org> |
---|
170 | 250 2.1.0 Ok |
---|
171 | -> RCPT To: <myemailaddress@at.home> |
---|
172 | 250 2.1.5 Ok |
---|
173 | -> DATA |
---|
174 | 354 End data with <CR><LF>.<CR><LF> |
---|
175 | -> Subject: A test mail for myself at home |
---|
176 | -> From: sysadm@pcX.ws.nsrc.org |
---|
177 | -> To: myemailaddress@at.home |
---|
178 | -> |
---|
179 | -> Hello to myself! |
---|
180 | -> . |
---|
181 | 250 2.0.0 Ok: queued as 3BC377FE9E |
---|
182 | |
---|
183 | 7. Check your mail at home (or Gmail, or hotmail, or whatever you use...) and |
---|
184 | check that you received the mail. Did you ? |
---|
185 | |
---|
186 | Either way, ask your neighbor to run: |
---|
187 | |
---|
188 | $ tail /var/log/mail.log |
---|
189 | |
---|
190 | You should see something like: |
---|
191 | |
---|
192 | Nov 23 21:32:16 pctest postfix/smtpd[32174]: connect from noc.ws.nsrc.org[10.10.0.250] |
---|
193 | Nov 23 21:32:48 pctest postfix/smtpd[32174]: 3BC377FE9E: client=noc.ws.nsrc.org[10.10.0.250] |
---|
194 | Nov 23 21:32:53 pctest postfix/cleanup[32178]: 3BC377FE9E: message-id=<> |
---|
195 | Nov 23 21:32:53 pctest postfix/qmgr[32144]: 3BC377FE9E: from=<sysadm@pc3.ws.nsrc.org>, size=223, nrcpt=1 (queue active) |
---|
196 | Nov 23 21:32:53 pctest postfix/smtpd[32174]: disconnect from noc.ws.nsrc.org[10.10.0.250] |
---|
197 | Nov 23 21:32:57 pctest postfix/smtp[32179]: 3BC377FE9E: to=<regnauld@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.53.27]:25, delay=14, delays=10/0.02/2.7/1.6, dsn=2.0.0, status=sent (250 2.0.0 OK 1322083977 h3si4968239pbm.236) |
---|
198 | Nov 23 21:32:57 pctest postfix/qmgr[32144]: 3BC377FE9E: removed |
---|
199 | |
---|
200 | ... do you see your mail there ? |
---|
201 | |
---|
202 | 9. Try to send mail again like in step 6, but try something different for the |
---|
203 | MAIL From: <sysadm@nonexist.ws.nsrc.org>. Does it work ? Why ? |
---|
204 | |
---|
205 | 10. We're going to send mail again, but this time we're going to use the "mutt" |
---|
206 | command: |
---|
207 | |
---|
208 | (as sysadm) |
---|
209 | # su - sysadm |
---|
210 | $ echo "testing mail" | mail -s "test" sysadm@pcY.ws.nsrc.org |
---|
211 | $ tail /var/log/mail.log |
---|
212 | |
---|
213 | You should see something like this: |
---|
214 | |
---|
215 | Nov 23 21:23:31 pcX postfix/pickup[32143]: 76DB67FE9E: uid=1000 from=<sysadm> |
---|
216 | Nov 23 21:23:31 pcX postfix/cleanup[32166]: 76DB67FE9E: message-id=<20111123212331.GA32155@pcX.ws.nsrc.org> |
---|
217 | Nov 23 21:23:31 pcX postfix/qmgr[32144]: 76DB67FE9E: from=<sysadm@pcX.ws.nsrc.org>, size=438, nrcpt=1 (queue active) |
---|
218 | Nov 23 21:23:31 pcX postfix/smtp[32168]: 76DB67FE9E: to=<sysadm@pcY.ws.nsrc.org>, relay=pcY.ws.nsrc.org[10.10.0.250]:25, delay=0.48, delays=0.29/0.01/0.07/0.1, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as F21281FF72) |
---|
219 | Nov 23 21:23:31 pcX postfix/qmgr[32144]: 76DB67FE9E: removed |
---|
220 | |
---|
221 | 11. Ask your neighbor to read the mail he should have received! |
---|
222 | |
---|
223 | Note: do this as the "sysadm" user! |
---|
224 | |
---|
225 | $ mutt |
---|
226 | |
---|
227 | (again, if mutt asks you |
---|
228 | |
---|
229 | /home/sysadm/Mail does not exist. Create it? ([yes]/no): |
---|
230 | |
---|
231 | ... answer 'yes') |
---|
232 | |
---|
233 | 12. Let's modify the /etc/aliases file, so we can receive mail for |
---|
234 | other system users into our mailbox: |
---|
235 | |
---|
236 | (As root!) |
---|
237 | |
---|
238 | # editor /etc/aliases |
---|
239 | |
---|
240 | Add the line: |
---|
241 | |
---|
242 | root: sanog |
---|
243 | |
---|
244 | root: sysadm |
---|
245 | |
---|
246 | Exit & save the file, and run the "newaliases" command: |
---|
247 | |
---|
248 | # newaliases |
---|
249 | |
---|
250 | |
---|
251 | 13. Try sending mails to the "postmaster" and "root" users on your PC: |
---|
252 | |
---|
253 | # su - sysadm |
---|
254 | $ echo "test to postmaster" | mutt -s "test postmaster" postmaster@localhost |
---|
255 | $ echo "test to root" | mutt -s "test root" root@localhost |
---|
256 | |
---|
257 | Send another mail but this time, to postmaster@pcX.ws.nsrc.org (your PC:) |
---|
258 | |
---|
259 | $ echo "test to postmaster" | mail -s "test postmaster" postmaster@pcX.ws.nsrc.org |
---|
260 | |
---|
261 | Notice how both work (use mutt, check the /var/log/mail.log) |
---|
262 | |
---|
263 | Check that you received these mails |
---|
264 | |
---|
265 | $ mutt |
---|
266 | |
---|
267 | Check that all mails have been received |
---|
268 | |
---|
269 | 14. Reading headers |
---|
270 | |
---|
271 | While in mutt, look at a mail, then press the 'h' key -- while displaying |
---|
272 | a mail, this will toggle between showing "full" headers, and limited |
---|
273 | headers. |
---|
274 | |
---|
275 | Use this feature to inspect the mails in your mailbox. |
---|
276 | |
---|
277 | Note the "To:" and "X-Original-To:" headers. |
---|
278 | |
---|
279 | |
---|
280 | 15. Send mail to other users in the class! |
---|
281 | |
---|
282 | Since you were able to send mail to your OWN machine, then you can also |
---|
283 | send mails to other users in the class: |
---|
284 | |
---|
285 | $ echo "hello from pcX" | mail -s "mail from pcX" sysadm@pcY.ws.nsrc.org |
---|
286 | $ echo "hello from pcX" | mail -s "mail from pcX" sysadm@pxZ.ws.nsrc.org |
---|
287 | |
---|
288 | |
---|
289 | etc... |
---|
290 | |
---|