您的位置:首页 > 其它

ssh ip change

2018-02-20 19:50 162 查看
https://www.v2ex.com/t/139986
http://blog.csdn.net/nolan__roronoa/article/details/52335223 http://blog.csdn.net/rongku/article/details/50402314

1. 163 turn on smtp service (login into email box to set up)
see pic from https://www.cnblogs.com/bass6/p/5544265.html
and

blog.csdn.net/nolan__roronoa/article/details/52335223

2. install msmtp (mailPassword, use 授权码 given by the step 1.)
sudo apt-get install msmtp
(1) 在/etc目录下创建msmtprc的配置文件/etc/msmtprc(msmtprc文件默认是没有的,要自己创建)
sudo vi msmtprc
#Accounts will inherit settings from this section
defaults

account    163
host       smtp.163.com
port       25
from       lin_eyun@163.com
auth       login
tls          off
user       lin_eyun@163.com
password   mailPassword
logfile     /var/log/msmtp.log
# Set a default account
account default : 163
(2) 创建上述配置的日志文件
sudo touch /var/log/msmtp.log

为了让所有用户都能读写这个日志文件,我们将其权限设置为777
sudo chmod 777 /var/log/msmtp.log
(3) 创建~/.msmtprc文件
vi  .msmtprc
defaults
account  163
host  smtp.163.com
port  25
from  lin_eyun@163.com
auth plain
user lin_eyun@163.com
password  mailPassword
account default:163
logfile ~/.msmtp.log

由于password是明文,所以需要修改此文件的访问权限,以下设置是只给.msmtprc的所属用户读和写的权限,其他人没有任何权限

sudo chmod 600 .msmtprc

(4) 创建上述配置中的log文件touch ~/.msmtp.log
(5) test of sending an email:
msmtp lin_eyun@163.com
test
键Ctrl+d

3. install mutt,

sudo apt-get install mutt
'Postfix configuration'界面,键盘点击箭头->使光标移到ok,点enter
“General type of mailconfiguration”中选择第三个”mail sent by smarthost;no localmail”,然后依次配置下去,在”Ip address or host name of the outgoingsmarthost”中,填入smtp.163.com等类似的smtp服务器地址,然后,其他的就很简单了(http://blog.sina.com.cn/s/blog_9ada6acf0100yh2d.html)
配置 mutt,系统全局设置配置文件在 /etc/Muttrc,如果使用某个系统用户,可以在~/.muttc中设置,没有该文件,就自己创建。
编辑 sudo vi Muttrc
在Muttrc文件最后添加以下内容
set sendmail="/usr/bin/msmtp"
set use_from=yes
set realname="eyun"
set from=lin_eyun@163.com
set envelope_from=yes
4. 测试邮件发送
echo "test" |mutt -s "my_first_test" lin_eyun@163.com

5. cron
installed by default of ubuntu https://www.linuxidc.com/Linux/2015-08/121087.htm
6. 弄了一个守护进程,每分钟检查一下ip
4000
有没有变,如果变了就把新ip以邮件形式发到我邮箱里,实现的依赖:msmtp,mutt,cron。首先要把邮件配置好。ifconfig查看本机ip, 看本机对应的是eth0/ppp0/wlp3s0/等。
具体的实现脚本:#!/bin/bash
IPADDRESS=$(ifconfig eth0 | sed -n 's/.*inet addr:\([^ ]*\).*/\1/p')

echo "Last check at: $(date)" >> updateip.log

if [[ "${IPADDRESS}" != $(cat ~/.current_ip) ]];then
if echo "${IPADDRESS}" | mutt -s "new ip" myemail@com ;then
echo "Ip change from $(cat ~/.current_ip) to ${IPADDRESS}" >> updateip.log
echo ${IPADDRESS} > ~/.current_ip
else
echo "Failed to send the mail, try again later." >> updateip.log
fi
fi

保存在~/bin/unpdateip.sh

然后在/etc/crontab文件最后加上一行:

* * * * * <user> bash ~/bin/updateip.sh
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: