ubuntu 網卡名稱重命名
參考:https://blog.csdn.net/hzj_001/article/details/81587824node
biosdevname 和 net.ifnames 兩種命名規範 --------------------------------------- net.ifnames 的命名規範爲: 設備類型+設備位置+數字 設備類型: en 表示Ethernet wl 表示WLAN ww 表示無線廣域網WWAN 實際的例子: eno1 板載網卡 enp0s2 pci網卡 ens33 pci網卡 wlp3s0 PCI無線網卡 wwp0s29f7u2i2 4G modem wlp0s2f1u4u1 鏈接在USB Hub上的無線網卡 enx78e7d1ea46da pci網卡 --------------------------------------- biosdevname 的命名規範爲: 實際的例子: em1 板載網卡 p3p4 pci網卡 p3p4_1 虛擬網卡 ---------------------------------------
修改 grub 引導參數ios
# 查看 GRUB_CMDLINE_LINUX 變量 $ cat /etc/default/grub | grep GRUB_CMDLINE_LINUX # 修改 GRUB_CMDLINE_LINUX 變量 $ sudo sed -i 's/^.*GRUB_CMDLINE_LINUX="".*$/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"/g' /etc/default/grub # 更新grub引導 $ sudo update-grub # 重啓系統 $ sudo reboot
參考:https://kb.vmware.com/s/article/1032790ubuntu
# 查看全部網卡列表 $ ifconfig -s
$ 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
# 從新加載設備規則配置文件
$ sudo chmod a+x /etc/udev/rules.d/70-persistent-net.rules
$ sudo udevadm control --reload-rules 或 sudo service udev restart
# 重啓網絡管理服務
# sudo service networking restart
# 編輯網卡配置文件 $ sudo vi /etc/network/interfaces
# 查看系統路由項
$ sudo netstat -nr
$ sudo vi /etc/network/interfaces
# 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
#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
$ 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
$ sudo cat /etc/hostname localhost.localdomain
$ 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
# 網絡設備信息
-------------------------------------------------------------------------------------- name type MATCHADDR Bandwidth PCIID driver device -------------------------------------------------------------------------------------- eth0 Ethernet 00:13:32:0e:2a:60 1000baseT/Full 0000:05:00.0 e1000e 8086:10d3 eth1 Ethernet 00:13:32:0e:2a:61 1000baseT/Full 0000:06:00.0 e1000e 8086:10d3 eth2 Ethernet 00:13:32:0e:2a:62 1000baseT/Full 0000:07:00.0 e1000e 8086:10d3 eth3 Ethernet 00:13:32:0e:2a:63 1000baseT/Full 0000:08:00.0 e1000e 8086:10d3 -------------------------------------------------------------------------------------- eth4 Ethernet 00:10:f3:5a:96:36 10000baseT/Full 0000:01:00.0 ixgbe 8086:10fb eth5 Ethernet 00:10:f3:5a:96:37 10000baseT/Full 0000:01:00.1 ixgbe 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
# 查看網橋鏈接
$ sudo modprobe br_netfilter
$ show brctl show
# 開啓 IP 轉發: $ sudo vi /etc/sysctl.conf --> 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
================ End網絡