linux网络配置

zhenjingcool / 2023-09-05 / 原文

linux网络配置工具有多种,比如ifconfig、ip、nmcli等。他们都可以进行网卡方面的配置,下面会分别介绍

1 ifconfig

ifconfig历史比较悠久,最早出现在unix系统上。

使用ifconfig命令,我们可以查看网卡(网络接口卡)信息,比如接口(interface)名称、mac地址、IP地址、子网、广播地址等。

查询所有网络接口

 ifconfig -a 

  • ens33:网卡名称
  • UP:接口已启用
  • BROADCAST:主机支持广播
  • RUNNING:表示接口在工作中
  • MULTICAST:主机支持多播
  • MTU 1500:最大传输单元1500字节
  • inet:ipv4地址,netmask:子网掩码,broadcast:广播地址(广播地址什么意思?比如某个子网为192.168.3.0/24,则广播地址为192.168.3.255。当在这个子网中某节点需要将报文发送到所有节点时,目的地址可以使用广播地址)
  • ether:表示连接类型为以太网
  • 00:0c:29:cc:cf:d7:mac地址
  • txqueuelen 1000:网卡传送队列长度
  • RX packets :接受到的总包数
  • RX bytes :接受到的总字节数
  • RX errors :接收时,产生错误的数据包数
  • RX dropped :接收时,丢弃的数据包数
  • RX overruns :接收时,由于速度过快而丢失的数据包数
  • RX frame (框架) :接收时,发生frame错误而丢失的数据包数
[root@localhost ~]# ifconfig -a
br-ed5a3cc94630: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.49.1  netmask 255.255.255.0  broadcast 192.168.49.255
        ether 02:42:0e:86:b4:69  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.148  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::9375:e7ad:e439:9325  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:cc:cf:d7  txqueuelen 1000  (Ethernet)
        RX packets 119  bytes 17196 (16.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 130  bytes 20125 (19.6 KiB)
        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
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:1f:62:ea  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0-nic: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 52:54:00:1f:62:ea  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]#