부팅할 때마다 내 IP를 원격 서버로 보냅니다.

부팅할 때마다 내 IP를 원격 서버로 보냅니다.

부팅할 때마다 컴퓨터의 IP를 자동으로 보내고 싶습니다. 나는 편집한다/etc/rc.local

sleep 10
ifconfig > /tmp/myip
scp /tmp/myip <server>
exit 0

inet addr, Bcast, Mask나는 그것을 시도했지만 거기에는 없습니다 /tmp/myip. 스크립트 후에 네트워크가 시작된 것 같습니다. 그래서 뭐 할까? 매우 감사합니다!

답변1

ifconfig출력이 표시되지 않습니다. 런타임 시 네트워크 설정이 아직 완전히 완료되지 않았기 때문일 수 있습니다. 또한 서버 가동 시간 동안 동적 IP 주소가 변경되지 않을 것이라는 100% 보장은 없습니다.

을 사용하는 경우 dhclient스크립트를 해당 디렉터리로 이동하여 /etc/dhcp/dhclient-exit-hooks.d실행합니다.뒤쪽에DHCP를 통해 IP 주소를 얻습니다. 데비안은 일반적으로 이 디렉터리를 채웁니다. 디렉터리가 없으면 새로 만들어야 할 수도 있습니다.

시작 시 및 IP 주소가 변경될 때마다 IP 주소를 보내도록 스크립트를 변경할 수 있습니다. IP 주소의 DHCP 임대 기간에 따라가능한또는아마매번 복사하는 데 관심이 있습니다.

ISP/인터넷 환경에 있다면 동적 DNS 서비스를 사용하는 것이 (더) 흥미로울 수도 있습니다.

자세한 내용은 여기를 참조하세요.ISP 변경 IP 주소를 처리하는 더 나은 방법은 무엇입니까?

그리고

http://manpages.ubuntu.com/manpages/wily/man8/dhclient-script.8.html

답변2

해결 방법은 사용하는 dhcp 클라이언트 데몬에 따라 다릅니다. 대부분의 배포판(*BSD 및 Linux)은 dhcpcd또는 를 사용합니다 dhclient. 두 경우 모두 클라이언트 구성에 스크립트를 삽입할 수 있습니다.

  • dhcpcd/etc/dhcpcd.sh제어되는 인터페이스가 작동하거나 작동 중지될 때마다 스크립트(있는 경우)를 실행합니다. scp이 스크립트에 자신의 것을 삽입하기 만 하면 됩니다 .

    Hooking into DHCP events
      dhcpcd will run /etc/dhcpcd.sh, or the script specified by the -c,
      --script option. It will set $1 to a shell compatible file that holds
      various configuration settings obtained from the DHCP server and $2 to
      either up, down or new depending on the state of dhcpcd.  dhcpcd ignores
      the exist code of the script.
    
  • dhclientETCDIR/dhclient-exit-hooks인터페이스를 설정한 후 즉시 스크립트를 호출합니다. Hook매뉴얼 페이지 섹션의 지침을 따를 수 있습니다 dhclient-script.

    After all processing has completed, CLIENTBINDIR/dhclient-script checks
    for  the  presence  of an executable ETCDIR/dhclient-exit-hooks script,
    which if present is invoked using the ´.´ command.  The exit status  of
    dhclient-script  will be passed to dhclient-exit-hooks in the exit_sta-
    tus shell variable, and will always be zero if the script succeeded  at
    the  task  for  which  it was invoked.   The rest of the environment as
    described previously for dhclient-enter-hooks is  also  present.    The
    ETCDIR/dhclient-exit-hooks  script  can modify the valid of exit_status
    to change the exit status of dhclient-script.
    

답변3

ifconfig ethx > /tmp/myip

x는 인터페이스 번호입니다(예: eth0).

관련 정보