Ifconfig tool for configuring network interfaces

Source: Internet
Author: User

Ifconfig
Interface tools ()


Ifconfig is a tool used to view, configure, enable, or disable network interfaces. You can use this tool to temporarily configure the IP address, mask, broadcast address, and gateway of the NIC. You can also write it into a file (such as/etc/rc. d/rc. Local ).
After booting, the file will be read and an IP address will be set for the NIC
1. ifconfig: view the network interface status;


If ifconfig is not followed by any parameters, 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 FIG: 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 indicates the first network card. hwaddr indicates the physical address of the network card. You can see that the current physical address (MAC address) of this network card is
00: C0: 9f: 94: 78: 0e; Inet ADDR is used to indicate the IP address of the NIC. the IP address of the NIC is 192.168.1.88 and the broadcast address,
Bcast: 192.168.1.255, mask Address Mask: 255.255.255.0
Lo indicates the host's bad return address, which is generally used to test a network program, but does not want the LAN
Or Internet users can view the network interfaces that can only be run and viewed on this host. For example, if you specify the address of the httpd server to a bad address
Enter 127.0.0.1 to view your website. But you can see that, LAN
Other hosts or users do not know;
If you want to know all the network interfaces of the host, use the following command;

[Root @ localhost ~] # Ifconfig-

If you want to view a port, such as the eth0 status, you can use the following method;

[Root @ localhost ~] # Ifconfig eth0


2. Configure the network interface in ifconfig;



Ifconfig can be used to configure IP addresses, masks, gateways, and physical addresses of network interfaces.
Specify an IP address for the NIC. This is only used for network debugging and does not change the NIC configuration file. If you want to fix the IP address of the network interface, there are three methods:
Tools dedicated for release and version are used to modify IP addresses. The second is to directly modify the configuration file of Network Interfaces. The third is to modify specific files and add ifconfig
Command to specify the IP address of the NIC. For example, in RedHat or fedora, write the ifconfig language name to the/etc/rc. d/rc. Local file;
How to configure the network port in ifconfig:

The ifconfig tool configures network interfaces through command parameters. We only need to specify the most common parameters;
Ifconfig network port IP address HW <HW> MAC address netmask mask address broadcast address [up/down]

* Instance 1:

For example, we use ifconfig to debug the address of the eth0 Nic.
[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 FIG: 1000
RX Bytes: 0 (0.0 B) TX Bytes: 0 (0.0 B)
Interrupt: 11 base address: 0x3400

Note:
Let's explain the above example;
The first line: ifconfig eth0 down indicates that if eth0 is activated, it will be down. This command is equivalent to ifdown eth0;
Row 2: Use ifconfig to configure the eth0 IP address, broadcast address, and network mask;
Row 3: Use ifconfig eth0 up to activate eth0. This command is equivalent to IFUP eth0.
Row 4: Use ifconfig eth0 to view the eth0 status;
Of course, you can also use the command IP address, network mask, broadcast address to activate the NIC, add the up parameter, for example, the following example;

[Root @ localhost ~] # Ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0 up

* Example 2:
In this example, we need to learn how to set the network IP address and the physical address (MAC address) of the network card );
For example, we set the IP address, network mask, broadcast address, physical address, and activate the eth1 Nic;
[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 up
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

HW is followed by the network interface type. Ether indicates Ethernet. It also supports ax25, ARCNET, and netrom. For more information, see man ifconfig;

3.3 How to Use ifconfig to configure virtual network interfaces;



Sometimes we need to configure virtual network interfaces to meet different needs. For example, we need to use different IP addresses to run multiple HTTPd servers; in this way, the same IP address is saved. If two HTTPd servers are opened, you must specify the port number.
A virtual network interface is used to specify multiple IP addresses for a network interface. The virtual interfaces are eth0: 0, eth0: 1, eth0: 2... eth1n. Of course, you must specify multiple IP addresses for eth1, that is, eth1: 0, eth1: 1, eth1: 2 ...... and so on;
In fact, if you use ifconfig to configure multiple IP addresses for a nic, you can use the ifconfig usage we mentioned earlier. This is relatively simple. See the following example;
[Root @ localhost ~] # Ifconfig eth1: 0 192.168.1.20.hw ether 00: 11: 00: 00: 11: 33 netmask 255.255.255.0 broadcast 192.168.1.255 up
Or
[Root @ localhost ~] # Ifconfig eth1 HW ether 00: 11: 00: 00: 11: 33
[Root @ localhost ~] # Ifconfig eth1 192.168.1.20.netmask 255.255.255.0 broadcast 192.168.1.255 up

Note:
Specify a different physical address for each virtual network card;
In RedHat/Fedora or a system similar to RedHat/fedora, you can configure the network IP address, broadcast address, mask address, physical address, and activate the network interface in one sentence, write/etc/rc. d/RC. local. For example, the following example;
Ifconfig eth1: 0 192.168.1.250 HW ether 00: 11: 00: 00: 11: 44 netmask 255.255.255.0 broadcast 192.168.1.255 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:
Two virtual interfaces are set for the network interface of eth1. Each interface has its own physical address and IP address ......

3.4 how to use ifconfig to activate and terminate network interface connections;



Use the ifconfig command to activate and terminate the network interface, followed by the network interface, and add the down or up parameter to disable or activate the corresponding network interface. Of course, you can also use specialized tools IFUP and ifdown;
[Root @ localhost ~] # Ifconfig eth0 down
[Root @ localhost ~] # Ifconfig eth0 up
[Root @ localhost ~] # IFUP eth0
[Root @ localhost ~] # Ifdown eth0

This is also true for activating other types of network interfaces, such as ppp0 and wlan0. It is only valid for the NIC of the specified IP address.

Note: The IP address automatically assigned by DHCP must be activated by the network tools provided by each release. Of course, you must install the DHCP client. You should understand this;


For example, RedHat/Fedora
[Root @ localhost ~] #/Etc/init. d/network start

Slackware release;
[Root @ localhost ~] #/Etc/rc. d/rc. inet1

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.