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 Viewing network interface status
Ifconfig If no parameters are received, the current network interface is output;
[Email protected] ~]# ifconfig
Eth0 Link encap:ethernet HWaddr 00:03:0d:27:86:41
inet addr:192.168.1.86 bcast:192.168.1.255 mask:255.255.255.0
Inet6 ADDR:FE80::203:DFF:FE27:8641/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:618 errors:0 dropped:0 overruns:0 frame:0
TX packets:676 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:491238 (479.7 KiB) TX bytes:86286 (84.2 KiB)
Interrupt:5 Base address:0x8c00
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:1692 errors:0 dropped:0 overruns:0 frame:0
TX packets:1692 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3174550 (3.0 MiB) TX bytes:3174550 (3.0 MiB)
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:03:0d:27:86:41; inet addr is used to represent the IP address of the network card, the IP address of this network card is 192.168.1. 86, 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;
[[Email protected] ~] #ifconfig-A
If you want to view a port, such as viewing the status of Eth0, you can use the following method;
[[Email protected] ~] #ifconfig eth0
2.ifconfig Configuring the 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 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.
[[Email protected] ~] #ifconfig eth0 down
[[Email protected] ~] #ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0
[[Email protected] ~] #ifconfig eth0 up
[[Email protected] ~] #ifconfig eth0
Eth0 Link encap:ethernet HWaddr 00:03:0d:27:86:41
inet addr:192.168.1.99 bcast:192.168.1.255 mask:255.255.255.0
Inet6 ADDR:FE80::203:DFF:FE27:8641/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:618 errors:0 dropped:0 overruns:0 frame:0
TX packets:676 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:491238 (479.7 KiB) TX bytes:86286 (84.2 KiB)
Interrupt:5 Base address:0x8c00
Note: The above example we explain;
First line: Ifconfig eth0 down indicates that if the eth0 is active, drop it. This command is equivalent to Ifdown eth0;
The second line: use Ifconfig to configure the eth0 IP address, broadcast address and netmask;
Third line: Use ifconfig eth0 up to activate eth0; This command is equivalent to Ifup eth0
Line four: Use ifconfig eth0 to check the status of Eth0;
Of course, you can also use directly in the command IP address, netmask, broadcast address at the same time, to activate the network card, to add up parameters, such as the following example;
[[Email protected] ~] #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 of the network card (MAC address);
For example, we set the network card eth1 IP address, netmask, broadcast address, physical address and activate it;
[[Email protected] ~] #ifconfig eth1 192.168.1.252 hw ether 04:64:03:00:12:51 netmask 255.255.255.0 broadcast 192.168.1.25 5 up
Or
[[Email protected] ~] #ifconfig eth1 hw ether 04:64:03:00:12:51
[[Email protected] ~] #ifconfig eth1 192.168.1.252 netmask 255.255.255.0 broadcast 192.168.1.255 up
Where HW is followed by the network interface type, ether represents the Ethernet, but also support ax25, ARCnet, Netrom, etc., see Man ifconfig for details;
3. How to configure the virtual network interface with Ifconfig
Sometimes we need to configure the virtual network interface to meet different needs, such as we use a different IP address to run multiple httpd servers, it is necessary to use virtual address, so that the same IP address, if you open two httpd server, you want to specify the port number.
Virtual network interface refers to a network interface to specify multiple IP addresses, the virtual interface is such eth0:0, Eth0:1, Eth0:2 ... eth1n. Of course you specify multiple IP addresses for eth1, i.e. eth1:0, eth1:1, Eth1:2 ... And so on
In fact, with Ifconfig for a network adapter to configure multiple IP addresses, the use of the previous we said the use of ifconfig, this is relatively simple, see the following example;
[[Email protected] ~] #ifconfig eth1:0 192.168.1.251 hw ether 04:64:03:00:12:51 netmask 255.255.255.0 broadcast 192.168.1.255 up
Or
[[Email protected] ~] #ifconfig eth1 hw ether 04:64:03:00:12:51
[[Email protected] ~] #ifconfig eth1 192.168.1.251 netmask 255.255.255.0 broadcast 192.168.1.255 up
Note: When specifying, specify a different physical address for each virtual NIC;
In Redhat/fedora or Redhat/fedora-like systems, you can put the configuration network IP address, broadcast address, mask address, physical address, and activation network interface together 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:33: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:33:11:55 netmask 255.255.255.0 broadcast 192.168.1.255 up
Explanation: The above is for the ETH1 network interface, set up two virtual interface, each interface has its own physical address, IP address ...
4. How to use Ifconfig to activate and terminate a network interface connection
The use of the ifconfig command to activate and terminate a network interface, followed by a network interface, followed by a down or up parameter, prevents or activates the corresponding network interface. Of course, you can also use special tools Ifup and Ifdown tools;
[[Email protected] ~] #ifconfig eth0 down
[[Email protected] ~] #ifconfig eth0 up
[[Email protected] ~] #ifup eth0
[[Email protected] ~] #ifdown eth0
This is true for activating other types of network interfaces, such as Ppp0,wlan0, but is only valid for IP-specified NICs.
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; this you we should understand;
Like Redhat/fedora.
[[email protected] ~]#/etc/init.d/network start
Slackware release version;
[Email protected] ~]#/etc/rc.d/rc.inet1
This article is from the "Ubuntu Rights" blog, so be sure to keep this source http://10231879.blog.51cto.com/10221879/1659974
Ifconfig does not have eth0 and settings eth0