树莓派玩机笔记(四)获取公网地址

本文介绍了如何在Linux系统上安装配置Postfix邮件服务器,并通过编写shell脚本实现自动获取并发送当前系统的公网IP地址到指定邮箱。此外,还展示了如何设置定时任务来定期执行该脚本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

感谢CCTV,感谢MTV,感谢高主任帮我写的脚本。

原文刊载于高主任cu论坛-http://blog.chinaunix.net/uid-25256412-id-4228235.html

 

1>: 安装配置postfix

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# apt-get install postfix   (安装postfix)
或:
# aptitude install postfix
# echo 'www.yes4ko.com' >/etc/hostname   (修改主机名)
# echo 'X.X.X.X www.yes4ko.com www' >> /etc/hosts
# echo 'X.X.X.X ftp.yes4ko.com ftp' >> /etc/hosts
# vim /etc/postfix/main.cf
myhostname = www.yes4ko.com            (主机名FQDN)
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = yes4ko.com                    (发件人地址)
mydestination = www.yes4ko.com, localhost.localdomain    (允许收件的主机)
relayhost =                       (由于是非公网domain,需要由上游ISP MTA帮忙送信,置空即可!)
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 hash:/etc/postfix/access    (只允许这些地址使用postfix)
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
relay_domains = yes4ko.com, localhost
:wq
# vim /etc/postfix/access
.yes4ko.com  OK            (允许此domain使用postfix)
X.X.X.       REJECT        (拒绝X.X.X.0/24使用postfix)
:wq
# postalias hash:/etc/aliases        (重新生成)
# postmap hash:/etc/postfix/access
# /etc/init.d/postfix reload  (重新加载配置文件)
# /etc/init.d/postfix check   (检查 postfix 相关的配置文件)
# /etc/init.d/postfix start   (运行 postfix 服务)
# /etc/init.d/postfix stop    (停止 postfix 服务)
# /usr/sbin/postqueue -p        (查看邮件队列排队的邮件)
或:
# mailq
# /etc/init.d/postfix flush   (强制将目前正在邮件队列排队的邮件寄出)

 

2>: 自动获取公网地址

 

1
2
3
4
5
6
7
8
9
# vim /usr/sbin/getPubIP.sh        (编写脚本取得公网IP并mail至相关邮箱)
#!/bin/sh
#Program: save as /usr/sbin/getPubIP.sh
#
DATE=$(date +'%Y-%m-%d %H:%M:%S')
curl ifconfig.me/ip > getip.txt 2>&1
echo $DATE >> getip.txt
tail -2 getip.txt| mail -s 'Today's Public IP Addr' none@none.com
:wq

 

3>: 配置 routine

 

1
# echo '07 */1 * * * root /usr/sbin/getPubIP.sh' >> /etc/crontab (每间隔1小时执行一次该脚本)

 

4>: Reserved for future use....

5>: Reserved for future use....

6>: Reserved for future use....

7>: Reserved for future use....


More About Debian :  http://bbs.chinaunix.net/thread-3751791-1-1.html
More About Postfix: http://www.postfix.org/STANDARD_CONFIGURATION_README.html#null_client

本文转自文东会博客51CTO博客,原文链接http://blog.51cto.com/hackerwang/1404858如需转载请自行联系原作者


谢文东666

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值