[ubuntu server 22.04. 3 LTS (Jammy Jellyfish)] 노트북에 hotspot 설치하기 (access point, 무선 AP)

yes 2023.10.03 15:44:23

[ubuntu server 22.04. 3 LTS (Jammy Jellyfish)] 노트북에 hotspot 설치하기 (access point, 무선 AP)

 

설치이유

- 현재 공유기가 802.11AC 를 지원하지 않습니다. 그래서, 무선 속도가 40Mb 정도 였습니다. (802.11g)

- 새로운 공유기를 살지, 우분투 서버로 사용하는 노트북의 wifi 를 살려서 AP 로 사용해 볼지를 고민했습니다.

 

결론

- 3일간 사투를 버렸습니다.

- 노트북 랜카드 사양은 802.11n(draft) 이었습니다.

  여기서, 실제 802.11n 의 속도를 검색했어야 했습니다. (이론상 속도는 100M 이상 이었지만, 실제 속도는 40M 정도라고 합니다.)

  (현재 공유기 무선 속도가 40M 이니, 서버 노트북을 AP 로 만들 필요가 없었습니다. ㅠㅠ)

- 그래도, 어렵게 리눅스 무선랜 공부를 했으니, 기록에 남깁니다.

  (무선 AP 만들기는 성공했습니다.)

 

 

 

무선 AP 만들기

 

환경

- 서버 노트북은 ubuntu 22.04.3LTS server 입니다.

- 100M 인터넷을 사용중입니다. (공유기 무선 속도는 40M 입니다.)

- 서버 노트북 랜카드는 802.11n 를 지원 합니다.

 

2가지 방법

- 브릿지 방법이 있습니다. (본인 실행)

- DHCP 방법이 있습니다. (해보지 않음)

 

 

 

hostapd 설치

apt-get install hostapd

 

sudo su

nano /etc/hostapd/hostapd.conf

 

interface=wlp4s0           무선랜 이름
# The nl80211 driver is suitable for most Wi-Fi adapters
driver=nl80211
# Your access point name
ssid=hansung

# The number of your Wi-Fi channel (1 to 13)
hw_mode=g
ieee80211n=1                           #802.11n 사용
ht_capab=[SHORT-GI-40][HT40+][HT40-][DSSS_CCK-40]
channel=5        # the channel to use, 0 means the AP will search for the channel with >
ieee80211d=1
country_code=FR       # the country code
wme_enabled=1
auth_algs=1
# Allow connections from all MAC addresses except those in the blacklist
macaddr_acl=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
#Set a password for your access point
wpa_passphrase=1111

 

 

세팅 완료 후, 실행 명령들,

/etc/init.d/hostapd start
/etc/init.d/hostapd stop
/etc/init.d/hostapd restart

 

 

브릿지 앱 설치

apt-get install bridge-utils

 

brctl addbr br0        #br0 라는 브릿지를 만듬

ip link set dev br0 up          #브릿지 가동

 

브릿지 만들기 전

hs7@hcp:~$ brctl show
bridge name     bridge id               STP enabled     interfaces
br-395f4074e725         8000.0242f37019c1       no              veth24aa0af
                                                        veth2b8f0c6
                                                        veth2f0e36e
                                                        veth7bb1a88
                                                        veth8575884
                                                        veth8b54956
                                                        vetha032e99
                                                        vetha15f68e
docker0         8000.0242b6c2780a       no              veth478afb6
                                                        veth51dc02e
                                                        veth6369238
                                                        veth91b12b1
                                                        vethfdd9da3
                                                        vethff392e9

 

 

 

브릿지 만든 후,

 

hs7@hcp:~$ brctl show
bridge name     bridge id               STP enabled     interfaces
br-395f4074e725         8000.0242f37019c1       no              veth24aa0af
                                                        veth2b8f0c6
                                                        veth2f0e36e
                                                        veth7bb1a88
                                                        veth8575884
                                                        veth8b54956
                                                        vetha032e99
                                                        vetha15f68e
br0             8000.d63274fa1f00       no
docker0         8000.0242b6c2780a       no              veth478afb6
                                                        veth51dc02e
                                                        veth6369238
                                                        veth91b12b1
                                                        vethfdd9da3
                                                        vethff392e9

 

 

**** docker 사용으로 만들어지 브릿지 같습니다. br-395f4074e725

 

 

유선인터넷을 브릿지와 연결해 줍니다.

brctl addif br0 enp5s0f2

연결 후,

hs7@hcp:~$ brctl show
bridge name     bridge id               STP enabled     interfaces
br-395f4074e725         8000.0242f37019c1       no              veth24aa0af
                                                        veth2b8f0c6
                                                        veth2f0e36e
                                                        veth7bb1a88
                                                        veth8575884
                                                        veth8b54956
                                                        vetha032e99
                                                        vetha15f68e
br0             8000.d63274fa1f00       no              enp5s0f2
docker0         8000.0242b6c2780a       no              veth478afb6
                                                        veth51dc02e
                                                        veth6369238
                                                        veth91b12b1
                                                        vethfdd9da3
                                                        vethff392e9

 

 

 

전체 네트워크 사정을 보겠습니다.

브릿지 br0 이 보이고,

hs7@hcp:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp5s0f2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
    link/ether 00:90:f5:d1:6d:46 brd ff:ff:ff:ff:ff:ff
    inet 192.168.219.150/24 brd 192.168.219.255 scope global enp5s0f2
       valid_lft forever preferred_lft forever
    inet6 fe80::290:f5ff:fed1:6d46/64 scope link
       valid_lft forever preferred_lft forever

3: wlp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 44:6d:57:7a:11:8e brd ff:ff:ff:ff:ff:ff
    inet6 fe80::466d:57ff:fe7a:118e/64 scope link
       valid_lft forever preferred_lft forever

4: br-395f4074e725: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:f3:70:19:c1 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 brd 172.18.255.255 scope global br-395f4074e725
       valid_lft forever preferred_lft forever
    inet6 fe80::42:f3ff:fe70:19c1/64 scope link
       valid_lft forever preferred_lft forever
5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:b6:c2:78:0a brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:b6ff:fec2:780a/64 scope link
       valid_lft forever preferred_lft forever
7: veth6369238@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether 92:45:2d:da:c9:a8 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::9045:2dff:feda:c9a8/64 scope link
       valid_lft forever preferred_lft forever
9: veth8575884@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-395f4074e725 state UP group default
    link/ether a6:b8:c0:64:d7:8f brd ff:ff:ff:ff:ff:ff link-netnsid 3
    inet6 fe80::a4b8:c0ff:fe64:d78f/64 scope link
       valid_lft forever preferred_lft forever
11: veth7bb1a88@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-395f4074e725 state UP group default
    link/ether e2:58:b9:aa:af:bd brd ff:ff:ff:ff:ff:ff link-netnsid 6
    inet6 fe80::e058:b9ff:feaa:afbd/64 scope link
       valid_lft forever preferred_lft forever
13: veth51dc02e@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether c2:e7:9e:80:78:84 brd ff:ff:ff:ff:ff:ff link-netnsid 1
    inet6 fe80::c0e7:9eff:fe80:7884/64 scope link
       valid_lft forever preferred_lft forever
15: vetha032e99@if14: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-395f4074e725 state UP group default
    link/ether ea:2c:42:da:13:64 brd ff:ff:ff:ff:ff:ff link-netnsid 2
    inet6 fe80::e82c:42ff:feda:1364/64 scope link
       valid_lft forever preferred_lft forever
17: vethfdd9da3@if16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether ba:8d:18:9a:58:c1 brd ff:ff:ff:ff:ff:ff link-netnsid 5
    inet6 fe80::b88d:18ff:fe9a:58c1/64 scope link
       valid_lft forever preferred_lft forever
19: vetha15f68e@if18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-395f4074e725 state UP group default
    link/ether 3a:e4:e5:98:25:f6 brd ff:ff:ff:ff:ff:ff link-netnsid 7
    inet6 fe80::38e4:e5ff:fe98:25f6/64 scope link
       valid_lft forever preferred_lft forever
21: vethff392e9@if20: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether 06:05:03:be:10:03 brd ff:ff:ff:ff:ff:ff link-netnsid 4
    inet6 fe80::405:3ff:febe:1003/64 scope link
       valid_lft forever preferred_lft forever
23: veth8b54956@if22: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-395f4074e725 state UP group default
    link/ether 9a:46:4a:b2:41:33 brd ff:ff:ff:ff:ff:ff link-netnsid 11
    inet6 fe80::9846:4aff:feb2:4133/64 scope link
       valid_lft forever preferred_lft forever
25: veth478afb6@if24: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether 6a:2d:2a:97:2e:ca brd ff:ff:ff:ff:ff:ff link-netnsid 9
    inet6 fe80::682d:2aff:fe97:2eca/64 scope link
       valid_lft forever preferred_lft forever
27: veth91b12b1@if26: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
    link/ether f6:f4:21:eb:d6:b1 brd ff:ff:ff:ff:ff:ff link-netnsid 10
    inet6 fe80::f4f4:21ff:feeb:d6b1/64 scope link
       valid_lft forever preferred_lft forever
29: veth24aa0af@if28: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-395f4074e725 state UP group default
    link/ether d2:ea:b9:5e:ff:20 brd ff:ff:ff:ff:ff:ff link-netnsid 8
    inet6 fe80::d0ea:b9ff:fe5e:ff20/64 scope link
       valid_lft forever preferred_lft forever
31: veth2f0e36e@if30: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-395f4074e725 state UP group default
    link/ether f6:91:74:0f:48:25 brd ff:ff:ff:ff:ff:ff link-netnsid 12
    inet6 fe80::f491:74ff:fe0f:4825/64 scope link
       valid_lft forever preferred_lft forever
33: veth2b8f0c6@if32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-395f4074e725 state UP group default
    link/ether c2:b8:78:9b:ac:b1 brd ff:ff:ff:ff:ff:ff link-netnsid 13
    inet6 fe80::c0b8:78ff:fe9b:acb1/64 scope link
       valid_lft forever preferred_lft forever
34: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether d6:32:74:fa:1f:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.219.150/24 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::d432:74ff:fefa:1f00/64 scope link
       valid_lft forever preferred_lft forever

 

**** 순서가 햇갈리는데, 위에 보면 br0 에 아이피 주소가(192.168.219.150/24) 가 있습니다. 만일 없다면,

ip address add 192.168.219.150/24 dev br0

 

 

 

*** 아래는 유선인터넷의 정보를 보는 방법입니다.

hs7@hcp:~$ ip address show enp5s0f2
2: enp5s0f2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:90:f5:d1:6d:46 brd ff:ff:ff:ff:ff:ff
    inet 192.168.219.150/24 brd 192.168.219.255 scope global enp5s0f2
       valid_lft forever preferred_lft forever
    inet6 fe80::290:f5ff:fed1:6d46/64 scope link
       valid_lft forever preferred_lft forever
hs7@hcp:~$ ip route show dev enp5s0f2
default via 192.168.219.1 proto static
192.168.219.0/24 proto kernel scope link src 192.168.219.150

 

 

브릿지 br0 정보를 봅니다.  (현재는 유선인터넷만 브릿지 되어 있습니다. 무선인터넷도 브릿지 해야 합니다.)

hs7@hcp:~$ brctl showstp br0
br0
 bridge id              8000.d63274fa1f00
 designated root        8000.d63274fa1f00
 root port                 0                    path cost                  0
 max age                  20.00                 bridge max age            20.00
 hello time                2.00                 bridge hello time          2.00
 forward delay            15.00                 bridge forward delay      15.00
 ageing time             300.00
 hello timer               0.00                 tcn timer                  0.00
 topology change timer     0.00                 gc timer                 174.81
 flags


enp5s0f2 (1)
 port id                8001                    state                forwarding
 designated root        8000.d63274fa1f00       path cost                 19
 designated bridge      8000.d63274fa1f00       message age timer          0.00
 designated port        8001                    forward delay timer        0.00
 designated cost           0                    hold timer                 0.00
 flags

 

 

 

 

순서가 햇갈리시죠?

다시 짧게 정리 합니다.  (위에 언급한 거는 모두 잊으셔도 됩니다.)

# ip link add name br0 type bridge       #브릿지 br0 만듬
# ip link set dev br0 up                     #브릿지 활성화
# ip address add 10.2.3.4/8 dev br0         #브릿지에 유선인터넷 주소를 넣어 줍니다.
# ip route append default via 10.0.0.1 dev br0          #게이트 웨이를 주는건데, 저는 에러가 났습니다.

 

# ip link set eth0 master br0                #유선인터넷을 마스터로 지정합니다.
# ip address del 10.2.3.4/8 dev eth0       # 중요 #

#중요한 이유 ; 마스터 지정 후, 유선인터넷의 IP 주소를 바로 없애줘야 합니다. 그렇지 않으면, ssh 통신이 다운됩니다.

즉, 유선인터넷 IP 를 브릿지에 넘겨주면, 브릿지 Br0 이 인터넷 환경을 책임져 줍니다.

 

 

위 까지 했으면, 무선 AP 가 생겼을 접니다. 그리고 접속이 됩니다. 다만, 인터넷이 없다고 합니다.

마지막 단계는 무선 인터넷을 브릿지에 연결해 줍니다.

 

brctl addif br0 wlp4s0            #무선인터넷을 브릿지에 연결

 

그리고,

 

 ip address add dev br0 192.168.66.66/24               # 아무 상관없는 IP 를 브릿지에 넘겨 줍니다.

 

이때 부터, 무선 AP 에 접속되고, 인터넷도 됩니다.

 

스마트폰으로 접속해 봅니다.

- 브릿지 해서 그런지, 기존 공유기에서 할당 받은 ip 를 사용합니다.

 

 

*** 재부팅 하면, 설정이 날라 갑니다. (중간에 잘못해도, 서버 껏다 키면, 원래 인터넷을 찾습니다.)

 

이상, 노트북 무선 AP 작동만 해보고,

설치되 앱은 모두 삭제 했습니다.

 

sudo apt-get -y autoremove --purge dnsmasq
sudo apt-get -y autoremove --purge iw
sudo apt-get -y autoremove --purge nmcli
sudo apt-get -y autoremove --purge network-manager
sudo apt-get -y autoremove --purge hostapd
sudo apt-get -y autoremove --purge isc-dhcp-server
sudo apt-get -y autoremove --purge bridge-utils
sudo apt-get -y autoremove --purge net-tools
sudo apt autoremove