Network information query function in Linux

Source: Internet
Author: User

Network-related information on hosts required by network applications generally includes: hosts, networks, protocols, and services. In this information, the host and network information can be obtained either through the Domain Name System (DNS) or through related files, the service and protocol information is generally read from the corresponding file. System files related to network information are as follows:

Information File Name Related functions
Host /Etc/hosts Gethostbyaddr, gethostbyname
Network /Etc/networks Getnetbyaddr, getnetbyname
Protocol /Etc/protocols Getprotobyname, getprotobynumber
Service /Etc/SER/vices Getservbyname, getservbyport
Table 1: Four files related to network informationWhen gethostbyname or gethostbyaddr is called in a program, the Linux system actually uses the/etc/hosts file to match the corresponding host name or IP address. The configuration format in the/etc/hosts file is as follows: IP address hostname alias
127.0.0.1 localhost local
192.168.1.202 linuxserver Server
............ ............ ......... The leftmost column is the Host IP information, and the middle column is the host name. All the columns that follow are aliases of the host.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.