Se você usa DHCP
, pode acionar a alteração do endereço IP usando dhclient-script
:
NAME
dhclient-script - DHCP client network configuration script
DESCRIPTION
The DHCP client network configuration script is invoked from time to
time by dhclient(8). This script is used by the dhcp client to set
each interface's initial configuration prior to requesting an address,
to test the address once it has been offered, and to set the
interface's final configuration once a lease has been acquired. If no
lease is acquired, the script is used to test predefined leases, if
any, and also called once if no valid lease can be identified.
This script is not meant to be customized by the end user. If local
customizations are needed, they should be possible using the enter and
exit hooks provided (see HOOKS for details). These hooks will allow
the user to override the default behaviour of the client in creating a
/etc/resolv.conf file.
No standard client script exists for some operating systems, even
though the actual client may work, so a pioneering user may well need
to create a new script or modify an existing one. In general,
customizations specific to a particular computer should be done in the
/etc/dhcp3/dhclient.conf file. If you find that you can't make such a
customization without customizing /etc/dhcp3/dhclient.conf or using the
enter and exit hooks, please submit a bug report.
Você pode escrever um script para obter o novo endereço IP e substituir o arquivo /etc/hosts
. Em seguida, coloque-o em /etc/dhcp/dhclient-exit-hooks.d/
.