ubuntu中怎么设置域名解析

706
2021/1/30 17:07:32
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

ubuntu中怎么设置域名解析

在ubuntu中设置域名解析的方法

1.首先,在ubuntu中新建一个main.cpp文件,并在文件中添加一下配置;

#include

#include

#include

#include

extern int h_errno;

int main(int argc, char **argv)

{

if (argc != 2) {

printf("Use example: %s www.google.com\n", *argv);

return -1;

}

char *name = argv[1];

struct hostent *hptr;

hptr = gethostbyname(name);

if (hptr == NULL) {

printf("gethostbyname error for host: %s: %s\n", name, hstrerror(h_errno));

return -1;

}

//输出主机的规范名

printf("\tofficial: %s\n", hptr->h_name);

//输出主机的别名

char **pptr;

char str[INET_ADDRSTRLEN];

for (pptr=hptr->h_aliases; *pptr!=NULL; pptr++) {

printf("\ttalias: %s\n", *pptr);

}

//输出ip地址

switch (hptr->h_addrtype) {

case AF_INET:

pptr = hptr->h_addr_list;

for (; *pptr!=NULL; pptr++) {

printf("\taddress: %s\n",

inet_ntop(hptr->h_addrtype, hptr->h_addr, str, sizeof(str)));

}

break;

default:

printf("unknown address type\n");

break;

}

return 0;

}

2.main.cpp文件新建好后,对main.cpp文件进行编译;

gcc main.cpp

3.最后,编译main.cpp文件后,使用dp命令即可对域名进行解析;

例:对www.baidu.com进行解析

dp www.baidu.com

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: ubuntu怎么打开anaconda