CentOS
传统命名方式-修改网卡名称
1.vim /etc/default/grub
GRUB_CMDLINE_LINUX="rhgb quiet net.ifnames=0"
2.为grub2生成其配置文件
UEFI引导模式下:
grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
传统引导模式:
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-mkconfig -o /etc/grub2.cfg
3. cd /etc/sysconfig/network-scripts
mv ifcfg-ens33 ifcfg-eth0
4.reboot
网卡配置文件
cd /etc/sysconfig/network-scripts
mv ifcfg-ens33 ifcfg-eth0
vim ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.150
PREFIX=24
GATEWAY=10.0.0.2
DNS1=218.30.19.40
DNS2=10.0.0.2
DOMAIN=baidu.com
ONBOOT=yes
vim ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=dhcp
DOMAIN=baidu.com
ONBOOT=yes
------------------------------------------------------------------------------
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.150
PREFIX=24
IPADDR1=10.0.0.151
PREFIX1=24
IPADDR2=10.0.0.152
PREFIX2=24
GATEWAY=10.0.0.2
DNS1=218.30.19.40
DNS2=10.0.0.2
DOMAIN=baidu.com
ONBOOT=yes
网卡配置生效方法
nmcli connection reload 加载配置文件
nmcli connection up eth0启动网卡
service network restart
验证网卡配置是否生效
ip a
route -n
cat /etc/resolv.conf
其他工具
ifconfig -淘汰
ifconfig eth0:1 1.1.1.1/24
ifconfig eth0:1 down
ifconfig eth0 192.168.1.163/24
ifconfig eth0 0
ifconfig -s
ip
ip link
ip link set eth0 down
ip address
ip address add 1.1.1.1/24 dev eth0
ip address del 1.1.1.1/24 dev eth0
netstat -淘汰
netstat -s
ss
ss-ntl
ss-nta
ss-ntau
Ubuntu
ubuntu网卡配置yaml格式,缩进统一
vim /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0"
:wq
grub-mkconfig -o /boot/grub/grub.cfg
grep net.ifnames /boot/grub/grub.cfg
----------------------------------------
vim /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 10.0.0.152/24
gateway4: 10.0.0.2
nameservers:
search: [baidu.com]
addresses: [8.8.8.8,10.0.0.2]
netplan apply
ip a
route -n
systemd-resolve --status