我想开开机启动的时候,给我的本地电脑新增一个虚拟IP地址
步骤
新增文件/Library/LaunchDaemons/org.my.ifconfig.plist (或许你需要sudo运行)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.my.ifconfig</string>
    <key>RunAtLoad</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
      <string>/sbin/ifconfig</string>
      <string>lo0</string>
      <string>alias</string>
      <string>192.168.24.2</string>
    </array>
</dict>
</plist>
确保有权限运行
# 配置own
sudo chown root:wheel /Library/LaunchDaemons/org.my.ifconfig.plist
# 使用管理员加载它
sudo launchctl load -w /Library/LaunchDaemons/org.my.ifconfig.plist
其他信息
https://www.zhihu.com/question/28268529
/Library/LaunchDaemons:系统启动时运行,用户不登录也会运行。
/Library/LaunchAgents:用户登录后运行。
~/Library/LaunchAgents:用户自定义的用户启动项
/System/Library/LaunchDaemons:系统自带的启动项
/System/Library/LaunchAgents:系统自带的启动项
因为ifconfig需要root权限运行,所以我要放到/Library/LaunchDaemons目录里面去。
参考链接
https://developer.apple.com/library/archive/technotes/tn2083/_index.html
https://superuser.com/questions/36087/how-do-i-run-a-launchd-command-as-root
