[Linux] Wifi USB 모듈 사용하기

5 minute read

데비안 계열 리눅스 운영체제에서 rtl8821cu wifi 모듈을 사용하는 방법입니다.

WIFI 모듈 사용하기

이 포스팅은 우분투, 라즈비안, 데비안 등 Debian 계열 리눅스 운영체제에서 적용할 수 있습니다.

준비하기

WIFI usb 모듈을 준비합니다.

wifiusb
[picture 1] USB wifi modules


준비할 것들 입니다.

- Debian type Linux OS
- Realtek wifi module(rtl8821) x1


wifi 사용을 위한 패키지를 다운로드 받습니다.
보통은 기본적으로 설치되어 있기는 합니다.

$ sudo apt install network-manager


장치 확인하기

모듈을 usb포트 연결하고 장치를 확인합니다.

$ lsusb
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 004: ID 0bda:c820 Realtek Semiconductor Corp. 802.11ac NIC
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


wifi 모듈의 정체를 확인해야 합니다.
장치의 VID:PID0bda:c820 입니다.
구글 검색을 통해서 제가 사용하는 장치는 rtl8821cu 이네요.

wifi 모듈의 종류는 다양합니다.
rtl8188eu 라던지,
rtl8191su 라던지 여러 종류가 있습니다.
본인이 사용하는 장치에 맞게 따라가면 됩니다.

본인이 사용하는 커널에서 관련 드라이버가 설치되어 있어야 합니다.
커널에 wifi 모듈 드라이버가 없으면 {module}-dkms 패키지를 설치합니다.

$ sudo apt install rtl8821cu-dkms

usb 모드 스위칭

가끔씩 모듈이 저장장치로 먼저 붙는 경우도 있습니다.

$ lsusb
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 003: ID 0bda:1a2b Realtek Semiconductor Corp. DISK
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


이런 경우에는 모드가 따로 존재하는 경우입니다.
모드를 전환하고 다시 확인합니다.

$ sudo usb_modeswitch -K -W -v 0bda -p 1a2b
$ lsusb
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 010: ID 0bda:c820 Realtek Semiconductor Corp. 802.11ac NIC
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

WIFI 연결하기

장치를 확인했으면 wifi 노드가 생겼는지 확인합니다.

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::89:c5ff:fe8c:d01d  prefixlen 64  scopeid 0x20<link>
        ether 02:89:c5:8c:d0:1d  txqueuelen 1000  (Ethernet)
        RX packets 5038  bytes 1482562 (1.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3157  bytes 539947 (539.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 50  

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 159  bytes 12289 (12.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 159  bytes 12289 (12.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlx200bd0464483: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 20:0b:d0:46:44:83  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


USB 모듈을 연결하고 ifconfig 명령을 실행하면, wifi 노드가 새로 생성되는 것을 확인할 수 있습니다.
제 경우에는 wlx200bd0464483 이네요.
정확히 wifi 노드인지 확인하려면 다음 명령을 실행합니다.

$ sudo nmcli device show wlx200bd0464483
GENERAL.DEVICE:                         wlx200bd0464483
GENERAL.TYPE:                           wifi
GENERAL.HWADDR:                         20:0B:D0:46:44:83
GENERAL.MTU:                            1500
GENERAL.STATE:                          30 (disconnected)
GENERAL.CONNECTION:                     --
GENERAL.CON-PATH:                       --


wifi 연결하는 방법은 Desktop 이미지와 headless server 이미지 모두 사용할 수 있는 방법으로 진행하겠습니다.

먼저 wifi 사용 가능여부를 확인합니다.

$ sudo nmcli radio wifi
Enabled


만약, 사용불가능하다면 다음 명령을 실행합니다.

$ sudo nmcli radio wifi on


wifi를 허용했으면 AP 장치를 탐색합니다.

$ sudo nmcli device wifi list
IN-USE  BSSID              SSID                           MODE   CHAN  RATE        SIGNAL  BARS  SECURITY  
        ??:??:??:??:??:??  HK_STEVE                       Infra  2     270 Mbit/s  100     ____  WPA2      
        ??:??:??:??:??:??  Hardkernel Lab 5G              Infra  36    270 Mbit/s  100     ____  WPA2      
        ??:??:??:??:??:??  SmartPower2                    Infra  1     54 Mbit/s   82      ____  WPA2      
        ??:??:??:??:??:??  Hardkernel Lab 2.4G            Infra  7     270 Mbit/s  75      ____  WPA2      
        ??:??:??:??:??:??  iptime4                        Infra  3     270 Mbit/s  40      ____  WPA2      
        ??:??:??:??:??:??  --                             Infra  9     270 Mbit/s  40      ____  WPA1      
        ??:??:??:??:??:??  KT_GiGA_2G_Wave2_76E7          Infra  7     130 Mbit/s  37      ____  WPA1 WPA2 
        ??:??:??:??:??:??  U+Net38A8                      Infra  11    130 Mbit/s  37      ____  WPA2      
        ??:??:??:??:??:??  U+Net38A8_5G                   Infra  48    270 Mbit/s  29      ____  WPA2      
        ??:??:??:??:??:??  KT_GiGA_5G_EDE2                Infra  157   270 Mbit/s  25      ____  WPA1 WPA2 
        ??:??:??:??:??:??  --                             Infra  161   270 Mbit/s  25      ____  WPA1 WPA2 
        ??:??:??:??:??:??  FactoryLine4                   Infra  1     270 Mbit/s  24      ____  WPA2      
        ??:??:??:??:??:??  iptime                         Infra  9     270 Mbit/s  24      ____  --        
        ??:??:??:??:??:??  SK_WiFiGIGA5802_5G             Infra  44    270 Mbit/s  17      ____  WPA2      
        ??:??:??:??:??:??  --                             Infra  44    270 Mbit/s  17      ____  WPA2      
        ??:??:??:??:??:??  [air purifier]_E30AJT1013771F  Infra  1     65 Mbit/s   14      ____  WPA2      
        ...


탐색 결과대로 원하는 wifi에 연결합니다.
저는 HK_STEVE 장치에 연결해 보겠습니다.

$ sudo nmcli device wifi connect "HK_STEVE" password "AP's password"
Device 'wlxe0e1a933d48b' successfully activated with '????????-????-????-????-????????????'.


연결이 제대로 되었는지 확인합니다.

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::acbf:8fff:fe56:39ad  prefixlen 64  scopeid 0x20<link>
        ether ae:bf:8f:56:39:ad  txqueuelen 1000  (Ethernet)
        RX packets 2416  bytes 883916 (883.9 KB)
        RX errors 0  dropped 2  overruns 0  frame 0
        TX packets 1450  bytes 170314 (170.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 50

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 178  bytes 14988 (14.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 178  bytes 14988 (14.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlxe0e1a933d48b: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.218  netmask 255.255.255.0  broadcast 192.168.11.255
        inet6 fe80::1795:5d38:f9f1:ab1b  prefixlen 64  scopeid 0x20<link>
        ether e0:e1:a9:33:d4:8b  txqueuelen 1000  (Ethernet)
        RX packets 12  bytes 12774 (12.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 35  bytes 14771 (14.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ip 주소가 할당된 것을 확인할 수 있습니다.

wifi 연결을 끊으려면 다음 명령을 실행합니다.

$ sudo nmcli connection down HK_STEVE
Connection 'HK_STEVE' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)

Leave a comment