debian9 修改网卡命名规则

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地址

 

重启生效

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值