hostname ¸í·É¾î°¡ ÂüÁ¶ÇÏ´Â À§Ä¡°¡ ±Ã±ÝÇÕ´Ï´Ù.(cont)

   Á¶È¸ 3919   Ãßõ 0    

 우선 재질문 드리게 되어 죄송합니다. 호이호이님이 알려주셨는데요 . 제 man페이지랑 다르고 제대로 이해가 안가서 올립니다.

man hostname의 내용중

-------------------------------------------------------------------

GET NAME
       When called without any arguments, the program displays the current names:

       The function gethostname(2) is used to get the hostname.  When  the  host-
       name -a, -d, -f or -i is called will gethostbyname(3) be called.  The dif-
       ference in gethostname(2) and gethostbyname(3) is that gethostbyname(3) is
       network  aware,  so  it  consults /etc/nsswitch.conf and /etc/host.conf to
       decide whether to read information in /etc/sysconfig/network or /etc/hosts

       To  add  another dimension to this, the hostname is also set when the net-
       work interface is brought up.

 redhat 4버전대 는 

단순히 gethostname() 이라고만 되어있네요 ㅡ.ㅠ

-------------------------------------------------------------------

해석하자면 

hostname 은 gethostname(2)를 호출하며

hostname -a -d -f of -i  는 gethostbyname(3)을 호출한다.

두개의 차이는 gethostbyname은 네트워크 인식??이며 그래서 /etc/nsswitch.conf 그리고 /etc/host.conf 를 참고 하여 /etc/sysconfig/network or

/etc/hosts에서 읽어온다.  (둘중애 랜덤인지 순서가 있는건지 알길이 없네요..)

또 다른 측면으로 hostname은 network interface가 올라올때? 설정 된다.

(그렇다면 gethostname(2)는 어디에서 찾는지 내용이 없고 hostname -s 에 대한것 역시 찾을 수 없네요)


호이호이 님은 어떻게 찾으신건지 ...


보통 nsswitch.conf 에는 별다른 설정이 없는한 

hosts: files dns

로 되어있고 files는 /etc/hosts를 지칭한다고 알고 있습니다. /etc/host.conf는 별다른 설정이 없다면 multi on? 으로 되어있구요(6버전 기준)

그렇다면 6버전 기준으로  /etc/hosts를 참고한다라고 봐야될꺼 같은데 맞는지 궁금합니다.


고견 부탁드립니다.



ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
ltrace hostname Çغ¸¼¼¿ä.

hostname ¸í·É¾î¿¡ ÀÎÀÚ°ªÀ» Áà°¡¸é¼­ ½ÇÇàÇغÁµµ µË´Ï´Ù.
     
¿ÉÅ×·Ð 2016-07
´äº¯ °¨»çÇÕ´Ï´Ù.
Çغ¸´Ï È£Ã⠵Ǵ ÇÔ¼ö°¡ ³ªÅ¸ ³ª³×¿ä . Çåµ¥ ÇÔ¼ö È£Ãâ½Ã ÂüÁ¶ÇÏ´Â ÆÄÀÏÀÌ ¾î´À°ÍÀÎÁö Ȥ½Ã ¾Ë ¼ö ÀÖ´Â ¹æ¹ýÀÌ ÀÖÀ»±î¿ä?
 ¿¹¸¦µé¾î /etc/hosts or /etc/sysconfig/network ÀÎÁö È®½ÇÄ¡ °¡ ¾Ê¾Æ¼­ ±×·¸½À´Ï´Ù.¤Ð
          
strace -e open hostname

¾î´À ÆÄÀÏÀ» open ÇÏ´ÂÁö º¸¿©ÁÝ´Ï´Ù.
               
¿ÉÅ×·Ð 2016-07
strace -e open hostname
open("/etc/ld.so.cache", O_RDONLY)      = 3
open("/lib64/libselinux.so.1", O_RDONLY) = 3
open("/lib64/libc.so.6", O_RDONLY)      = 3
open("/lib64/libdl.so.2", O_RDONLY)    = 3
open("/usr/lib/locale/locale-archive", O_RDONLY) = 3
dns
 ÀÌ·± ¹æ¹ýÀÌ ÀÖ´Ù´Ï ½Å¼¼°è³×¿ä. ±Ùµ¥ ¿¹»óÇϱ⸦ À§¿¡ µÎ ÆÄÀÏÀϲ¨¶ó »ý°¢Çߴµ¥ ¾Æ´Ï¿´³ª º¸³×¿ä .. ȯ°æº¯¼ö¿¡¼­ °¡Á®¿À´Â°ÇÁöµµ ¸ð¸£°Ú³×¿ä..``
               
¿ÉÅ×·Ð 2016-07
Ȥ½Ã³ª Çؼ­ ´ÙÀ½À¸·Î Çغôµ¥¿ä
export HOSTNAME=dns6
echo $HOSTNAME
dns6
hostname
dns
ȯ°æº¯¼ö´Â ¾Æ´Ñ°¡ º¾´Ï´Ù ¤¾
È­¶õ 2016-07
gethostname(), sysinfo() µîµî ¹öÀüº°·Î ¾²ÀÌ´Â ÇÔ¼ö°¡ ´Ù¸¥°É·Î ¾Ë°í ÀÖ±¸¿ä

ÇØ´ç ¹èÆ÷ÆÇÀÇ hostname.c µîÀÇ ¼Ò½ºÄڵ带 ±¸±Û¸µ Çغ¸¸é °¡Àå Á¤È®ÇÕ´Ï´Ù.

Âü°í·Î, CentOS 6.7¿¡¼­´Â gethostname() ÇÔ¼ö¸¦ default·Î »ç¿ëÇϳ׿ä...
     
¿ÉÅ×·Ð 2016-07
´äº¯ °¨»çÇÕ´Ï´Ù. hostname.c¸¦ ºÃ´Âµ¥¿ä ¼Ò½ºÄÚµå Çؼ®ÀÌ ¾ÈµÇ³×¿ä ..
     
¿ÉÅ×·Ð 2016-07
/* hostname.c

  Display or change the system hostname.

  Usage: hostname [new-host-name]
*/
#define _BSD_SOURCE
#include <sys/param.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#define BUF_SIZE (MAXHOSTNAMELEN + 1)
int
main(int argc, char *argv[])
{
    char buf[BUF_SIZE];

    if (argc > 1) {
        if (sethostname(argv[1], strlen(argv[1])) == -1) {
            perror("sethostname");
            exit(EXIT_FAILURE);
        }
    } else {
        if (gethostname(buf, BUF_SIZE) == -1) {
            perror("gethostname");
            exit(EXIT_FAILURE);
        }
        printf("%s\n", buf);
    }

    exit(EXIT_SUCCESS);
}

ÀÎÀÚ°¡ ÀÖ´Ù¸é set-hostnameÀÌ µ¿ÀÛÇÏ°í ¾ø´Ù¸é gethostnameÀÌ µ¿ÀÛÇϴ°Š°°ÀÌ º¸À̳׿ä ~~ ÇÏÁö¸¸ ±Ã±ÝÇÑ°ÍÀº ¾îµð¼­ °¡Á®¿À´ÂÁö¿¡ ´ëÇÑ°ÍÀÌ ¸íȮġ°¡ ¹®Àǵ帳¤¤µð¤¿.
          
È­¶õ 2016-07
Çؼ® ¸Â´Âµ¥¿ä^^

argc°¡ 1º¸´Ù Å©´Ù¸é, Áï, ¸í·É¾î ÀÚü¿Í ÀÎÀÚ°¡ 1°³ ÀÌ»ó ÀÖ´Ù¸é sethostname() ÇÔ¼ö·Î »õ·Î¿î È£½ºÆ®³×ÀÓÀ» '¼³Á¤'ÇÏ°Ô µÇ°í,

ÀÎÀÚ¾øÀÌ ¸í·É¾î ÀÚü¸¸ ÀÖ´Ù¸é gethostname() + printf() ¸¦ ½ÇÇàÇÕ´Ï´Ù.


man gethostname

man 2 uname

¼øÀ¸·Î Á»´õ Æĺ¸¼¼¿ä^^

°³ÀÎÀûÀ¸·Î´Â uname() ÇÔ¼ö Æĺ¸¸é ³ª¿Ã°Í °°Àºµ¥¿ä...


¹èÆ÷¸¸ ¸¶´Ù ¸Þ´º¾ó ÆäÀÌÁöÀÇ ³»¿ëÀº Á¶±Ý¾¿ ´Ù¸£°í,

ÇÑ±Û ¸Þ´º¾óÀº ¿À·¡µÈ°ÍÀÌ ¸¹À¸´Ï±î ¹Ýµå½Ã ÇØ´ç ¹èÆ÷ÆÇÀÇ ÃֽŠ¿µ¹® ¸Þ´º¾óÀ» º¸¼Å¾ß ÇÕ´Ï´Ù.
               
¿ÉÅ×·Ð 2016-07
°¨»çÇÕ´Ï´Ù. Á»´õ ÆĹپ߰ڳ׿ä !


QnA
Á¦¸ñPage 2214/5598
2014-05   4511624   Á¤ÀºÁØ1
2015-12   1063457   ¹é¸Þ°¡
2016-07   4482   ÁÖ»óÀý¸®
2016-07   3485   ÁÖ¿µÁø¿µ¾Æºü
2016-07   4719   yuno
2016-07   3948   blueGEE
2016-07   3493   ´ÃÆĶõ
2016-07   3626   ¸Å´Ï¾Æ1
2016-07   6609   ÆÈÄÚ2
2016-07   4171   isaiah
2016-07   7278   ¶óÀÌÁ¨
2016-07   3220   ´ÃÆĶõ
2016-07   3624   ±èÀ¯Áß
2016-07   4768   ±¼´Ù¸®±³
2016-07   15030   Landa
2016-07   4552   º¸±¤
2016-07   4590   Astarot
2016-07   9940   ¿Ë½º
2016-07   4111   ³ë¾Æµð
2016-07   3899   ¹Ú¼º¸¸
2016-07   7384   yuno
2016-07   5786   ´ÃÆĶõ