Detecting a change of IP address in Linux

前端 未结 7 1348
轮回少年
轮回少年 2020-12-29 10:53

Does anyone know a way to detect a change of IP address in Linux. Say I have dhcpcd running, and it assigns a new IP address, is there a way I can get a notification when it

7条回答
  •  轮回少年
    2020-12-29 11:09

    Since DHCP activity is sent to syslogd you could create a named pipe, direct syslog traffic to it and watch the stream for IP address updates. See 'man syslogd' and 'man syslog.conf'.

    Edit: Another approach would be to use inotify to monitor the DHCP leases file for the interface. Under Ubuntu 9.10 that is in the /var/lib/dhcp3 directory.

提交回复
热议问题