Linux system view network card configuration information

  There are several ways to view network card configuration in Linux system, which are described below.

  1. Method 1: ifconfig command to view and set the network card
  • ifconfig: View all active network card information, you can view the IP address and subnet mask, but you cannot view the gateway and DNS address. You can also temporarily set the IP address and subnet mask of a certain network card.
[root@cloudgw ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.19.243.202  netmask 255.255.240.0  broadcast 172.19.255.255
        ether 00:16:3e:04:2c:c4  txqueuelen 1000  (Ethernet)
        RX packets 387660324  bytes 226790748853 (211.2 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 328446865  bytes 259013344959 (241.2 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1  (Local Loopback)
        RX packets 249981451  bytes 195165066686 (181.7 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 249981451  bytes 195165066686 (181.7 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  eth0 is the first network card, lo represents the information of the local loopback network card.

  • ifconfig -a: View all network card information, the result is as shown above.
  • ifconfig eth0: View the information of the specific network card eth0
[root@cloudgw ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.19.243.202  netmask 255.255.240.0  broadcast 172.19.255.255
        ether 00:16:3e:04:2c:c4  txqueuelen 1000  (Ethernet)
        RX packets 387661202  bytes 226790872151 (211.2 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 328447665  bytes 259013675834 (241.2 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  1. Method 2: View the network card information through the Linux network configuration file.
    Enter the /etc/sysconfig/network-scripts/ path, you can see the file information of different network cards.
[root@cloudgw ~]# cd /etc/sysconfig/network-scripts/
[root@cloudgw network-scripts]# ll
total 224
-rw-r--r--  1 root root    38 May  2  2018 ifcfg-eth0
-rw-r--r--. 1 root root   254 May  3  2017 ifcfg-lo
---

  View the information of the first network card

[root@cloudgw network-scripts]# cat ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

  For more information, see the table below.

Configuration Description
DEVICE=eth0 Network card device name, eth0 means the first network card
BOOTPROTO=none Whether to automatically obtain IP (none, static, dhcp), when the value is dhcp, you only need to configure those items in the above example to connect to the Internet
HWADDR=00:0C:29:11:30:39 MAC address
NM_CONTROLLED=yes Can it be hosted by the Network Manager graphical management tool
ONBOOT=yes Whether the current network card takes effect when the network service is started (ONBOOT is disabled by default in CentOS 6 and above)
TYPE=Ethernet Network type, here is Ethernet
UUID=5ab36190-a5df-4bf1-94d8-6c126afd05f1 Unique identification code
IPADDR=192.168.0.200 IP address
NETMASK=255.255.255.0 Subnet mask
GATEWAY=192.168.0.1 Gateway
DNS1=202.106.0.20 DNS
IPV6INIT=no Whether IPv6 is enabled, here is set to not enable
USERCTL = no Whether to allow non-root users to control this network card, here is not allowed

  Description:

  • The condition for obtaining IP automatically is: There must be a DHCP server in the LAN.
  • Computers with the same UUID network configuration will cause each other to be unable to access the Internet.
Article reference

Guess you like

Origin blog.csdn.net/piaoranyuji/article/details/113735345