1. 网卡命名
1.1 传统网卡命名机制
传统命名:
以太网eth[0,1,2,…]
wlan[0,1,2,…]
1.2 redhat7网卡命名机制
systemd对网络设备的命名方式:
1.如果Firmware或BIOS为主板上集成的设备提供的索引信息可用,且可预测,则根据此索引进行命名,例如eno1
2.如果Firmware或BIOS为PCI-E扩展槽所提供的索引信息可用,且可预测,则根据此索引进行命名,例如ens1
3.如果硬件接口的物理位置信息可用,则根据此信息进行命名,例如enp2s0
4.如果用户显式启动,也可根据MAC地址进行命名,例如enx2387a1dc56
5.上述均不可用时,则使用传统命名机制
上述命名机制中,有的需要biosdevname程序的参与。所以必须安装biosdevname程序且启用它。
1.3 网络接口名称组成格式
基于固件、设备结构、设备类型
- 由两个字母开头标示固件
- 以太网网卡以 en 开头
- 无线网卡以 wl 开头
- 设备结构
- o:主板上集成的设备的设备索引号
- s:扩展槽的索引号
- x:基于MAC地址的命名
- p < bus> s < slot >:基于物理位置拓扑的命名。如enp2s1,表示PCI总线上第2个总线的第1个插槽的设备索引号
1.4 回归传统命名
//修改网卡配置文件
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# mv ifcfg-ens33 ifcfg-eth0
[root@localhost network-scripts]# vim ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0 //此处要把ens33改成eht0
UUID=03be31f5-a3c1-4f8d-88b3-aea6e85c869f
DEVICE=eth0 //此处要把ens33改成eth0
ONBOOT=yes
//编辑/etc/default/grub配置文件,在以GRUB_CMDLINE_LINUX开头的行内rhgb的前面加上net.ifnames=0 biosdevname=0
[root@localhost ~]# vim /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap net.ifnames=0 biosdevname=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
//为grub2生成其配置文件
[root@localhost ~]# grub2-mkconfig -o /etc/grub2.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-fd0bcf5782d24ba5b903b175c35f328e
Found initrd image: /boot/initramfs-0-rescue-fd0bcf5782d24ba5b903b175c35f328e.img
done
//重启系统
[root@localhost ~]# reboot
2. 网络管理常用命令
2.1 ifconfig
//查看当前处于活动状态的所有网络接口
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.12.128 netmask 255.255.255.0 broadcast 172.16.12.255
inet6 fe80::20c:29ff:fe73:110 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:73:01:10 txqueuelen 1000 (Ethernet)
RX packets 5121 bytes 424364 (414.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3813 bytes 3257482 (3.1 MiB)
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 4 bytes 344 (344.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 344 (344.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
//仅查看eth0网卡状态
[root@localhost ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.12.128 netmask 255.255.255.0 broadcast 172.16.12.255
inet6 fe80::20c:29ff:fe73:110 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:73:01:10 txqueuelen 1000 (Ethernet)
RX packets 5148 bytes 426572 (416.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3828 bytes 3259946 (3.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
//查看所有网卡状态信息, 包括禁用和启用
[root@localhost ~]# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.12.128 netmask 255.255.255.0 broadcast 172.16.12.255
inet6 fe80::20c:29ff:fe73:110 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:73:01:10 txqueuelen 1000 (Ethernet)
RX packets 5177 bytes 428948 (418.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3844 bytes 3262104 (3.1 MiB)
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 4 bytes 344 (344.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 344 (344.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
//网卡配置信息含义如下:
UP: 网卡处于活动状态
BROADCAST: 支持广播
RUNNING: 网线已接入
MULTICAST: 支持组播
MTU: 最大传输单元(字节),即此接口一次所能传输的最大封包
inet: 显示IPv4地址行
inet6: 显示IPv6地址行
link/enther: 指设备硬件(M