Ifconfig usage Explanation

Source: Internet
Author: User
6.6 There is no ifaddrget these functions, from 6.7 began to have.


I think I can make up this function by myself, probably the idea is
struct Ifreq req;
S=socket (af_inet,sock_dgram,0);
IOCTL (S,SIOCGIFADDR, (int) &req);
Do some conversion to req.
Go from Tony Embedded Forum, Address: http://www.cevx.com/bbs/thread-28499-1-1.html






Ifconfig usage Explanation
Ifconfig Configuring the Network Interface Tool Introduction


Ifconfig is a tool used to view, configure, enable, or disable a network interface, which is extremely common. This tool can be used to temporarily configure the network card IP address, mask, broadcast address, Gateway and so on. It can also be written to a file (such as/etc/rc.d/rc.local), so that after the system boots, it will read the file, set the IP address for the network card
1 ifconfig view network interface status;


Ifconfig If no parameters are received, the current network interface is output;


[Root@localhost ~]# Ifconfig
Eth0 Link encap:ethernet HWaddr 00:c0:9f:94:78:0e
inet addr:192.168.1.88 bcast:192.168.1.255 mask:255.255.255.0
Inet6 ADDR:FE80::2C0:9FFF:FE94:780E/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:850 errors:0 dropped:0 overruns:0 frame:0
TX packets:628 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:369135 (360.4 KiB) TX bytes:75945 (74.1 KiB)
Interrupt:10 Base address:0x3000


Lo Link encap:local Loopback
inet addr:127.0.0.1 mask:255.0.0.0
Inet6 addr::: 1/128 scope:host
Up LOOPBACK RUNNING mtu:16436 metric:1
RX packets:57 errors:0 dropped:0 overruns:0 frame:0
TX packets:57 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8121 (7.9 KiB) TX bytes:8121 (7.9 KiB)


Explanation:
Eth0 represents the first network card, where HWaddr represents the physical address of the network card, you can see the current network card physical address (MAC address) is 00:c0:9f:94:78:0e; inet addr is used to represent the IP address of the network card, the IP address of this network card is 192.168.1. 88, broadcast address, bcast:192.168.1.255, mask address mask:255.255.255.0


Lo is the return of the host's bad address, which is generally used to test a network program, but do not want to let the local area network or extranet users can view, can only run on this host and view the network interface used. For example, the HTTPD server is assigned to the bad address, in the browser input 127.0.0.1 will be able to see your Web site. But you can see that the other host or user of the local area network is unknown;


If you want to know all the network interface of the host, please use the following command;
[Root@localhost ~]# Ifconfig-a


If you want to view a port, such as viewing the status of Eth0, you can use the following method;
[Root@localhost ~]# ifconfig eth0




2 ifconfig configuration Network interface;


Ifconfig can be used to configure the network interface IP address, mask, gateway, physical address, etc. it is worth to use Ifconfig to specify the IP address for the network card, which is only used to debug the net, and does not change the system about the network card configuration file. If you want to fix the IP address of the network interface, there are currently three methods: one is to modify the IP address through each release and version-specific tool, and the other is to modify the configuration file of the network interface directly, and the third is to modify the specific file and add the ifconfig instruction to specify the IP address of the NIC. For example, in Redhat or Fedora, the name of the Ifconfig is written into the/etc/rc.d/rc.local file;


Ifconfig How to configure network ports:


Ifconfig tools to configure the network interface method is through the parameters of the directive to achieve the purpose, we only say the most commonly used parameters;
Ifconfig Network Port IP address HW <HW> MAC address netmask mask address broadcast broadcast address [Up/down]


* Example One:
For example, we use Ifconfig to debug the address of the eth0 NIC.

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.