These three commands are used to start the network interface. However, ifup and ifdown can only be used for ifcfg-ethX (X is a number) in/etc/sysconfig/network-scripts) you cannot directly modify the network parameters when starting or disabling the ifcfg-ethX file. For ifconfig, You can manually configure IP addresses or adjust network parameters for an interface.
1. ifconfig
Ifconfig allows you to manually start, view, and modify parameters related to network interfaces. Many parameters can be modified, including IP Parameters and MTU. Its syntax is as follows:
[Root @ override top40 ~] # Ifconfig {interface} {up/down}
[Root @ override top40 ~] # Ifconfig [network device] [down up-allmulti-arp-promisc] [add <address>] [del <address>] [
Additional instructions
Note: ifconfig can set the status of network devices or display the current settings.
Parameters
Parameters:
The name of the [network device] network device.
Down to disable the specified network device.
Up to start the specified network device.
-Arp: Enables or disables the ARP protocol used on the specified interface. Add a negative sign to disable this option.
-Allmuti: no difference between disabling or starting a specified interface. Add a negative sign to disable this option.
-Promisc: Disable or start the promiscuous mode of the specified network device. Add a negative sign to disable this option.
Add <address> set the IPv6 IP address of the network device.
Del <address> Delete the IPv6 IP address of the network device.
Media <network media type> sets the media type of the network device.
Mem_start <memory address> sets the starting address occupied by the network device in the main memory.
Metric <quantity> specifies the number of data packets to be added when calculating the number of data packets to be transferred.
Mtu <byte> sets the MTU of the network device.
Netmask <subnet mask> sets the subnet mask of the network device.
Tunnel <address> establishes the tunnel communication address between IPv4 and IPv6.
-Broadcast <address> processes data packets sent to the specified address as broadcast data packets.
-The pointopoint <address> is directly connected to the network device of the specified address. This mode has the confidentiality function.
Nic commands
Whether it is Linux automatic installation or manual installation, Linux will ask you about network problems and configure related software. The basic command used to configure the NIC is ifconfig.
After executing the ifconfig command, the system will set necessary parameters in the kernel table, so that Linux will know how to communicate with the network card. The ifconfig command has the following two formats:
※Ifconfig [interface]
※Ifconfig interface [aftype] option | address...
The first format of ifconfig (or the ifconfig command without any parameters) can be used to view the network configuration of the current system.
After installing the system, you actually use Linux without a network adapter or network connection. However, ifconfig allows you to work in a loop to make the computer think that it is working on the network.
Run the ifconfig command. The ifconfig command without parameters can display the network interface currently started. The output result is:
[Root @ override top40 ~] # Ifconfig
Eth0 Link encap: Ethernet HWaddr 52: 54: AB: DD: 6F: 61
Inet addr: 210.34.6.89 Bcast: 210.34.6.127 Mask: 255.255.255.128
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 46299 errors: 0 dropped: 0 overruns: 0 frame: 189
TX packets: 3057 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 100
Interrupt: 5 Base address: 0xece0
Lo Link encap: Local Loopback
Inet addr: 127.0.0.1Mask: 255.0.0.0
Up loopback running mtu: 3924 Metric: 1
RX packets: 44 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 44 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
The part headed by eth0 is the ethernet card configuration parameter of the local machine. The device name/dev/eth0 of the nic and the MAC address of the hardware are shown as 52: 54: AB: DD: 6F: 61. The MAC address is determined by the manufacturer. Each Nic has a unique address.
However, you can manually change the MAC address of the NIC as long as we add the following to the network in/etc/rc. d/init. d:
Ifconfig eth0 hw ether xx: xx
Jiania commentary note:
Eth0, eth1, and eth2 indicate network adapter 1, network adapter 2, and network adapter 3.
Hw stands for hardware
Ether indicates ethernet.
Then restart and run the ifconfig command to check whether the MAC address of the NIC has changed to xx: xx.
Configure the NIC
Configure the IP address of the NIC
Ifconfig eth0 192.168.0.1 netmask 255.255.255.0
Configure the IP address and 24-bit mask of 192.168.0.1 on eth0. What if I want to configure another IP address 192.168.1.1/24 on eth0? Use the following command
Ifconfig eth0: 0 192.168.1.1 netmask 255.255.255.0
Then run the ifconifg command to view the information of the two NICs: eth0 and eth0: 0. if you want to add more IP addresses, the name of the NIC will be: eth0: 1, eth0: 2 ...... Enter a few if you want. OK!
Configure the hardware address of the NIC
Ifconfig eth0 hw ether xx: xx changes the hardware address of the NIC. In this case, you can cheat the IP address bound to the LAN.
Disable Nic
Ifconfig eth0 down
Enable the NIC
Ifconfig eth0 up
The ifconfig command has powerful functions. You can also set the MTU and hybrid mode of the NIC.
2. ifup/ifdown
Syntax format: ifdown/ifup + interface
The interface must be the ethX corresponding to the ifcfg-ethX file in the/etc/sysconfig/network-scripts/directory.
Ifup and ifdown: These two files are script files and start network interfaces in a simpler way. Ifup and ifdown start or close ifcfg-ethX in/etc/sysconfig/network-scripts, but cannot directly modify network parameters unless you adjust the ifcfg-ethX file!
[Root @ override top40 ~] # Ifdown eth0
Note: ifdown/ifup starts and closes corresponding interfaces by searching the setting file (ifcfg-ethx, therefore, before use, determine whether ifcfg-ethX exists in the correct directory, otherwise it will start to become invalid. In addition, if ifconfig eth0 is used to set or modify the network interface information, then you can no longer ifdown eth0 to close the way, because ifdown will analyze and compare the current network parameters and ifcfg-eth0 is consistent, if not, will give up this operation, therefore, if ifconfig is used after modification, you must use ifconfig eth0 down to disable this interface.