Altere dinamicamente o / etc / hosts

1

Sempre que altero o meu endereço IP, tenho de editar /etc/hosts e alterar a linha:

myPc-Vaio  192.168.1.x

Eu preciso dessa alteração para alguns programas que estou usando, por isso não posso simplesmente definir a linha como 127.0.0.1 .

Existe alguma automação para mudar essa linha em cada mudança de rede?

editar. Eu estou no kubuntu 13.10 e estou usando servidores dhcp com dhclient padrão do Ubuntu para obter novos endereços IP (configuração padrão).

    
por Phate 03.04.2014 / 09:43

1 resposta

2

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/ .

    
por 03.04.2014 / 11:19