우분투 18.04 부터는 네트워크 카드를 설정하려면, netplan
을 사용해야 합니다.
네트워크 인터페이스 추가
네트워크 인터페이스를 추가한 다음, ifconfig
명령어를 실행해 봅니다. 별다른 옵션을 주기 않았기 때문에, 추가된 네트워크 인터페이스가 보이지 않습니다.
ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 944 bytes 67408 (67.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 944 bytes 67408 (67.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
추가한 네트워크 인터페이스 확인
ifconfig -a
명령어를 이용하여, 추가한 네트워크 인터페이스를 확인할 수 있습니다.
ifconfig -a
eth0
이 추가된 것을 확인할 수 있습니다.
eth0: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 00:15:5d:15:0e:00 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 944 bytes 67408 (67.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 944 bytes 67408 (67.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
설정에 네트워크 인터페이스를 추가하기
/etc/netplan/*.yaml
파일에 네트워크 설정을 추가해 줘야 합니다
cat /etc/netplan/*.yaml
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets: {}
version: 2
현재 설정된 네트워크 인터페이스가 없기 때문에, ethernets 필드에 아무런 값이 없습니다.
/etc/netplan/*.yaml
파일에 네트워크 설정을 추가합니다.
sudo vi /etc/netplan/*.yaml
ifconfig -a
명령어를 통해서 확인한 네트워크 인터페이스 이름을 ethernets
필드에 추가하고, 설정값을 지정해줍니다. 아래 예제에서는 dhcp 를 사용하기 때문에, IP 직접 명시하지 않았습니다.
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
addresses: []
dhcp4: true
version: 2
만약 고정 IP를 사용한다면 아래처럼 설정할 수 있습니다.
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
addresses: [192.168.21.100/24]
gateway4: 192.168.56.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]
dhcp4: no
dhcp6: no
version: 2
설정 적용하기
다음 명령어를 실행하여, 변경한 설정을 적용합니다.
sudo netplan apply
설정이 적용되면 ifconfig
명령어를 실행하여, 적용한 내용을 확인할 수 있습니다.
ifconfig
정상적으로 적용되었다면, 추가한 eth0
을 확인할 수 있습니다.
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.21.39 netmask 255.255.255.0 broadcast 192.168.21.255
inet6 fe80::215:5dff:fe15:e00 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:15:0e:00 txqueuelen 1000 (Ethernet)
RX packets 47668 bytes 70216376 (70.2 MB)
RX errors 0 dropped 6 overruns 0 frame 0
TX packets 9362 bytes 772780 (772.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 120 bytes 9592 (9.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 120 bytes 9592 (9.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0