1. 默认网卡名称
pi@debian9:~$ ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:fc:e9:e5 brd ff:ff:ff:ff:ff:ff
inet 192.168.115.32/24 brd 192.168.115.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fefc:e9e5/64 scope link
valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:fc:e9:ef brd ff:ff:ff:ff:ff:ff
inet 192.168.145.135/24 brd 192.168.145.255 scope global ens37
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fefc:e9ef/64 scope link
valid_lft forever preferred_lft forever
有点难记,并且保不准会发生网卡移动后名称更改的情况.
想自定义原来的网卡名,
2. 修改grub
root用户修改/etc/default/grub:
找到GRUB_CMDLINE_LINUX=""
在引号中添加内容,变成如下:
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
然后root用户应用grub修改:
grub-mkconfig -o /boot/grub/grub.cfg
3 按照MAC地址绑定网卡名称
创建/编辑
/etc/udev/rules.d/70-persistent-net.rules
# interface with MAC address "00:0c:29:fc:e9:e5" will be assigned "eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:fc:e9:e5", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# interface with MAC address "00:0c:29:fc:e9:ef" will be assigned "eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:fc:e9:ef", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
注意修改MAC地址.
当然也可以改成自己需要的网卡名称:
例如把一块网卡重命名为:eth_dhcp
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:fc:e9:ef", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth_dhcp"
4. 修改完后注意修改/etc/network/interfaces中配置的网卡IP地址
重启生效