In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Detailed explanation of ifconfig and route configuration Network under Linux system
Ifconfig and route are used to configure the network (the ip command combines the two functions, not discussed here). Usually, after the former sets information such as ip address, the route command is used to configure routing. (dynamically assign the network of the ip to the DHCP, and activate this ip). The route command is not covered in this article.
1. Ifconfig command
The ifconfig command makes the LINUX core aware of network interfaces such as software loopback and network cards 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 take a number of command-line parameters. Here is a general invocation syntax for ifconfig:
# ifconfig [- v] [- a] [- s] interface
# ifconfig [- v] interface [[- net-host] [address | parameters] +]
Where interface is the network interface name and address is the hostname or IP address assigned to the specified interface. The hostnames used here are resolved to their peer IP address, and this parameter is required. The-net and-host parameters tell ifconfig to use this address as the network number or host address, respectively.
The positions of the following address and parameters parameters can be exchanged in groups. + indicates that there can be one or more parameters of this class
If you call the ifconfig command followed by only the port device name, it will show the configuration of the port; if you don't take any parameters, the ifconfig command will show all the information about the interfaces configured so far; and if you have the-an option, you can also show the currently inactive interfaces.
An ifconfig call that checks the Ethernet interface eth0 produces 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 255.255.255.0
UP BROADCAST RUNNING MTU 1500 Metric 0
RX packets 3136 errors 217 dropped 7 overrun 26
TX packets 1752 errors 25 dropped 0 overrun 0
(note: where XXX.XXX.XXX.XXX is the IP address)
The MTU and Metric columns show the most big data transfer value and interface metric of the current eth0 interface. The interface metric represents the cost of sending a packet on this path. Routing is not currently used in the kernel, but it may be used later. The lines RX (number of packets received) and TX (number of packets transmitted) show the number of packets received and transmitted, as well as the number of packet errors, the number of packets lost (one possible reason is less memory), and the number of overruns (which usually occurs when the receiver receives data faster than the core processing speed).
Parameters represents the various parameters supported by ifconfig, which can be used to easily monitor and change the state of the network interface.
Command line arguments for ifconfig:
Up activates the specified interface
Down shuts down the specified interface. This parameter effectively blocks IP traffic through a specified interface. If we want to permanently shut down an interface, we also need to delete 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 the prefix 0x or four decimal digits separated by dots. If you are not going to divide the network into subnets, you can ignore this option; if you are using subnets, keep in mind that every system in the network must have the same subnet mask.
Pointpoint turns on 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, turn on the POINTPOINT option for the specified interface. Preceded by a minus sign indicates that the pointpoint option is turned off.
Broadcast address sets the broadcast address of this interface when an address is used. If no address is given, turn on the IFF_BROADCAST option for the specified interface. Preceded by a minus sign indicates that this option is turned off.
Metric number sets the interface metric to the integer number. The measure represents the cost of sending a packet on this path. Routing costs are not currently used in the kernel, but they will be in the future.
Mtu bytes sets the maximum number of bytes that the interface can handle in a single transfer to the integer bytes. At present, the core network code does not deal with IP segmentation, so be sure to set the value of MTU (the most big data transmission unit) large enough.
Arp turns on or off the ARP protocol used on the specified interface. A negative sign is preceded by a negative sign to turn off this option.
Allmuti turns on the undifferentiated mode of the specified interface. Turn on this mode to let the interface send all the information flow on the network to the core, not just send your machine's information to the core. Preceded by a minus sign indicates that the option is turned off
Hw class address sets the hardware type and hardware address for the specified interface. The ASCII character of the hardware type name and secondary hardware address equivalent must follow this keyword. Currently supported hardware types (hardware class) include ether, AMPR, AX.25, and PPP traliers to turn on the tracker on the Ethernet frame. It is not currently implemented in LINUX networks, and you usually do not need to use all of these configurations.
Ifconfig can set everything you need simply by the interface name, the netmask, and the assigned IP address. When ifconfig omits or has a complex network, just reset most of the parameters.
Check the status of the network using netstat
Next, we introduce a very useful command-netstat, which uses the netstat command to monitor the configuration and operation of the TCP/IP network. It displays the kernel routing table, the active network status, and useful statistics for each network interface. For more information, please refer to man page.
-a displays information about all Internet connections, including those that are being monitored
-I display statistics for all network devices
-c constantly displays the update status of the network. This parameter uses netstat's output list of network states once a second until the program is interrupted
-n displays remote address, local address, and port information in numeric / raw form, rather than resolving hostname and server
-o displays the end time of the counter and the back off of each network connection
-r displays the kernel routing table (netstat-r command is equivalent to route command)
-t displays only TCP socket information, including the information being monitored
-u displays only UDP socket information
-v displays netstat version information
-w displays raw (raw) socket information
-x displays the UNIX domain socket information
= =
Ifconfig detailed explanation
2009-01-12 00:54
Ifconfig is a very common tool for viewing, configuring, enabling, or disabling network interfaces. You can use this tool to temporarily configure the IP address, mask, broadcast address, gateway, etc. You can also write it to a file (such as / etc/rc.d/rc.local), so that after the system boots, it reads the file and sets the IP address for the network card.
1.ifconfig to view the status of network interfaces
If ifconfig does not take any parameters, it will output the current network interface
[root@linuxchao ~] # 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)
Commentary:
Eth0 represents the first network card, where HWaddr represents the physical address of the network card. You can see that the current physical address (MAC address) of this network card is 00Rom 03LV 0DRO 27RV 86RV 41; inet addr is used to represent the IP address of the Nic, and the IP address of this Nic is 192.168.1.86, broadcast address, Bcast:192.168.1.255, mask address Mask:255.255.255.0.
Lo is the bad address of the host, which is generally used to test a network program, but does not want users of the local area network or external network to view it, so it can only run and view the network interface used on this host. For example, assign the HTTPD server to the bad address and type 127.0.0.1 in the browser to see your WEB site. But only you can see, other hosts or users of the local area network do not know.
If you want to know all the network interfaces of the host, use the following command
[root@linuxchao] # ifconfig-a
If you want to view a port, such as the status of eth0, you can use the following method
[root@linuxchao ~] # ifconfig eth0
2.ifconfig configure network interface
Ifconfig can be used to configure the IP address, mask, gateway, physical address of the network interface; it is worth mentioning that ifconfig is used to specify the IP address for the network card, which is only used to debug the network, and will not change the configuration file of the system about the network card. If you want to fix the IP address of the network interface, there are three ways: one is to modify the IP address through the special tools for each release and version; the second is to modify the configuration file of the network interface directly; the third is to modify the specific file and add the ifconfig instruction to specify the IP address of the network card. For example, in redhat or Fedora, write the name of ifconfig into the / etc/rc.d/rc.local file.
How to configure network ports in ifconfig:
The method of configuring the network interface of the ifconfig tool is achieved through the parameters of the instructions, we will only talk about the most commonly used parameters
Ifconfig Nic IP address hw class MAC address netmask mask address broadcast broadcast address [up/down]
* example 1:
For example, we use ifconfig to debug the address of the eth0 network card.
[root@linuxchao ~] # ifconfig eth0 down
[root@linuxchao ~] # ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0
[root@linuxchao ~] # ifconfig eth0 up
[root@linuxchao ~] # 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: let's explain the above example
The first line: ifconfig eth0 [inet] down means that if eth0 is active, DOWN it off. This command is equivalent to ifdown eth0
Line 2: use ifconfig to configure eth0's IP address, broadcast address, and network mask
Line 3: activate eth0 with ifconfig eth0 [inet] up; this command is equivalent to ifup eth0
Line 4: use ifconfig eth0 to check the status of eth0
Of course, you can also activate the network card directly while instructing the IP address, network mask and broadcast address; add the up parameter; for example, the following example
[root@linuxchao ~] # ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0 inet up
The above four parts (apple background and underscore) can be out of order, and inet is the default, so you can not write it.
* example 2: in this example, we should learn to set the physical address (MAC address) of the network card as well as the network IP address.
For example, we set the IP address, network mask, broadcast address, physical address of the network card eth2 and activate it.
[root@linuxchao ~] # ifconfig eth2 192.168.1.252 hw ether 04 hw ether 64 netmask 255.255.255.0 broadcast 192.168.1.255 up
Or
[root@linuxchao ~] # ifconfig eth2 hw ether 04R 64R 03R 00R 1251
[root@linuxchao ~] # ifconfig eth2 192.168.1.252 netmask 255.255.255.0 broadcast 192.168.1.255 up
Hw is followed by the type of network interface. Ether represents Ethernet. It also supports ax25, ARCnet, netrom, etc. For more information, please see man ifconfig.
3. How to configure virtual network interface with ifconfig
Sometimes we need to configure virtual network interfaces to meet different needs. For example, if we use different IP addresses to set up and run multiple HTTPD servers, we need to use virtual addresses; this eliminates the need for the same IP address. If you set up two HTTPD servers, you should specify the port number.
A virtual network interface refers to specifying multiple IP addresses for a network interface. Virtual interfaces are eth0:0, eth0:1, eth0:2. Eth2N . Of course, you specify multiple IP addresses for eth2, that is, eth2:0, eth2:1, eth2:2. And so on.
In fact, using ifconfig to configure multiple IP addresses for a network card, just use the use of ifconfig mentioned earlier, which is relatively simple; take a look at the following example
[root@linuxchao ~] # ifconfig eth2:0 192.168.1.251 hw ether 04 hw ether 04 netmask 255.255.255.0 broadcast 192.168.1.255 up
Or
[root@linuxchao ~] # ifconfig eth2 hw ether 04R 64R 03R 00R 1251
[root@linuxchao ~] # ifconfig eth2 192.168.1.251 netmask 255.255.255.0 broadcast 192.168.1.255 up
Note: when specified, each virtual network card should be assigned a different physical address.
On Redhat/Fedora or a system similar to Redhat/Fedora, you can put the configured network IP address, broadcast address, mask address, physical address, and active network interface in one sentence at the same time, and write it into / etc/rc.d/rc.local. For example, the following example
Ifconfig eth2: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 eth2: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 the network interface for eth2, set up two virtual interfaces; each interface has its own physical address, IP address.
4. How to activate and terminate the connection of a network interface with ifconfig
Activate and terminate the network interface with the ifconfig command, followed by the network interface, and then add the down or up parameters, you can disable or activate the corresponding network interface. Of course, you can also use special tools ifup and ifdown tools.
[root@linuxchao ~] # ifconfig eth0 down
[root@linuxchao ~] # ifconfig eth0 up
[root@linuxchao ~] # ifup eth0
[root@linuxchao ~] # ifdown eth0
The same is true for activating other types of network interfaces, such as ppp0,wlan0, etc., but only for NICs that specify IP.
Note: the IP automatically assigned to DHCP must also be activated by the network tools included in each distribution; of course, you have to install the dhcp client; we should understand this.
Like Redhat/Fedora.
[root@linuxchao ~] # / etc/init.d/network start
Slackware distribution
[root@linuxchao ~] # / etc/rc.d/rc.inet1
There are dhcpcd, dhcp3-client (dhclient) and another software package under debian, only one is needed. For details, see the section on "debian configuring the Network" on the official home page.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.