玉米阳光 發表於 2019-5-29 16:54:00

ubuntu 网卡名称重命名

<h1>ubuntu 网卡名称重命名</h1>
<p>&nbsp;</p>
<p>参考:https://blog.csdn.net/hzj_001/article/details/81587824</p>
<div class="cnblogs_code">
<pre>biosdevname 和 net.ifnames 两种命名规范
---------------------------------------
net.ifnames 的命名规范为: &nbsp;&nbsp;设备类型+设备位置+数字

设备类型:
en 表示Ethernet
wl 表示WLAN
ww 表示无线广域网WWAN

实际的例子:
eno1 板载网卡
enp0s2 &nbsp;pci网卡
ens33 &nbsp;&nbsp;pci网卡
wlp3s0 &nbsp;PCI无线网卡
wwp0s29f7u2i2 &nbsp;&nbsp;4G modem
wlp0s2f1u4u1 &nbsp;&nbsp;连接在USB Hub上的无线网卡
enx78e7d1ea46da pci网卡

---------------------------------------

biosdevname 的命名规范为:

实际的例子:
em1 板载网卡
p3p4 pci网卡
p3p4_1 虚拟网卡

---------------------------------------</pre>
</div>
<p>&nbsp;</p>
<p>修改 grub&nbsp;引导参数</p>
<div class="cnblogs_code">
<pre># 查看 GRUB_CMDLINE_LINUX 变量
$ cat /etc/default/grub | grep GRUB_CMDLINE_LINUX

# 修改 GRUB_CMDLINE_LINUX 变量
$ sudo sed -i 's/^.*GRUB_CMDLINE_LINUX="".*$/GRUB_CMDLINE_LINUX="<span style="color: rgba(0, 0, 255, 1)">net.ifnames=0 biosdevname=0</span>"/g' /etc/default/grub

# 更新grub引导
$ sudo update-grub

# 重启系统
$ sudo reboot<br><br></pre>
</div>
<p>&nbsp;</p>
<p>参考:https://kb.vmware.com/s/article/1032790</p>
<p>&nbsp;</p>
<div class="cnblogs_code">
<pre># 查看所有网卡列表
$ ifconfig -s<br>$ ifconfig -a

# 查看网络设备类型的设备配置规则
$ cat /etc/udev/rules.d/70-persistent-net.rules | grep net

# 执行 write_net_rules 脚本,此脚本会更新 /etc/udev/rules.d/70-persistent-net.rules 文件
# "ethN" 指网卡设备名称,例如:"eth0"
# "xx:xx:xx:xx:xx:xx" 指网卡设备的MAC地址,例如:"00:10:f3:5a:96:36"
$ sudo rm /etc/udev/rules.d/70-persistent-net.rules
$ sudo env INTERFACE="ethN" MATCHADDR="xx:xx:xx:xx:xx:xx" /lib/udev/write_net_rules


# 查看网卡名称设备对应的MAC地址
$ ifconfig -a eth0 | grep HWaddr

# 查看网卡名称设备的带宽速率
$ ethtool eth0 | grep "link mode"

# 查看网卡名称设备对应的PCIID
$ ethtool -i eth0 | grep bus

# 查看网卡名称设备对应的驱动
$ ethtool -i eth0 | grep driver

# 查看网卡设备的PCIID
$ lspci | grep -i eth
# 查看PCIID的设备信息
$ lspci -D -n -vvv -s 01:00.0
# 查看指定设备ID的设备信息
$ lspci -D -n -vvv -d 8086:10fb

# 查看系统指定设备信息
$ udevadm info -a -p /sys/class/net/eth0
<br># 重新加载设备规则配置文件<br>$ sudo chmod a+x /etc/udev/rules.d/70-persistent-net.rules<br>$ sudo udevadm control --reload-rules 或 sudo service udev restart<br><br># 重启网络管理服务<br># sudo service networking restart<br>
# 编辑网卡配置文件
$ sudo vi /etc/network/interfaces<br><br># 查看系统路由项<br>$ sudo netstat -nr<br><br></pre>
</div>
<p>&nbsp;</p>
<div class="cnblogs_code">
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo vi /etc/network/interfaces</span><br># This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
# auto setting
#auto eth0
#iface eth0 inet dhcp
#auto eth1
#iface eth1 inet dhcp

# manual setting
auto eth0
iface eth0 inet static
      address 172.16.204.31
      netmask 255.255.255.0
      broadcast 172.16.204.255
        network 172.16.204.0

#auto eth1
#iface eth1 inet static      
        #address 192.168.1.31
        #netmask 255.255.255.0
        #broadcast 192.168.1.255
        #network 192.168.1.0

up route add default gw 172.16.204.1 dev eth0<br>#up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth1

# This is an autoconfigured IPv6 interface
# auto setting
iface eth0 inet6 auto
#iface eth1 inet6 auto

# manual setting<br><br></pre>
</div>
<p>&nbsp;</p>
<div class="cnblogs_code">
<pre>$ sudo vi /etc/resolvconf/resolv.conf.d/base
nameserver 114.114.114.114
nameserver 8.8.8.8
#nameserver 4.2.2.1
#nameserver 4.2.2.2
search localdomain<br><br></pre>
</div>
<p>&nbsp;</p>
<div class="cnblogs_code">
<pre>$ sudo cat /etc/hostname
localhost.localdomain<br><br></pre>
</div>
<p>&nbsp;</p>
<div class="cnblogs_code">
<pre>$ sudo vi /etc/hosts
127.0.0.1        localhost localhost.localdomain

# The following lines are desirable for IPv6 capable hosts
::1   localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters</pre>
</div>
<p>&nbsp;</p>
<div class="cnblogs_code">
<pre># 网络设备信息<br><br>--------------------------------------------------------------------------------------
nametype      MATCHADDR          Bandwidth      PCIID         driver   device
--------------------------------------------------------------------------------------
eth0Ethernet00:13:32:0e:2a:601000baseT/Full   0000:05:00.0e1000e   8086:10d3
eth1Ethernet00:13:32:0e:2a:611000baseT/Full   0000:06:00.0e1000e   8086:10d3
eth2Ethernet00:13:32:0e:2a:621000baseT/Full   0000:07:00.0e1000e   8086:10d3
eth3Ethernet00:13:32:0e:2a:631000baseT/Full   0000:08:00.0e1000e   8086:10d3
--------------------------------------------------------------------------------------
eth4Ethernet00:10:f3:5a:96:3610000baseT/Full0000:01:00.0ixgbe    8086:10fb
eth5Ethernet00:10:f3:5a:96:3710000baseT/Full0000:01:00.1ixgbe    8086:10fb
--------------------------------------------------------------------------------------

# 将设备MAC地址与ethN接口名称相关联

$ sudo vi cat 70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.


# PCI device 0x8086:10d3 (e1000e) --- 05:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:13:32:0e:2a:60", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:10d3 (e1000e) --- 06:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:13:32:0e:2a:61", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

# PCI device 0x8086:10d3 (e1000e) --- 07:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:13:32:0e:2a:62", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

# PCI device 0x8086:10d3 (e1000e) --- 08:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:13:32:0e:2a:63", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"

# PCI device 0x8086:0x10fb (ixgbe) --- 01:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:10:f3:5a:96:36", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth4"

# PCI device 0x8086:0x10fb (ixgbe) --- 01:00.1
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:10:f3:5a:96:37", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth5"


# 将设备PCI总线地址与ethN接口名称相关联

$ sudo vi cat 70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.


# PCI device 0x8086:10d3 (e1000e) --- 05:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:05:00.0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:10d3 (e1000e) --- 06:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:06:00.0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

# PCI device 0x8086:10d3 (e1000e) --- 07:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:07:00.0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

# PCI device 0x8086:10d3 (e1000e) --- 08:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:08:00.0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"

# PCI device 0x8086:0x10fb (ixgbe) --- 01:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:01:00.0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth4"

# PCI device 0x8086:0x10fb (ixgbe) --- 01:00.1
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:01:00.1", ATTR{type}=="1", KERNEL=="eth*", NAME="eth5"


# 重新加载设备规则配置文件
$ sudo chmod a+x /etc/udev/rules.d/70-persistent-net.rules
$ sudo udevadm control --reload-rules 或 sudo service udev restart<br><br><br></pre>
</div>
<p>&nbsp;</p>
<div class="cnblogs_code">
<pre># 查看网桥连接<br>$ sudo modprobe br_netfilter<br>$ show brctl show<br><br># 开启 IP 转发:
$ sudo vi /etc/sysctl.conf --&gt; net.ipv4.ip_forward=1 (永久开启)

# 禁用网络过滤器
# 向文件/etc/sysctl.conf添加以下代码:
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

# 重新加载kernel参数
$ sudo sysctl -p <br><br><br></pre>
</div>
<p>&nbsp;</p>
<p>================&nbsp;End</p>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/lsgxeva/p/10944806.html
頁: [1]
查看完整版本: ubuntu 网卡名称重命名