Ifconfig Command Detailed

Source: Internet
Author: User
Tags unix domain socket

Ifconfig usage Detailed
Introduction to Tools for configuring network interfaces Ifconfig

Ifconfig is a tool used to view, configure, enable, or disable network interfaces, which is extremely common. You can use this tool 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 when the system is booted, it will read the file and set the IP address for the network card.
1 ifconfig view network interface status;

Ifconfig If no parameters are received, the current network interface will be exported;

[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, in which hwaddr represents the physical address of the network card, you can see that the physical address of the network card (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 host's return-bad address, which is typically used to test a network program, but does not want the local area network or extranet users to be able to view, only on this host to run and view the network interface used. For example, the HTTPD server is designated to the bad address, in the browser input 127.0.0.1 will be able to see your Web site. But only you can see, the other LAN hosts or users do not know;

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 see a port, such as viewing the status of a eth0, you can use the following method;
[Root@localhost ~]# ifconfig eth0


2 ifconfig configuration Network interface;

Ifconfig can be used to configure the IP address, mask, gateway, physical address of the network interface, etc. it is worth saying that the IP address is specified with Ifconfig for the network card, which is only used to debug the Web, and does not change the system's configuration file about the NIC. 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 the various distribution and version-specific tools; the other is to modify the network interface configuration file directly; The third is to modify specific files, add ifconfig instructions to specify the IP address of the network card, For example, in Redhat or Fedora, the Ifconfig's name is written into/etc/rc.d/rc.local file;

Ifconfig How to configure network ports:

The Ifconfig tool configures the network interface by using the parameters of the instruction to achieve the goal, 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 network card
[Root@localhost ~]# ifconfig eth0 down
[Root@localhost ~]# ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0
[Root@localhost ~]# ifconfig eth0 up
[Root@localhost ~]# ifconfig eth0
Eth0 Link encap:ethernet hwaddr 00:11:00:00:11:11
inet addr:192.168.1.99 bcast:192.168.1.255 mask:255.255.255.0
Up broadcast multicast mtu:1500 metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:11 Base address:0x3400

Note: Let us explain the above example;

The first line: Ifconfig eth0 down means that if eth0 is active, it's down. This command equates to Ifdown eth0;
Second line: Use Ifconfig to configure eth0 IP address, broadcast address and netmask;
Third line: Activates the eth0 with ifconfig eth0 up; This command is equivalent to Ifup eth0
Line four: Use ifconfig eth0 to view the state of the eth0;

Of course, you can also use directly in the command IP address, network mask, broadcast address at the same time, activate the network card, to add up the parameters, such as the following example;
[Root@localhost ~]# ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0 up

* Example Two: In this example, we have to learn to set the network IP address at the same time, learn to set the Physical Address Card (MAC address);

For example, we set the network card eth1 IP address, netmask, broadcast address, physical address and activate it;
[Root@localhost ~]# ifconfig eth1 192.168.1.252 hw ether 00:11:00:00:11:11 netmask 255.255.255.0 broadcast 192.168.1.255 u P
Or
[Root@localhost ~]# ifconfig eth1 hw ether 00:11:00:00:11:22
[Root@localhost ~]# ifconfig eth1 192.168.1.252 netmask 255.255.255.0 broadcast 192.168.1.255 up

Where HW followed by the network interface type, Ether said that the B-net, but also support ax25, ARCnet, netrom, etc., please see man ifconfig;


3.3 How to use Ifconfig to configure the virtual network interface;

Sometimes we need to configure the virtual network interface to meet different needs, for example, we use a different IP address to run multiple httpd servers, it is necessary to use a virtual address; This eliminates the same IP address, and if you are opening two HTTPD servers, specify the port number.

Virtual network interface refers to a network interface to specify multiple IP addresses, virtual interface is such eth0:0, Eth0:1, Eth0:2 ... eth1n. Of course, you specify multiple IP addresses for eth1, that is, eth1:0, eth1:1, Eth1:2 ... Analogy

In fact, the use of ifconfig for a network adapter to configure multiple IP addresses, using the previous we said the use of ifconfig, this relatively simple; look at the example below;
[Root@localhost ~]# ifconfig eth1:0 192.168.1.251 hw ether 00:11:00:00:11:33 netmask 255.255.255.0 broadcast up
Or
[Root@localhost ~]# ifconfig eth1 hw ether 00:11:00:00:11:33
[Root@localhost ~]# ifconfig eth1 192.168.1.251 netmask 255.255.255.0 broadcast 192.168.1.255 up

Note: When specified, specify a different physical address for each virtual NIC;

In Redhat/fedora or similar systems with Redhat/fedora, you can put the configuration network IP address, broadcast address, mask address, physical address, and activate network interface in one sentence, and write to/etc/rc.d/rc.local. such as the following example;
Ifconfig eth1:0 192.168.1.250 hw ether 00:11:00:00:11:44 netmask 255.255.255.0 broadcast up
Ifconfig eth1:1 192.168.1.249 hw ether 00:11:00:00:11:55 netmask 255.255.255.0 broadcast 192.168.1.255 up

Explanation: Above is the network interface for ETH1, set up two virtual interfaces, each interface has its own physical address, IP address ...


3.4 How to use ifconfig to activate and terminate the connection of network interface;

Activate and terminate the network interface with the Ifconfig command, followed by the network interface, then add down or up parameters, you can prohibit or activate the corresponding network interface. Of course, can also use special tools Ifup and Ifdown tools;
[Root@localhost ~]# ifconfig eth0 down
[Root@localhost ~]# ifconfig eth0 up
[Root@localhost ~]# ifup eth0
[Root@localhost ~]# Ifdown eth0

This is true for activating other types of network interfaces, such as Ppp0,wlan0, but only for network adapters that specify IP.


Note: The IP assigned to DHCP is also activated by the network tools that come with each release, and of course you have to install the DHCP client;

Like Redhat/fedora.
[Root@localhost ~]#/etc/init.d/network start

Slackware Release edition;
[Root@localhost ~]#/etc/rc.d/rc.inet1
------------------------------------------------------------------------------
Introduction
The Ifconfig command makes the Linux core aware of some network interfaces such as software loopback and Nic so that Linux can use them. In addition to the usage described above, the ifconfig command is used to monitor and change the state of the network interface, and can also carry many command-line arguments.
    
Add Favorites Set as homepage

The Ifconfig command makes the Linux core aware of some network interfaces such as software loopback and Nic so that Linux can use them. In addition to the usage described above, the ifconfig command is used to monitor and change the state of the network interface, and can also carry many command-line arguments. The following is a generic invocation syntax for a ifconfig:

#ifconfig interface [[-net-host] address [parameters]]

Where interface is the name of the network interface: address is the host name or IP addresses assigned to the specified interface. The host names used here are parsed into their peer IP addresses, and this parameter is required. The-net and-host parameters tell Ifconfig to use this address as a network number or as a host address, respectively.

If you call the Ifconfig command with only the upper port device name, it displays the configuration of the port, and if you do not take any arguments, the ifconfig command displays all the information of the interface configured so far, and if you take the-a option, you can also display the currently inactive interface.

A ifconfig call that checks the Ethernet interface eth0 can get the following output:

#ifconfig eth0

Eth0 Link encap 10Mbps Ethernet hwaddr 00:00:c0:90:b3:44

inet addr xxx.xxx.xxx.xxx bcast xxx.xxx.xxx.255 Mask

Up broadcast RUNNING MTU 1500 Metric 0

RX Packets 3136 Errors 217 dropped 7 overrun 26

TX packets 1752 Errors dropped 0 overrun 0

(Note: Where XXX.XXX.XXX.XXX is an IP address)

The MTU and Metric columns show the maximum data transfer values and interface measures for the current eth0 interface. An interface measure represents the cost of sending a group on this path. Routing is not currently used in the kernel, but may be used later. RX (Receive group number) and TX (Transfer group number) These two lines show the receive, the number of transfer groupings, as well as the number of group errors, the number of missing groups (one likely due to less memory), and the number of limits (usually occurs when the receiver receives data faster than the core processing speed).

Parameters represents the various parameters supported by the ifconfig, which makes it easy to monitor and change the state of the network interface.

ifconfig Command Line arguments:

Up activates the specified interface

Down closes the specified interface. This parameter effectively blocks IP traffic through the specified interface, and if you want to permanently close an interface, we also need to remove all routing information for that interface from the core routing table

Netmask Mask Sets the IP netmask for the interface. The mask can be a 32-bit hexadecimal number with a prefix of 0x, or it can be 4 decimal digits separated by dots. If you don't want to divide your network into subnets, you can ignore this option; If you want to use subnets, remember that each system in your network must have the same subnet mask.

Pointpoint opens the point-to-point mode of the specified interface. It tells the core that the interface is a direct connection to another machine. When an address is included, the address is assigned to the machine at the other end of the list. If no address is given, open the Pointpoint option for the specified interface. A minus sign in front indicates that the Pointpoint option is turned off.

Broadcast address when you use an address, set the broadcast addresses for this interface. If no address is given, open the Iff_broadcast option for the specified interface. A minus sign in front indicates that this option is turned off.

Metric number sets the interface measure to integer number. A measure represents the cost of sending a group on this path. Routing costs are not currently used in the kernel, but will be in the future.

The MTU bytes sets the maximum number of bytes that an interface can handle in one transmission to an integer bytes. At present, the core network code does not handle IP segmentation, so be sure to set the MTU (Maximum data transfer unit) value large enough

ARP turns on or off the ARP protocol used on the specified interface. Preceded by a minus sign to turn off this option.

Allmuti Open the No-difference mode of the specified interface. Open this mode so that the interface sends all the information on the network to the core, not just the message to the core of your machine. Preceded by a minus sign indicates that the option is turned off

HW sets the hardware address for the specified interface. The equivalent ASCII character of the hardware type name and the secondary hardware address must follow this keyword. Currently supports Ethernet (ether), AMPR, ax.25, and PPP traliers to open the tracker on Ethernet frames. It is not currently implemented on a Linux network, and typically does not require all of these configurations.

Ifconfig can set everything that is required only by the interface name, netmask, and assigned IP address. When Ifconfig is overlooked or has a complex network, just reset most of the parameters.

Use Netstat to check network status

Here's a useful command--netstat, using the netstat command to monitor TCP/IP network configuration and working conditions. It can display the kernel routing table, active network status, and useful statistics for each network interface. For more information, please read man page.

-a displays information about all Internet connections, including those that are listening

-I displays statistics for all network devices

-C continuously displays the update status of the network. This parameter uses the Netstat output network status list once per second until the program is interrupted

-N Displays remote address, local address, and port information in digital/raw form, rather than resolving host names and servers

-O Displays the end time of the counter and the fallback (back off) of each network connection

-R Display Kernel routing table

-T displays only TCP socket information, including information that is listening

-u only displays UDP socket information

-V
Display Netstat version information

-W Display Raw (RAW) socket information

  -X display UNIX domain socket information

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.