惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - CalvinChu

vyos syslog配置 How to upgrade pip on Debian Wheezy 指数数据解密,懂的都懂 OpenWRT and VPN Passthrough - CalvinChu 如何将 find 命令与 exec 一起使用 CentOS 7 下搭建 OpenVPN - CalvinChu How to get the ip ranges of domain esxi 直通sata控制器 Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_P xRDP – Detected issues with Debian 11 – Oh No ! Something has gone wrong…. qemu-mips环境搭建跳坑指南 ImportError: libSM.so.6: cannot open shared object file: No such file or directory openwrt(lede)中,PPtP Client需要安装的软件包 MAC OSX VPN自动添加静态路由 - CalvinChu fbprophet安装和使用 CentOS7安装iptables防火墙 CENTOS7下安装REDIS mysql忘记root密码解决办法 iptables命令(备忘)
OpenWrt中的Hotplug脚本
CalvinChu · 2021-02-05 · via 博客园 - CalvinChu

Hotplug,直译就是热插拔。在OpenWrt中,无论何时一个设备从系统中增删,都产生一个“热插拔事件”。

每次网络接口启动(up)或者关闭(down)的时候,所有在/etc/hotplug.d/iface/目录中的脚本都会以字母顺序执行。根据一个不成文的规则,会在每个脚本的前面加上一个数字前缀来设置正确的运行顺序。这就是为什么脚本名称都像:/etc/hotplug.d/iface/<nn>-<scriptname>的原因。

在iface hotplug脚本中有三个主要的环境变量:

变量名称 描述
ACTION "ifup" 或者 "ifdown"
INTERFACE 网络接口的名称,如"wan"
DEVICE 物理设备的名称,如"br-lan"

利用hotplug脚本可以在网络接口启动或关闭时执行相应的动作,新建:/etc/hotplug.d/iface/99-ipreport:

vi /etc/hotplug.d/iface/99-ipreport

#!/bin/bash
[ "$ACTION" = ifup ] || exit 0
[ "$INTERFACE" = wan ] || exit 0
ip=$(ifconfig pppoe-wan | grep inet | awk '{print $2}' | cut -c 6-)
echo $ip > /tmp/ip.txt

会生成一个/tmp/ip.txt,里面有个外网ip地址

或者换一种if写法,将脚本外置方便修改

vi /etc/hotplug.d/iface/99-ipreport

#!/bin/bash
if [ $ACTION=ifup -a $INTERFACE=wan ]; then
  sh /root/pppoe-success.sh
fi

/root/pppoe-success.sh的内容为访问一个网址汇报ip地址

vi /root/pppoe-success.sh
#!/bin/bash
curl -s '网址' > /dev/null

上面用到了curl,openwrt默认没有,可以在luci后台搜索curl安装

然后设置执行权限,ipreport无需设置执行权限,只需要设置外部脚本pppoe-success.sh执行权限即可

chmod +x /root/pppoe-success.sh

在luci后台将wan断开,然后再连接,或者直接重启路由器,即可看到效果