Rename network interface on Ubuntu
- Ubuntu OS에서 network 장치의 이름을 rename하며 정리한 노트
- 꼭 수정할 필요없으며 기본값 사용 권장 (Update: Aug 26, 2021)
환경 구성
- OS: Ubuntu 16, 18
- VM: VMware vsphere 6.7 UP3
1. OS 설치 후 자동으로 인식된 네트웍 장치
USER1@UBUNTU16:~$ ifconfig -a
ens160 Link encap:Ethernet HWaddr 12:3c:29:33:ec:df
inet addr:192.168.0.33 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::123:29ff:fe33:ecdf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:57 errors:0 dropped:0 overruns:0 frame:0
TX packets:71 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6868 (6.8 KB) TX bytes:10964 (10.9 KB)
USER1@UBUNTU16:~$ dmesg |grep -i net
(...생략...)
[ 1.134069] FUJITSU Extended Socket Network Device Driver - version 1.0 - Copyright (c) 2015 FUJITSU LIMITED
[ 1.153441] VMware vmxnet3 virtual NIC driver - version 1.4.14.0-k-NAPI
[ 1.153572] vmxnet3 0000:03:00.0: # of Tx queues : 4, # of Rx queues : 4
[ 1.154562] vmxnet3 0000:03:00.0 eth0: NIC Link is Up 10000 Mbps
[ 1.179238] vmxnet3 0000:03:00.0 ens160: renamed from eth0
[ 2.604768] SELinux: Unregistering netfilter hooks
[ 2.808421] systemd[1]: Reached target Network (Pre).
[ 3.251979] vmxnet3 0000:03:00.0 ens160: intr type 3, mode 0, 5 vectors allocated
[ 3.252730] vmxnet3 0000:03:00.0 ens160: NIC Link is Up 10000 Mbps
(...생략...)
2. network interface 이름 수정
2-1. grub 및 network 설정 파일 수정으로 이름 변경
USER1@UBUNTU16:~$ sudo vi /etc/default/grub
(...생략...)
GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=2
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="security=selinux selinux=1"
#GRUB_CMDLINE_LINUX=""
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
(...생략...)
USER1@UBUNTU16:~$ sudo grub-mkconfig -o /boot/grub/grub.cfg
USER1@UBUNTU16:~$ sudo vi /etc/network/interfaces
USER1@UBUNTU16:~$ sudo reboot
2-2. udev 네트웍 장치 rules 수정 방법
; Ubuntu 16, 18 설정 파일 내용이 약간 다르지만 수정 부분은 같음
USER1@UBUNTU16:~$ sudo vi /lib/udev/rules.d/73-usb-net-by-mac.rules
(...생략...)
IMPORT{cmdline}="net.ifnames"
ENV{net.ifnames}=="0", GOTO="usb_net_by_mac_end"
ACTION=="add", SUBSYSTEM=="net", SUBSYSTEMS=="usb", NAME=="", \
ATTR{address}=="?[014589cd]:*", \
TEST!="/etc/udev/rules.d/80-net-setup-link.rules", \
#IMPORT{builtin}="net_id", NAME="$env{ID_NET_NAME_MAC}"
IMPORT{builtin}="net_id", NAME="eth0"
# NAME= 부분을 수정한다
LABEL="usb_net_by_mac_end"
;network 설정 파일도 같은 이름으로 수정
USER1@UBUNTU16:~$ sudo vi /etc/network/interfaces
(...생략...)
# The primary network interface
#auto ens160
#iface ens160 inet static
auto eth0
iface eth0 inet static
address 192.168.0.33
netmask 255.255.255.0
gateway 192.168.0.1
USER1@UBUNTU18:~$ sudo vi /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
#ens160:
eth0:
dhcp4: no
addresses:
- 192.168.0.32/24
gateway4: 192.168.0.1
nameservers: {}
version: 2
;리부팅 후 결과
USER1@UBUNTU16:~$ ifconfig -a
eth0 Link encap:Ethernet HWaddr 12:3c:29:33:ec:df
inet addr:192.168.0.33 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::123:29ff:fe33:ecdf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:173 errors:0 dropped:0 overruns:0 frame:0
TX packets:200 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:40750 (40.7 KB) TX bytes:26522 (26.5 KB)
root@UBUNTU16:~$ dmesg |grep -i net
(...생략...)
[ 1.120281] FUJITSU Extended Socket Network Device Driver - version 1.0 - Copyright (c) 2015 FUJITSU LIMITED
[ 1.165768] VMware vmxnet3 virtual NIC driver - version 1.4.14.0-k-NAPI
[ 1.165899] vmxnet3 0000:03:00.0: # of Tx queues : 4, # of Rx queues : 4
[ 1.166926] vmxnet3 0000:03:00.0 eth0: NIC Link is Up 10000 Mbps
[ 1.179391] vmxnet3 0000:03:00.0 ens160: renamed from eth0
[ 2.608323] SELinux: Unregistering netfilter hooks
[ 2.841503] systemd[1]: Reached target Network (Pre).
[ 3.021175] vmxnet3 0000:03:00.0 eth0: renamed from ens160
[ 3.146681] vmxnet3 0000:03:00.0 eth0: intr type 3, mode 0, 5 vectors allocated
[ 3.147669] vmxnet3 0000:03:00.0 eth0: NIC Link is Up 10000 Mbps
(...생략...)
; network 설정 추가 확인
USER1@UBUNTU18:~$ lshw -C network
WARNING: you should run this program as super-user.
*-network
description: Ethernet interface
product: VMXNET3 Ethernet Controller
vendor: VMware
physical id: 0
bus info: pci@0000:03:00.0
logical name: eth0
version: 01
serial: 12:3c:29:05:f3:ba
size: 10Gbit/s
capacity: 10Gbit/s
width: 32 bits
clock: 33MHz
(...생략...)
USER1@UBUNTU18:~$ find /sys/devices/ -name device |grep net
/sys/devices/pci0000:00/0000:00:15.0/0000:03:00.0/net/eth0/device
3. 참고용
; OS 버전별 기본 설치 후 인식된 네트웍 장치 이름
VERSION="20.04.2 LTS (Focal Fossa)"
logical name: ens160
VERSION="18.04.5 LTS (Bionic Beaver)"
logical name: ens160
VERSION="16.04.7 LTS (Xenial Xerus)"
logical name: ens160
VERSION="14.04.2 LTS, Trusty Tahr"
logical name: eth0
VERSION="12.04.5 LTS, Precise Pangolin"
logical name: eth0
CentOS Stream release 8
logical name: ens192
CentOS Linux release 7.9.2009 (Core)
logical name: ens192
CentOS release 6.10 (Final)
logical name: eth0
CentOS release 6.2 (Final)
logical name: eth0