CentOS 7 까지만 해도 /etc/sysconfig/network-scripts/ 에서 네트워크 설정하고 Network Manager 를 끄고 사용해도 됐지만 이제는 사라진 경로..

nmcli 명령어를 사용해서 간편하게 인터페이스에 IP 를 설정하는 방법에 대해 글을 씁니다. nmcli 명령어는 Cisco 네트워크 장비처럼 명령어 단축이 가능합니다.

 

nmcli connection show

 - 현재 connections 목록 확인

[root@localhost ~]# nmcli con show
NAME                UUID                                  TYPE      DEVICE
ens160              b29cf6bb-54dd-33f0-ad47-ab337991a9b2  ethernet  ens160
Wired connection 1  edcc0845-ef95-3d83-a344-49dcf052f251  ethernet  ens224

 

nmcli connection edit '<NAME>'

 - 지정한 connections 설정이며 NAME 에 적힌 이름을 넣어주시면 됩니다.

[root@localhost ~]# nmcli con edit 'Wired connection 1'

===| nmcli interactive connection editor |===

Editing existing '802-3-ethernet' connection: 'Wired connection 1'

Type 'help' or '?' for available commands.
Type 'print' to show all the connection properties.
Type 'describe [<setting>.<prop>]' for detailed property description.

You may edit the following settings: connection, 802-3-ethernet (ethernet), 802-1x, dcb, sriov, ethtool, match, ipv4, ipv6, hostname, tc, proxy
nmcli> 

 

nmcli> print ipv4

 - ipv4 값들에 대한 정보 출력이며 현재 아무런 설정 값이 없습니다.

nmcli> print ipv4
['ipv4' setting values]
ipv4.method:                            auto
ipv4.dns:                               --
ipv4.dns-search:                        --
ipv4.dns-options:                       --
ipv4.dns-priority:                      0
ipv4.addresses:                         --
ipv4.gateway:                           --
ipv4.routes:                            --
ipv4.route-metric:                      -1
ipv4.route-table:                       0 (unspec)
ipv4.routing-rules:                     --
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-iaid:                         --
ipv4.dhcp-timeout:                      0 (default)
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.dhcp-fqdn:                         --
ipv4.dhcp-hostname-flags:               0x0 (none)
ipv4.never-default:                     no
ipv4.may-fail:                          yes
ipv4.required-timeout:                  -1 (default)
ipv4.dad-timeout:                       -1 (default)
ipv4.dhcp-vendor-class-identifier:      --
ipv4.dhcp-reject-servers:               --

 

nmcli> set ipv4.address <IP>/<PREFIX>

 - IP 주소를 넣을 수 있으며 뒤에 PREFIX 를 붙이지 않으면 /32 로 붙으니 꼭 설정합시다.

 - ipv4.method 를 manual 로 변경하냐고 물어보면 yes 를 입력하시면 됩니다.(auto : dhcp, manual : 고정)

nmcli> set ipv4.address 192.168.1.210/24
Do you also want to set 'ipv4.method' to 'manual'? [yes]: yes

 

nmcli> set ipv4.gateway <GATEWAY>

nmcli> set ipv4.gateway 192.168.1.1

 

만약, 값이 잘못 들어가 있거나 지우고 싶다면 print 로 현재 들어간 설정 값을 보면서  set 말고 remove 를 앞에 넣어서 값을 지울 수 있습니다.

 

nmcli> set ipv4.dns<DNS SERVER>

nmcli> set ipv4.dns 8.8.8.8

 

nmcli> set connection.id <NAME>

 - connection 이름이 너무 길고 원하는 이름으로 변경하고 싶다면 설정

nmcli> set connection.id ext1

 

nmcli> save

 - 설정 저장

nmcli> save
Connection 'ext1' (edcc0845-ef95-3d83-a344-49dcf052f251) successfully updated.

 

nmcli> activate

 - 변경된 설정 값들을 바로 반영할 수 있으며 네트워크 재시작 필요없이 바로 수정됩니다.

nmcli> activate
Monitoring connection activation (press any key to continue)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)

 

이후 다음 명령어를 통해 변경된 정보들을 확인할 수 있습니다.

 - nmcli

 - ip a

 - ifconfig

 

감사합니다.