Linux:ifconfig command

HLee 2022-06-24 05:29:12 阅读数:846

linuxifconfigcommand

ifconfig Commands are used to configure and display Linux Network parameters of network interface in kernel . use ifconfig Command configuration network card information , After the network card restarts, the machine restarts , Configuration doesn't exist . To store the above configuration information in the computer forever , Then you need to modify the configuration file of the network card .

 grammar :ifconfig ( Parameters )
Parameters :
add< Address >: Set up network devices IPv6 Of ip Address ;
del< Address >: Delete network device IPv6 Of IP Address ;
down: Turn off the specified network device ;
<hw< Network device type >< Hardware address >: Set the type of network device and hardware address ;
io_addr<I/O Address >: Set up the I/O Address ;
irq<IRQ Address >: Set up the IRQ;
media< Types of Internet media >: Set the media type of the network device ;
mem_start< Memory address >: Set the starting address of the network device in the main memory ;
metric< number >: Specifies when calculating the number of transfers of packets , The number to be added ;
mtu< byte >: Set up the MTU;
netmask< Subnet mask >: Set the subnet mask of the network device ;
tunnel< Address >: establish IPv4 And IPv6 The tunnel communication address between ;
up: Start the specified network device ;
-broadcast< Address >: Treat the packets to be sent to the specified address as broadcast packets ;
-pointopoint< Address >: Establish a direct connection with the network device at the specified address , This mode has the function of confidentiality ;
-promisc: Turn off or start the... Of the specified network device promiscuous Pattern ;
IP Address : Specify the... Of the network device IP Address ;
Network devices : Specify the name of the network device .

example : Display network device information ( Activated )

[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:16:3E:00:1E:51
inet addr:10.160.7.81 Bcast:10.160.15.255 Mask:255.255.240.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:61430830 errors:0 dropped:0 overruns:0 frame:0
TX packets:88534 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3607197869 (3.3 GiB) TX bytes:6115042 (5.8 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:56103 errors:0 dropped:0 overruns:0 frame:0
TX packets:56103 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5079451 (4.8 MiB) TX bytes:5079451 (4.8 MiB)
explain :
eth0 Indicates the first network card , among HWaddr Represents the physical address of the network card , You can see the physical address of the current network card (MAC Address ) yes 00:16:3E:00:1E:51.
inet addr Used to represent network card IP Address , NIC IP The address is 10.160.7.81, Broadcast address Bcast:10.160.15.255, Mask address Mask:255.255.240.0.
lo Is the return address of the host , This is usually used to test a network program , But they don't want users on the LAN or the Internet to be able to view it , You can only run and view the network interface used on this host . For example httpd Server's designated back to bad address , Type in the browser 127.0.0.1 You can see what you're up to WEB The web site . But you can see it , No other host or user of LAN knows .
first line : Connection type :Ethernet( Ethernet )HWaddr( Hardware mac Address ).
The second line : NIC IP Address 、 subnet 、 Mask .
The third line :UP( On behalf of network card )RUNNING( The network cable representing the network card is connected )MULTICAST( Support multicast )MTU:1500( Maximum transmission unit ):1500 byte .
Fourth 、 Five elements : receive 、 Statistics of packets sent .
Seventh elements : receive 、 Send data bytes statistics .

example : Start and close the specified network card

ifconfig eth0 up
ifconfig eth0 down
Be careful :ifconfig eth0 up To start the NIC eth0,ifconfig eth0 down To turn off the NIC eth0.ssh land linux Server operation should be careful , If it's closed, it can't be opened , Unless you have multiple network cards .

example : Configure and delete the network card IPv6 Address

ifconfig eth0 add 33ffe:3240:800:1005::2/64 # For network card eth0 To configure IPv6 Address
ifconfig eth0 del 33ffe:3240:800:1005::2/64 # For network card eth0 Delete IPv6 Address 

example : use ifconfig modify MAC Address

ifconfig eth0 hw ether 00:AA:BB:CC:dd:EE

example : To configure IP Address

[[email protected] ~]# ifconfig eth0 192.168.2.10
[[email protected] ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0
[[email protected] ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0 broadcast 192.168.2.255

example : Turn on and off arp agreement

ifconfig eth0 arp # Open network card eth0 Of arp agreement
ifconfig eth0 -arp # Close network card eth0 Of arp agreement 

example : Set the maximum transmission unit

ifconfig eth0 mtu 1500 # Set the maximum packet size that can be passed to 1500 bytes

example : Other examples

ifconfig # Active network interface
ifconfig -a # All configured network interfaces , Whether it's activated or not
ifconfig eth0 # Show eth0 Network card information of 
copyright:author[HLee],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/175/20210811191028283r.html