Use ifconfig to configure the network in Centos

Source: Internet
Author: User
Many Windows administrators are very familiar with the ipconfig command line tool, which is used to obtain and modify network interface configuration information. Linux has a similar tool, ifconfig, which is a common tool of most Linux system administrators. However, there are some obvious differences between ipconfig and ifconfig. for example, DOS/Windowsipconfig does not allow you to modify the network

Many Windows administrators are very familiar with the ipconfig command line tool, which is used to obtain and modify network interface configuration information. Linux has a similar tool, ifconfig, which is a common tool of most Linux system administrators. However, there are some obvious differences between ipconfig and ifconfig. for example, DOS/Windows ipconfig does not allow you to modify the network configuration.
Generally, you must log on as root or use sudo to use ifconfig on a Linux machine. Depending on the options used in the ifconfig command, the ifconfig tool can be used not only to obtain the network interface configuration information, but also to modify these configurations.

Basic functions

Entering ifconfig on the command line interface without specifying any options will provide you with a fairly complete description of the current status of all active network interfaces. For example, if you enter ifconfig in the command line on a machine with the host name erebus, the following output may be returned:

Eth0 Link encap: Ethernet HWaddr 00: C0: F0: 77: FD: AD
Inet addr: 192.168.2.103 Bcast: 192.168.2.255 Mask: 255.255.255.0
Inet6 addr: fe80: 2c0: f0ff: fe77: fdad/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 913240 errors: 230 dropped: 0 overruns: 0 frame: 230
TX packets: 663990 errors: 7 dropped: 0 overruns: 0 carrier: 12
Collisions: 0 fig: 1000
RX bytes: 179148797 (170.8 MiB) TX bytes: 53220450 (50.7 MiB)
Interrupt: 9 Base address: 0xb000
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: 9814 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 9814 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 3655065 (3.4 MiB) TX bytes: 3655065 (3.4 MiB)

The ifconfig command provides the following important information:

Each activity interface is identified by its name.
When there is only one physical network adapter, you will see the MAC address with the term HWaddr added above.
Inetaddr is added before the IP address of the API. the broadcast address is Bcast and the subnet Mask is Mask.
Inet6 is added before the IPv6 address of each interface, and the word Scope is added before the range.
The activity types of each interface are listed together-in the case of eth0 above, it is listed as up broadcast running multicast.
The statistics for receiving and forwarding packets are listed in rows starting with RX or TX, respectively. In the other row, the summary information of the total amount of data received and transferred is provided, including the total number of bytes transferred and received by the slave database so far.

Option

You can specify multiple options in the ifconfig command to change the behavior:

-A: This option tells ifconfig to display information about all interfaces, including active and inactive interfaces. On erebus, ifconfig-a returns the eth0, lo, and sit0 results.
-S: this is a "short list" option, which displays a line of summary data for each interface. The returned information is related to interface activity and is not configured. The returned content of the output is the same as that of the netstat-I command.
-V: this "detailed" option returns additional information when certain types of error conditions are met to help identify and handle faults.
[Int]: As long as your ifconfig command is followed by an interface name, the interface information will be obtained. For example, if you only want to know the eth0 interface information, rather than the loop interface, you can execute the command ifconfig eth0. In addition, there are several options to specify the interface you want to configure or obtain information.
Up: if an interface is not active, this option will activate it. For example, ifconfig eth0 up will activate eth0.
Down: opposite to up, which invalidates the specified interface. Therefore, ifconfig eth0 down will invalidate the currently active eth0.
Netmask [addr]: The "netmask" option allows you to set a network mask for a given interface. For example, to set a network mask for eth0, you can enter ifconfig eth0 netmask mask 255.255.0.
Broadcast [addr]: when the "broadcast" option is followed by an address parameter, for example, ifconfig eth0 broadcast 192.168.2.255, the broadcast address of the specified interface is set.
[Addr]: only specify an address after the interface name, for example, ifconfig eth0 192.168.2.103. the IP address of this interface is set.

Tips

In most Linux systems, the ifconfig eth0 up command can be abbreviated as ifup eth0. The same method can make an interface invalid, so ifconfig eth0 down can be abbreviated as ifdown eth0. Some Linux systems even have a further abbreviated command named ifupdown, which loops through the status of an interface, quickly invalidates the interface, and then reactivates the interface, however, it is not as common as ifup and ifdown commands.

More information
Ifconfig, ifup, ifdown, and ifstatus are short for interfaces. It is different from the conditional statement in programming. If you enter man ifconfig in the command line to view its online documentation, you can obtain more information about this tool.
Other network connection tools included in the notes:

Arp-it provides address ing cache information and allows you to operate on it in various ways, such as deleting or adding entries.
The iptables-iptables tool is actually a firewall configuration interface with kernel packet filtering performance.
Netstat-the tool returns network connection information, route table, interface status, and other information.
The Route-route tool can be used to obtain information in the IP Route table of your host or modify the route table.
Enter man utilityname in the command line to view the online documentation of these tools for more information. For example, input man arp to view the online documents of the arp tool. You can enter man to obtain more information about the man tool.

Related Article

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.