#OpenWrt์ Raspberry PI2๋ฅผ ์ด์ฉํ ๊ณต์ ๊ธฐ ๋ง๋ค๊ธฐ
##0. ์๋ก Raspberry Pi2์ OpenWrt๋ฅผ ์ด์ฉํ์ฌ ์์ค์์ ๊ตฌํ ์ ์๋ ๊ณต์ ๊ธฐ๋ฅผ ๋ง๋๋ ์์ ์ ๋๋ค. ๋ณธ ์์ ์์ ๊ตฌํํ๊ณ ์ํ๋ ๊ณต์ ๊ธฐ์ ํฌํจ๋ก์ง์ ๊ณต์ ๊ธฐ์ ์ธํฐํ์ด์ค ์ ๋ณด๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
Fig1. Topologyroot@openwrt:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:90:f5:e4:cb:2c
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::290:f5ff:fee4:cb2c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:823383 errors:0 dropped:5 overruns:0 frame:0
TX packets:99326 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:271224907 (271.2 MB) TX bytes:9310318 (9.3 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:6436 errors:0 dropped:0 overruns:0 frame:0
TX packets:6436 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:760775 (760.7 KB) TX bytes:760775 (760.7 KB)
wlan0 Link encap:Ethernet HWaddr 2c:d0:5a:61:5c:f4
inet addr:192.168.100.1 Bcast:192.168.100.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
##1. ์ค๋น๋ฌผ 0. ํฌ๋ก์ค ์ผ์ด๋ธ 0. ๋ฐ์คํฌํ(64bit, Ubuntu 14.04 LTS) 0. Raspberry Pi2 0. WiFi USB ๋๊ธ
##2. OpenWrt ์ค์น
- ์ด๋ฏธ์ง ๋ค์ด๋ก๋
-
์ปค์คํ ์ด๋ฏธ์ง
๋ณธ ์์ ์์ ์ฌ์ฉ๋ ์ด๋ฏธ์ง์ ๋๋ค. ์ฌ๊ธฐ ํ๋จ๋ถ์์ ๋ฐ์ผ์ค ์ ์์ต๋๋ค. ๊ฐ์ข ์ ํธ๋ฆฌํฐ์ ๋ฌด์ ๋ ๋๋ผ์ด๋ฒ๊ฐ ๊ธฐ๋ณธ ๋ด์ฅ๋์์ผ๋ฏ๋ก ๋ณธ ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ๋ค๊ณ ๊ฐ์ ํ๊ณ ์งํํ๊ฒ ์ต๋๋ค. ํน์ ์ปค์คํ ์ด๋ฏธ์ง๋ฅผ ์ง์ ๋น๋ ์ฌ๊ธฐ๋ฅผ ์ฐธ์กฐ ํ์ธ์. -
๊ณต์ ๋ฐฐํฌ ์ด๋ฏธ์ง
์ฌ๊ธฐ์์ ํ์ํ ์ด๋ฏธ์ง๋ฅผ ๋ฐ์ ์ ์์ต๋๋ค. * Raspberry Pi1์ ๊ฒฝ์ฐ: brcm2708/brcm2708/ * Raspberry Pi2์ ๊ฒฝ์ฐ: brcm2708/brcm2709/
ํ์ ๋๋ ํ ๋ฆฌ์์ ํด๋น sdcard ์ด๋ฏธ์ง๋ฅผ ๋ฐ์ ์ ์์ต๋๋ค. ํด๋น ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ
๋๋ผ์ด๋ฒ ๋ฑ์ ๋ฐ๋ก ์ก์์ค์ผ ํ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค.
- sd ์นด๋์ ์ด๋ฏธ์ง ๋ฃ๊ธฐ
์ฌ๊ธฐ๋ฅผ ์ฐธ์กฐํ์ธ์. ๊ทธ ์ธ ๋์ฑ ์์ธํ ์ ๋ณด๋ฅผ ์ป์ผ์ค๋ ค๋ฉด OpenWrt Wiki/Raspberry Pi ํญ๋ชฉ์ ์ฐธ์กฐ ํ์ธ์.
##3. ๋ก๊ทธ์ธ ๋ฐ ์ด๊ธฐ ์ค์
###3.1 ๋ก๊ทธ์ธ
OpenWrt ์ต์ด ์ค์น ๋์์ ๋ ๊ธฐ๋ณธ๊ฐ์ผ๋ก 192.168.1.1์ ์ฃผ์๋ฅผ ๊ฐ์ต๋๋ค.
๋ํ root ๊ณ์ ์ ๋น๋ฐ๋ฒํธ๋ฅผ ๋ณ๊ฒฝ ํ๊ธฐ ์ ๊น์ง ssh ์ ์๊ณผ https ์ ์์ด ๋ถ๊ฐ๋ฅ ํฉ๋๋ค.
๋์ฑ ์์ธํ ์ ๋ณด๋ firstlogin ๋ฅผ ์ฐธ์กฐํ์๊ธธ ๋ฐ๋๋๋ค.
-
ํธ์คํธ ์ปดํจํฐ์ Raspberry Pi๋ฅผ ํฌ๋ก์ค ์ผ์ด๋ธ๋ก ์ฐ๊ฒฐํฉ๋๋ค.
์ผ๋ฐ์ ์ธ USB ํค๋ณด๋๋ก๋ ์ ๋ ฅ์ด ๋ถ๊ฐ๋ฅํ๋ฏ๋ก ํฌ๋ก์ค ์ผ์ด๋ธ์ ์ด์ฉํ์ฌ ๋ก๊ทธ์ธ ํ๋ ๋ฒ์ ์ค๋ช ํฉ๋๋ค. UART-USB console cable๋ฅผ ๊ฐ์ง๊ณ ๊ณ์๋ฉด ๋ฐ๋ก ๋ก๊ทธ์ธ ํ๋ฉด ๋ฉ๋๋ค. -
ํธ์คํธ ์ปดํจํฐ์ ๋คํธ์ํฌ ์ค์ ์ ๋ฐ๊พธ์ด ์ค๋๋ค.
MCLAB@KHU:~$ sudo service network-manager stop
MCLAB@KHU:~$ sudo ifconfig eth0 192.168.1.2/24
- telnet์ ์ด์ฉํ์ฌ ์ ์์ ํฉ๋๋ค.
์์ ์ธ๊ธํ๋ฏ, OpenWrt๋ ์ต์ด ๋ก๊ทธ์ธ์ 192.168.1.1์ ์ฃผ์๋ฅผ ๊ฐ์ต๋๋ค. telnet์ ์ด์ฉํ์ฌ ์๋์ ๊ฐ์ด ์ ์์ ์๋ ํฉ๋๋ค.
MCLAB@KHU:~$ telnet 192.168.1.1
์๋์ ๊ฐ์ ํ๋ฉด์ด ์ถ๋ ฅ๋๋ฉด ์ฑ๊ณต์ ๋๋ค.
Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is '^]'.
=== IMPORTANT ============================
Use 'passwd' to set your login password
this will disable telnet and enable SSH
------------------------------------------
BusyBox v1.23.2 (2015-07-03 17:09:21 CEST) built-in shell (ash)
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
CHAOS CALMER (15.05-rc3, r46163)
-----------------------------------------------------
* 1 1/2 oz Gin Shake with a glassful
* 1/4 oz Triple Sec of broken ice and pour
* 3/4 oz Lime Juice unstrained into a goblet.
* 1 1/2 oz Orange Juice
* 1 tsp. Grenadine Syrup
-----------------------------------------------------
root@openwrt:~$
- ํจ์ค์๋๋ฅผ ๋ฐ๊ฟ ์ค๋๋ค.
root@openwrt:~$ passwd
Changing password for root
New password:
Retype password:
Password for root changed by root
root@openwrt:~$
์ด์ ๋ถํฐ telnet์ผ๋ก ์ ์ ํ ์ ์์ผ๋ฉฐ, ssh ๋ ์น์ธํฐํ์ด์ค๋ก ์ ์ํด์ ์ค์ ํด์ผ ํฉ๋๋ค.
###3.2 ํ์ ํจํค์ง ์ค์น 2.1.1์์ ์ฌ์ฉํ ์ปค์คํ ์ด๋ฏธ์ง๋ฅผ ์ด์ฉํ๋ฉด, ๋๋ถ๋ถ์ ๋๋ผ์ด๋ฒ๋ฅผ ํฌํจํ๊ณ ์์ต๋๋ค. ๋ฐ๋ผ์ ๋๋ผ์ด๋ฒ๋ฅผ ์ ์ธํ, ํ์ ํจํค์ง์ธ hostapd ๊ฒฝ๋๋ฒ์ ์ธ wpad๋ฅผ ์ค์น ํ๋๋ก ํฉ๋๋ค.
-
wpad ๋ค์ด๋ก๋
ํธ์คํธ ์ปดํจํฐ์์ wpad (for Raspberry Pi2 package)๋ฅผ ๋ฐ์ต๋๋ค. -
Raspberry Pi2๋ก ์ ๋ก๋ ํ๊ธฐ
ํธ์คํธ ์ปดํจํฐ์์ Raspberry Pi2 wpad๋ฅผ ์ ๋ก๋ ํฉ๋๋ค.
MCLAB@KHU:~$ scp ./wpad_2015-03-25-1_brcm2708.ipk root@192.168.1.1:/
-
wpad ์ค์นํ๊ธฐ
-
wpa_supplicant ์ด๋ฆ์ ๋ณ๊ฒฝํฉ๋๋ค.(ํ์ผ ์ถฉ๋ ์๋ฐฉ)
root@OpenWrt:/# mv /usr/sbin/wpa_supplicant /usr/sbin/wpa_supplicant2 -
opkg๋ฅผ ํตํ์ฌ wpad๋ฅผ ์ค์นํฉ๋๋ค.
root@OpenWrt:/# opkg install wpad_2015-03-25-1_brcm2708.ipk Installing wpad (2015-03-25-1) to root... Configuring wpad. root@OpenWrt:/#
##4. ๊ณต์ ๊ธฐ๋ก ์ค์ OpenWrt์ ์ฃผ์ ์ค์ ์ UCI System(Unified Configuration Interface)์ํด ์ด๋ฃจ์ด ์ง๋๋ค. UCI System์ ๋ชจ๋ ์ค์ ํ์ผ์ /etc/config/ ๋๋ ํ ๋ฆฌ ์๋์ ์์ต๋๋ค.
๋ง์ฝ linux physical interface ๋ฐ linux virtual interface๋ฅผ ๋ชจ๋ฅด์ ๋ค๋ฉด ์ฌ๊ธธ ๋ฅผ ๋จผ์ ์ฐธ์กฐํ์ธ์.
###4.1 /etc/config/wireless ์ค์
iw๋ฅผ ๋์ฒดํ๋ UCI System ์ค์ ํ์ผ๋ก, ๋ฌด์ ๋ ์ด๋ํฐ๋ฅผ ์ค์ ํฉ๋๋ค. wifi-device, wifi-iface ๋ ๊ฐ์ง ํญ๋ชฉ์ ์์ ํด์ผํฉ๋๋ค. ์๋๋ ๋ฌด์ ๋ ๋๊ธ์ ์ฐ๊ฒฐ ํ์ ๋ ๊ธฐ๋ณธ์ผ๋ก ์์ฑ๋์ด์๋ ๊ธฐ๋ณธ ์ค์ ์ ๋๋ค.
config wifi-device radio0
option type mac80211
option channel 11
option hwmode 11g
option path 'platform/bcm2708_usb/usb1/1-1/1-1.5/1-1.5:1.0'
option htmode HT20
# REMOVE THIS LINE TO ENABLE WIFI:
option disabled 1
config wifi-iface
option device radio0
option network lan
option mode ap
option ssid OpenWrt
option encryption none
- wifi-device section
linux physical interface ์ ํด๋น ํ๋ ๊ฒ์ผ๋ก, iw phy ๋ช ๋ น์ ํตํด์ ํ์ธ ํ ์ ์์ต๋๋ค. ์ด ํญ๋ชฉ์ ์์คํ ์ ์ํด์ ์ค์ ํ์ผ์ ์๋์ผ๋ก type, hwmode, path, htmode ๋ฑ์ด ์ค์ ๋๋ฏ๋ก channel์ ์ ๋ณด๋ง ์์ ํด ๋ด ์๋ค.
config wifi-device radio0
option type mac80211
option channel 6
option hwmode 11a
option path pci0000:00/0000:00:00.0
option htmode HT20
- config wifi-device
- UCI System ๋ด๋ถ์ ์ผ๋ก ์ฌ์ฉ๋ wifi-deviceํ์ ์ ์๋ณ์๋ฅผ ์ ์ํฉ๋๋ค.
- wifi-iface section
linux virtual interface ์ ํด๋นํ๋ ๊ฒ์ผ๋ก, iw dev info ํตํด์ ํ์ธ ํ ์ ์์ต๋๋ค. ๋ฌด์ ์ค์ ์ /etc/config/wireless ์์ ์ ํตํด ์ด๋ฃจ์ด ์ง๋๋ค. ์๋์ ๊ฐ์ด ์ถ๊ฐ ํฉ๋๋ค. - option device
- wifi-device section์ ์ ์๋ wifi-deviceํ์ ์ ์๋ณ์๋ฅผ ์ง์ ํฉ๋๋ค.
- config interface
- UCI System ๋ด๋ถ์ ์ผ๋ก ์ฌ์ฉ๋๋ interface ํ์ ์ ์๋ณ์ ์ด๋ฆ์ ๋๋ค
- option ifname
- ethernet์ ๊ฒฝ์ฐ ๋ฌผ๋ฆฌ ์ธํฐํ์ด์ค๋ฅผ ์ง์ ํฉ๋๋ค.
- wifi์ ๊ฒฝ์ฐ ์๋ตํฉ๋๋ค.
- option proto
- static ํน์ dhcp(or dhcpv6)๊ฐ ๋ ์ ์์ต๋๋ค.
<dt>option channel</dt>
<dd>์ด๋ํฐ๊ฐ ์ฌ์ฉํ ๋ฌผ๋ฆฌ ์ฒด๋์ ์ง์ ํฉ๋๋ค.</dd>
<dt>option disabled</dt>
<dd>๋๋ฐ์ด์ค์ ๊ธฐ๋ณธ ๋์์ '๋' ์ํ๋ก ์ค์ ํฉ๋๋ค. ํด๋น ํญ๋ชฉ์ ์ญ์ ํฉ๋๋ค.</dd>
</dl>
config wifi-iface
option device radio0
option network wlan
option mode ap
option ssid OpenWrt
option encryption none
<dt>option network</dt>
<dd>๋ฌด์ ์ ์ฐ๊ฒฐ๋ interface ์๋ณ์๋ฅผ ์ง์ ํฉ๋๋ค. interface๋ ๋ค์ ํญ๋ชฉ์์ ์์ธํ ์ค๋ช
๋ฉ๋๋ค.</dd>
<dt>option mode</dt>
<dd>๋ฌด์ ์ด๋ํฐ์ ๋์ ๋ชจ๋๋ฅผ ์ง์ ํฉ๋๋ค. ๊ณต์ ๊ธฐ๋ก ์ฌ์ฉ ๋ ๊ฒ์ด๋ฏ๋ก ap๋ผ๊ณ ์ ์ต๋๋ค.</dd>
<dt>option ssid</dt>
<dd>๋ฌด์ ๊ณต์ ๊ธฐ๊ฐ ๋ธ๋ก๋์บ์คํธ ํ ssid๋ฅผ ์ง์ ํฉ๋๋ค. </dd>
<dt>option encryption</dt>
<dd>์ํธํ ๋ฐฉ์์ ์ ํํฉ๋๋ค. ๊ฐ๋จํ ์์ ์ด๋ฏ๋ก none์ผ๋ก ์ค์ ํฉ๋๋ค.</dd>
</dl>
๋ค๋ฅธ ์์ธํ ์ต์ ์ ๋ณด๋ ค๋ฉด ์ฌ๊ธฐ๋ฅผ ์ฐธ๊ณ ํ์ธ์.
###4.2 /etc/config/network ์ค์ ifconfig๋ฅผ ๋์ฒดํ๋ UCI System ์ค์ ํ์ผ๋ก, ๋คํธ์ํฌ๋ฅผ ์ค์ ํฉ๋๋ค.
config interface lan
option ifname eth0
option proto static
option ipaddr 192.168.1.1
option netmask 255.255.255.0
config interface wlan
option proto static
option ipaddr 192.168.100.1
option netmask 255.255.255.0
###4.3 /etc/config/dhcp ์ค์ DHCP ์ค์ ์ ๋๋ค. ํ ๋นํด ์ค ์ฃผ์์ ๋ฒ์์ ์๊ฐ ๋ฑ์ ์ง์ ํด ์ค ์ ์์ต๋๋ค.
config dhcp wlan
option interface wlan
option start 100
option limit 150
option leasetime 12h
###4.4 /etc/config/firewall
*iptables*๋ฅผ ๋์ฒดํ๋ UCI System ์ค์ ํ์ผ๋ก, ๋ฐฉํ๋ฒฝ ์ค์ ๋ฐ NAT ์ค์ ํฉ๋๋ค. ์ด๋ฒ ํญ๋ชฉ์ ๊ณต์ ๊ธฐ๋ก ์๋ํ๊ธฐ ์ํ ๊ธฐ๋ณธ ์ค์ ๋ง ํ๋๋ก ํ๊ณ ์์ธํ ์ค๋ช ์ ์๋ต ํ๋๋ก ํ๊ฒ ์ต๋๋ค. ๋ง์ฝ ๋ณด๋ค ์์ธํ ์ค์ ์ ํ์๋ ค๋ฉด Firewall configuration์ ์ฐธ์กฐํ์ญ์์ค.
config zone
option name lan
list network lan
option input ACCEPT
option output ACCEPT
option forward REJECT
config zone
option name wlan
list network wlan
option input ACCEPT
option output ACCEPT
option forward REJECT
option masq 1
config forwarding
option src lan
option dest wlan
config forwarding
option src wlan
option dest lan
##5. ๋ณ๊ฒฝ์ฌํญ ์ ์ฉ ์์์ ์๋์ ๊ฐ์ด ์ ๋ ฅํฉ๋๋ค.
root@openwrt:~$ ifdown wlan
root@openwrt:~$ ifup wlan
root@openwrt:~$ /etc/init.d/firewall restart
root@openwrt:~$ /etc/init.d/dnsmasq restart
์ฃผ์: ifdown, ifup ๋ค์ ์ธ์๋ 4.2์ ์์ ์ ์๋ ์๋ณ์์ ๋๋ค. ์ปค๋ ์ธํฐํ์ด์ค ์ด๋ฆ์ด ์๋๋๋ค.
##6. ๋์ ํ์ธ
Raspberry Pi2์ OpenWrt์์์ ์ ๋๋ก ๋์ํ๋์ง ํ์ธํด ๋ด ์๋ค.
root@OpenWrt:/etc/config# iw dev
phy#0
Interface wlan0
ifindex 10
wdev 0x7
addr 00:e0:4d:a0:30:65
ssid OpenWrt
type AP
channel 11 (2462 MHz), width: 20 MHz, center1: 2462 MHz
