2

I want to run sudo ifconfig lo0 alias someIp every time I open my mac, what would be the best way to achieve this?

6

You can create a LauchDaemon. LaunchDaemons are processes managed by the launchd service in macOS that are loaded when the system boots. LaunchDaemons can be used to run a program one-time, contiuously or periodically after boot.

Create a file called org.my.ifconfig.plist in /Library/LaunchDaemons/ with the following content and you should be good to go.

<?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>Nice</key>
    <integer>10</integer>
    <key>ProgramArguments</key>
    <array>
      <string>/sbin/ifconfig</string>
      <string>lo0</string>
      <string>alias</string>
      <string>someIp</string>
    </array>
</dict>
</plist>

Make sure the file is owned by root and in the group wheel, and has the permissions 644: Owner – read/write, group – read, everyone – read

More information can be found at developer.apple.com at Creating Launch Daemons and Agents.

  • Mind the typo: <interger>10</integer> -> <integer>10</integer> – Bart Gloudemans Aug 21 at 12:51

Not the answer you're looking for? Browse other questions tagged .