LINUX 网络
1. 网络配置命令
1.1 ifconfig
来自于net-tools包
[root@localhost ~]#rpm -qi net-tools
Name : net-tools
Version : 2.0
Release : 0.22.20131004git.el7
Architecture: x86_64
Install Date: 2021年08月06日 星期五 20时58分47秒
Group : System Environment/Base
Size : 938986
License : GPLv2+
Signature : RSA/SHA256, 2017年08月11日 星期五 02时30分02秒, Key ID 24c6a8a7f4a80eb5
Source RPM : net-tools-2.0-0.22.20131004git.el7.src.rpm
Build Date : 2017年08月03日 星期四 17时17分34秒
Build Host : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://sourceforge.net/projects/net-tools/
Summary : Basic networking tools
Description :
The net-tools package contains basic networking tools,
including ifconfig, netstat, route, and others.
Most of them are obsolete. For replacement check iproute package.
基础用法
在不带任何选项和参数执行 ifconfig 命令时, 将显示当前主机中已启用(活动)的网络接口信息
网卡名称详解:
ens33:第一块以太网卡的名称详解:
“ens33”中的“en”是“EtherNet”的缩写,表示网卡
类型为以太网,“s”表示热插拔插槽上的设备(hot-plug Slot),数字“33”表示插槽 编号
[root@localhost ~]#ifconfig
ens33: flags=4163<UP, BROADCAST,RUNNING,MULTICAST> mtu 1500
该接口 已启用,支持广播、 正在运行 支持组播 最大传输单元1500字节
inet 192.168.91.100 netmask 255.255.255.0 broadcast 192.168.91.255
inet6 fe80::fe7:ca03:81f:2887 prefixlen 64 scopeid 0x20<link>
IPV6地址 子网长度 作用域 link表示仅该接口有效
ether 00:0c:29:fe:e5:bf txqueuelen 1000 (Ethernet)
mac地址 传输队列长度(传输缓存大小) 接口类型
RX packets 2211 bytes 182146 (177.8 KiB)
接收 报文个数 总和字节数
RX errors 0 dropped 0 overruns 0 frame 0
接收 错误 丢弃 溢出 冲突帧数
TX packets 1317 bytes 294334 (287.4 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 1 (Local Loopback)
RX packets 82 bytes 7100 (6.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 82 bytes 7100 (6.9 KiB)
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:e8:a0:b9 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
常用格式:
ifconfig 具体网卡名称 #只显示具体网卡的详细信息(无论该网卡是否使用)
ifconfig -a #表示显示所有网卡包括没有启动的网卡
ifconfig 网卡名称 [up|down] #表示开启或关闭网卡
ifconfig 网络接口 ip地址 [netmask 子网掩码]
ifconfig 网络接口 ip地址[/子网掩码长度]
ifconfig ens33:0 地址 #表示虚拟网卡
[root@localhost ~]#ifconfig ens37 down
#关闭
[root@localhost ~]#ifconfig ens37 up
#开启
[root@localhost ~]#ifconfig ens37:0 192.168.91.200
#设置临时虚拟网卡
[root@localhost ~]#ifconfig ens37:0
ens37:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.91.200 netmask 255.255.255.0 broadcast 192.168.91.255
ether 00:0c:29:fe:e5:c9 txqueuelen 1000 (Ethernet)
[root@localhost ~]#ifconfig ens37:0 down
#关闭虚拟网卡
[root@localhost ~]#ifconfig -a
#查看所有网卡包括为开启的
[root@localhost ~]#ifconfig -s
#网络通讯情况
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
ens33 1500 7491 0 0 0 2617 0 0 0 BMRU
lo 65536 86 0 0 0 86 0 0 0 LRU
virbr0 1500 0 0 0 0 0 0 0 0 BMU
ip a
#先加新IP,再删除旧的IP
[root@centos8 ~]#ip address add 10.0.0.88/24 dev ens33
[root@centos8 ~]#ip address del 10.0.0.8/24 dev ens33
[root@centos8 ~]#ip a
1.2 hostname
查看或设置当前主机名
hostname [主机名]
[root@localhost ~]#hostname
localhost.localdomain
#临时生效