웹사이트 검색

nmcli 명령을 사용하여 AlmaLinux 8, CentOS 8 또는 Rocky Linux 8에서 네트워킹 구성(예제 20개)


이 페이지에서

  1. 전제 조건
  2. 1. NetworkManager 상태 확인\n
  3. 2. 사용 가능한 모든 장치 확인\n
  4. 3. 활성 연결 확인\n
  5. 4. 이더넷 연결에 대한 정보 표시\n
  6. 5. \자동 연결 지시어 변경
  7. 6. 네트워크 연결 BOOTPROTO 지시문 변경
  8. 7. nmcli로 IPv6 주소 비활성화\n
  9. 8. 기존 연결에 DNS 서버 추가
  10. 9. 기존 연결에서 DNS 서버 제거
  11. 10. 대화식으로 연결 추가/편집\n
  12. 11. 연결 활동 모니터링\n
  13. 12. 고정 IP로 새 연결 만들기
  14. 13. DHCP로 새 연결 만들기
  15. 14. 새 연결 활성화\n
  16. 15. 연결 비활성화\n
  17. 16. 연결 삭제
  18. 17. nmcli로 호스트 이름 변경\n
  19. 18. DEFROUTE 지시문 변경
  20. 19. 이더넷 연결 다시 시작
  21. 20. nmcli 도움말
  22. 결론

nmcli는 NetworkManager를 제어하는 데 사용할 수 있는 명령줄 도구입니다. 이 도구는 네트워크 장치 상태를 표시하고 네트워크 연결을 생성, 편집, 활성화/비활성화, 삭제하고 Linux 시스템의 네트워킹 문제를 해결하는 데 도움이 됩니다. 서버 및 헤드리스 시스템이 시스템 전체 연결을 제어하는 데 매우 유용합니다.

이 자습서에서는 nmcli 명령을 사용하여 예제와 함께 네트워크 연결을 제어하는 방법을 보여줍니다.

전제 조건

  • AlmaLinux 8, CentOS 8 또는 Rocky Linux 8을 실행하는 서버.\n
  • 서버에 루트 암호가 설정되어 있습니다.\n

1. NetworkManager 상태 확인

Network Manager가 실행 중인지 여부를 확인하려면 다음 명령을 사용하십시오.

nmcli -t -f RUNNING general

다음 출력이 표시되어야 합니다.

running

일반 상태를 가져오려면 다음 명령을 실행합니다.

nmcli general

다음 출력이 표시되어야 합니다.

STATE      CONNECTIVITY  WIFI-HW  WIFI     WWAN-HW  WWAN    
connected  full          enabled  enabled  enabled  enabled 

2. 사용 가능한 모든 장치 확인

시스템에서 사용 가능한 모든 장치를 표시하려면 다음 명령을 실행하십시오.

nmcli dev status

다음 출력이 표시되어야 합니다.

DEVICE  TYPE      STATE      CONNECTION  
eth0    ethernet  connected  System eth0 
eth1    ethernet  connected  System eth1 
lo      loopback  unmanaged  --      

3. 활성 연결 확인

시스템의 모든 활성 연결을 나열하려면 다음 명령을 실행하십시오.

nmcli con show

다음 출력이 표시되어야 합니다.

NAME         UUID                                  TYPE      DEVICE 
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0   
System eth1  9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1

4. 이더넷 연결에 대한 정보 표시

다음 명령을 사용하여 이더넷 연결에 대한 간략한 정보를 표시할 수 있습니다.

nmcli con show "System eth0"

다음 출력이 표시되어야 합니다.

connection.id:                          System eth0
connection.uuid:                        5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
connection.stable-id:                   --
connection.type:                        802-3-ethernet
connection.interface-name:              eth0
connection.autoconnect:                 yes
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.multi-connect:               0 (default)
connection.auth-retries:                -1
connection.timestamp:                   1588217245
connection.read-only:                   no
connection.permissions:                 --
connection.zone:                        --
connection.master:                      --
connection.slave-type:                  --
connection.autoconnect-slaves:          -1 (default)
connection.secondaries:                 --
connection.gateway-ping-timeout:        0
connection.metered:                     unknown
cat /etc/sysconfig/network-scripts/ifcfg-eth1 | grep BOOTPROTO
BOOTPROTO=dhcp

5. 자동 연결 지시문 변경

기본적으로 모든 이더넷 연결은 자동으로 연결됩니다. 다음 명령으로 비활성화할 수 있습니다.

nmcli con mod "System eth1" connection.autoconnect no

다음 명령을 사용하여 변경 사항을 확인할 수 있습니다.

cat /etc/sysconfig/network-scripts/ifcfg-eth1 | grep ONBOOT

다음 출력이 표시되어야 합니다.

ONBOOT=no

6. 네트워크 연결 BOOTPROTO 지시어 변경

다음 명령을 사용하여 이더넷 연결 BOOTPROTO 지시문을 정적에서 DHCP로 변경할 수 있습니다.

nmcli con mod "System eth1" ipv4.method auto

이제 다음 명령을 사용하여 변경 사항을 확인할 수 있습니다.

cat /etc/sysconfig/network-scripts/ifcfg-eth1 | grep BOOTPROTO

다음 출력이 표시되어야 합니다.

BOOTPROTO=dhcp

다음 명령을 사용하여 이더넷 연결 BOOTPROTO 지시어 정적을 DHCP로 변경하려면 다음을 수행하십시오.

nmcli con mod "System eth1" ipv4.method manual ipv4.address 192.168.0.10/24 ipv4.gateway 192.168.0.1

7. nmcli로 IPv6 주소 비활성화

기본적으로 CentOS 8에서는 IPv6 및 IPv4 연결이 모두 활성화되어 있습니다. 다음 명령을 사용하여 IPv6 연결을 비활성화할 수 있습니다.

nmcli con mod "System eth1" ipv6.method ignore

8. 기존 연결에 DNS 서버 추가

다음 명령을 사용하여 기존 연결에 새 DNS 서버를 추가하려면:

nmcli con mod "System eth1" ipv4.dns 8.8.4.4

다음 명령을 사용하여 변경 사항을 확인할 수 있습니다.

cat /etc/sysconfig/network-scripts/ifcfg-eth1 | grep DNS

산출:

DNS1=8.8.4.4

+ipv4.dns 옵션을 사용하여 새 DNS 서버를 추가할 수도 있습니다.

nmcli con mod "System eth1" +ipv4.dns 4.4.4.4

9. 기존 연결에서 DNS 서버 제거

연결에서 단일 DNS 서버를 제거하려면 다음 명령을 실행합니다.

nmcli con mod "System eth1" -ipv4.dns 8.8.4.4

연결에서 여러 DNS 서버를 제거하려면 다음 명령을 실행합니다.

nmcli con mod "System eth1" -ipv4.dns 8.8.4.4,8.8.2.2

10. 대화식으로 연결 추가/편집

대화형 편집기를 사용하여 새 연결을 만들거나 기존 연결을 편집할 수도 있습니다.

예를 들어 기존 연결을 편집하고 다음 명령을 실행합니다.

nmcli con edit "System eth1"

다음 출력이 표시되어야 합니다.

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

Editing existing '802-3-ethernet' connection: 'System eth1'

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

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

이제 기존 IP 주소를 표시하고 다음 명령을 실행합니다.

nmcli> print ipv4.address

산출:

ipv4.addresses: 192.168.0.10/32

새 IP 주소를 설정하려면 다음 명령을 실행합니다.

nmcli> set ipv4.address 192.168.0.11

다음 명령을 사용하여 연결을 확인하고 저장할 수 있습니다.

nmcli> verify

산출:

Verify connection: OK
nmcli> save

산출:

Connection 'System eth1' (9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04) successfully updated.

이제 다음 명령을 사용하여 저장된 연결을 확인할 수 있습니다.

cat /etc/sysconfig/network-scripts/ifcfg-eth1 | grep IPADDR

다음 출력이 표시되어야 합니다.

IPADDR=192.168.0.10
IPADDR1=192.168.0.11

11. 연결 활동 모니터링

연결 상태, 프로필, 장치 등의 변경 사항과 같이 nmcli를 사용하여 NetworkManager 활동을 모니터링할 수도 있습니다.

이더넷 연결을 수정한 후 다음 명령을 실행하여 모니터링합니다.

nmcli con monitor "System eth1"

12. 고정 IP로 새 연결 만들기

nmcli를 사용하여 새로운 정적 이더넷 연결을 생성할 수도 있습니다. 예를 들어 다음 명령을 실행하여 eth2, IP 192.168.0.12/24, Gateway 192.168.0.1, "onboot=yes"라는 새 이더넷 연결을 만듭니다.

nmcli con add con-name eth2 type ethernet ifname eth2 ipv4.method manual ipv4.address 192.168.0.15/24 ipv4.gateway 192.168.0.1

다음 출력이 표시되어야 합니다.

Connection 'eth2' (cefb3f7d-424c-42f8-b4e8-ed54e7dcb880) successfully added.

이제 다음 명령으로 연결을 확인합니다.

nmcli con

산출:

NAME         UUID                                  TYPE      DEVICE 
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0   
System eth1  9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
eth2         cefb3f7d-424c-42f8-b4e8-ed54e7dcb880  ethernet  eth2 

13. DHCP로 새 연결 만들기

nmcli를 사용하여 새 DHCP 연결을 만들 수도 있습니다. 예를 들어 다음 명령을 사용하여 eth3이라는 이름의 새 DHCP 이더넷 연결을 만듭니다.

nmcli con add con-name eth3 type ethernet ifname eth3 ipv4.method auto

다음 출력이 표시되어야 합니다.

Connection 'eth3' (ff54dbd6-255d-4935-abc8-73773bef5b55) successfully added.

14. 새 연결 활성화

새 이더넷 연결 eth2를 활성화하려면 다음 명령을 실행하십시오.

nmcli con up eth2

다음 출력이 표시되어야 합니다.

Connection successfully activated

이제 다음 명령을 사용하여 활성 연결을 확인할 수 있습니다.

nmcli con show --active

다음 출력이 표시되어야 합니다.

산출:

NAME         UUID                                  TYPE      DEVICE 
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0   
System eth1  9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
eth2         cefb3f7d-424c-42f8-b4e8-ed54e7dcb880  ethernet  eth2 

15. 연결 비활성화

연결 eth2를 비활성화하려면 다음 명령을 실행합니다.

nmcli con down eth2

16. 연결 삭제

nmcli를 사용하여 특정 이더넷 연결을 삭제할 수도 있습니다.

예를 들어 eth2 연결을 삭제하려면 다음 명령을 실행합니다.

nmcli con del eth2

다음 출력이 표시되어야 합니다.

Connection 'eth2' (cefb3f7d-424c-42f8-b4e8-ed54e7dcb880) successfully deleted.

17. nmcli로 호스트 이름 변경

시스템의 현재 호스트 이름을 찾으려면 다음 명령을 실행하십시오.

nmcli general hostname

다음 출력이 표시되어야 합니다.

centos8

그런 다음 다음 명령을 사용하여 호스트 이름을 centos8에서 Linux로 변경합니다.

nmcli general hostname linux

그런 다음 다음 명령을 사용하여 호스트 이름을 확인합니다.

nmcli general hostname

다음 출력이 표시되어야 합니다.

linux

18. DEFROUTE 지시문 변경

DEFROUTE 지시문은 이더넷 연결의 기본 게이트웨이를 비활성화 및 활성화하는 데 사용됩니다.

eth2에 대한 DEFROUTE 지시문을 활성화하려면 다음 명령을 실행하십시오.

nmcli con mod "System eth2" ipv4.never-default yes

19. 이더넷 연결 다시 시작

다음 명령을 사용하여 이더넷 연결을 다시 시작하거나 다시 로드할 수 있습니다.

nmcli con reload

20. nmcli 도움말

nmcli 명령에 대한 자세한 정보를 얻으려면 다음 명령을 실행하십시오.

nmcli --help

다음 출력이 표시되어야 합니다.

Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }

OPTIONS
  -a, --ask                                ask for missing parameters
  -c, --colors auto|yes|no                 whether to use colors in output
  -e, --escape yes|no                      escape columns separators in values
  -f, --fields <field,...>|all|common      specify fields to output
  -g, --get-values <field,...>|all|common  shortcut for -m tabular -t -f
  -h, --help                               print this help
  -m, --mode tabular|multiline             output mode
  -o, --overview                           overview mode
  -p, --pretty                             pretty output
  -s, --show-secrets                       allow displaying passwords
  -t, --terse                              terse output
  -v, --version                            show program version
  -w, --wait                      set timeout waiting for finishing operations

OBJECT
  g[eneral]       NetworkManager's general status and operations
  n[etworking]    overall networking control
  r[adio]         NetworkManager radio switches
  c[onnection]    NetworkManager's connections
  d[evice]        devices managed by NetworkManager
  a[gent]         NetworkManager secret agent or polkit agent
  m[onitor]       monitor NetworkManager changes

결론

위 가이드에서는 nmcli를 사용하여 AlmaLinux, centOS 또는 Rocky Linux와 같은 RHEL 8 클론에서 이더넷 연결을 관리하고 제어하는 방법을 배웠습니다. 이제 nmcli를 사용하여 새 연결을 쉽게 추가, 편집 또는 생성할 수 있기를 바랍니다. 궁금한 점이 있으면 언제든지 문의해 주세요.