NetPlan은 우분투 17.10부터 도입된 새로운 네트워크 구성 도구 입니다.
기존 /etc/network/interface 파일을 대체하며 /etc/netplan/*.yaml을 사용하여 우분투
네트워크를 설정합니다.
ubuntu 18.04 에서 진행하였습니다.
root@smileserv:~# cat /etc/issue Ubuntu 18.04.1 LTS \n \l |
네트워크 인터페이스 확인
root@smileserv:~# ifconfig -a enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::a00:27ff:fe13:a97c prefixlen 64 scopeid 0x20<link> ether 08:00:27:13:a9:7c txqueuelen 1000 (Ethernet) RX packets 634 bytes 686396 (686.3 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 302 bytes 32975 (32.9 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: enp0s8: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether 08:00:27:16:da:4a txqueuelen 1000 (Ethernet) RX packets 3081 bytes 274464 (274.4 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2991 bytes 420676 (420.6 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
기본 설정값을 확인하였습니다.
root@smileserv:~# vi /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by # the datasource. Changes to it will not persist across an instance. # 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: enp0s3: addresses: [] dhcp4: true version: 2
|
enp0s8 인터페이스를 netplan을 이용해 설정 해보겠습니다.
root@smileserv:/etc/netplan# cp -arp 50-cloud-init.yaml 01-netcfg.yaml |
root@smileserv:~# vi /etc/netplan/01-netcfg.yaml
# This file is generated from information provided by # the datasource. Changes to it will not persist across an instance. # 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: enp0s8: dhcp4: no addresses: [192.168.56.110/24] gateway4: 192.168.56.1 nameservers: addresses: [8.8.8.8] version: 2
|
- dhcp4 : IPv4 dhcp 설정
- dhcp6 : IPv6 dhcp 설정
- addresses : ,로 구분한 IP 멀티로 가능
- gateway4 : IPv4 gateway 설정
- nameservers : dns 설정 ,로 구분 멀티로 설정 가능 [생략 가능]
다음 명령어로 설정을 적용합니다.
root@smileserv:~# netplan apply
|
설정값을 확인합니다.
root@smileserv:~# ifconfig enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::a00:27ff:fe13:a97c prefixlen 64 scopeid 0x20<link> ether 08:00:27:13:a9:7c txqueuelen 1000 (Ethernet) RX packets 636 bytes 687576 (687.5 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 312 bytes 34213 (34.2 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.110 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:fe16:da4a prefixlen 64 scopeid 0x20<link> ether 08:00:27:16:da:4a txqueuelen 1000 (Ethernet) RX packets 3455 bytes 307797 (307.7 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3364 bytes 489408 (489.4 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
예전방식 ( /etc/network/interface) 으로 설정하고 싶은 경우에는 ifupdown 패키지를 설치하고 설정하면 됩니다.
root@smileserv:~# apt-get install ifupdown
Reading package lists… Done Building dependency tree Reading state information… Done ifupdown is already the newest version (0.8.17ubuntu1.1). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@smileserv:~# reboot
|
기존 우분투 네트워크 설정과 동일하게 설정하시면 됩니다 .
root@smileserv:~# vi /etc/network/interfaces
# ifupdown has been replaced by netplan(5) on this system. See # /etc/netplan for current configuration. # To re-enable ifupdown on this system, you can run: # sudo apt install ifupdown
# The loopback network interface auto lo iface lo inet loopback
# The primary network interface auto enp0s3 iface enp0s3 inet dhcp
# The primary network interface auto enp0s8 iface enp0s8 inet static address 192.168.56.101 netmask 255.255.255.0 gateway 192.168.56.1 dns-nameservers 164.124.101.2
|
네트워크를 재시작 합니다 .
root@smileserv:~# /etc/init.d/networking restart [ ok ] Restarting networking (via systemctl): networking.service. |
설정되었는지 확인합니다.
root@smileserv:~# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::a00:27ff:fe13:a97c prefixlen 64 scopeid 0x20<link> ether 08:00:27:13:a9:7c txqueuelen 1000 (Ethernet) RX packets 14 bytes 3258 (3.2 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 48 bytes 5086 (5.0 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.56.101 netmask 255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:fe16:da4a prefixlen 64 scopeid 0x20<link> ether 08:00:27:16:da:4a txqueuelen 1000 (Ethernet) RX packets 1599 bytes 142447 (142.4 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1945 bytes 243039 (243.0 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|