-
라즈베리파이 AP 만들기.Programming/Project 2018. 2. 13. 07:52
Raspberry Pi 4 model 에서의 테스트는 하지 못하였고
제 글은 Raspberry Pi 3B 모델이라 4 model은 레퍼런스 자료를 바탕으로 해주시면 될 것 같습니다.
비슷한 부분도 있는데 다른 부분도 있는 것 같아 남겨 드립니다.
reference : https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.mdSetting up a Raspberry Pi as a routed wireless access point - Raspberry Pi Documentation
documentation > configuration > wireless > access-point-routed Setting up a Raspberry Pi as a routed wireless access point A Raspberry Pi within an Ethernet network can be used as a wireless access point, creating a secondary network. The resulting new wir
www.raspberrypi.org
RaspberryPi 3 B Model AP Mode
dnsmasq와 hostapd
dnsmasq
: 1000클라이언트 이하의 로컬 네트워크에서 활용할 수 있는 간단한 DHCP/DNS 서버.DHCP
는 컴퓨터 사고 랜선 꼽으면 그냥 아무 설정 안했는데 자동으로 그냥 인터넷 연결도 되고 편하게 사용할 수 있다. 그렇게 해주는 설정이 바로 DHCP설정이라고 한다.DHCP를 통한 IP주소 할당은 흔히 '임대'라는 개념을 가지고 있어서 IP주소를 임대기간을 명시하여 그 기간 동안에만 단말이 IP주소를 사용할수 있다고 하고 더 사용하고자 하면 기간연장을 서버에 요청하고 필요없으면 반납절차를 수행하게 된다고 한다.
DNS
는 흔히 naver.com이나 google.co.kr 같은 도메인 네임을 뜻한다.hostapd is a user space daemon for wireless access point and authentication servers. There are three implementations: Jouni Malinen's hostapd, OpenBSD's hostapd and Devicescape's hostapd. Contents [hide]
AP와 인증 서버를 위한 사용자 공간 데몬이라고 한다. 데몬은 흔히 백그라운도 프로세스라고 불린다.
그냥 무선 네트워크 인터페이스는 AP모드로 전환하여 서비스를 하게 해주는 패키지라고 생각하면 될 것 같다.
라즈베리파이는 독립형 와이파이 ap로 사용할 수 있다.
라즈베리파이 3, 제로W 에 무선요소가 내장되었거나 AP를 지원하는 USB 동글이 탑제된 라즈베리도 가능하다.
라즈베리3 장비에서 테스트를 한 문서이고 USB동글을 이용하게 된다면 조금 설정을 바꿔야 하는 부분이 필요하다.
만약 USB 무선동글을 이용하여 문제가 발생이되면, 동글의 상태를 체크하길 바란다.
추가적으로 라즈베리파이 기본 AP의 네트워크 설정에 관한 정보는 이 섹션을 참고한다.
sudo apt-get update sudo apt-get upgrade sudo apt-get install dnsmasq hostapd
sudo systemctl stop dnsmasq sudo systemctl stop hostapd
Configuring a static IP - 고정 IP 설정.
라즈베리파이는 무선포트 연결을 위해 고정 아이피 필요하다.
192.168.x.x의 주소를 무선 네트워크 주소를 사용한다.
라즈베리파이 주소는 192.168.4.1이고 wlan0이라는 이름을 사용한다.
고정 IP주소를 사용하고 dhcp 설정 파일을 편집을 한다.
sudo nano /etc/dhcpcd.conf
다음으로 파일의 마지막 줄에 아래의 글을 추가로 적고 저장 후 종료한다.
interface wlan0 static ip_address=192.168.4.1/24
그리고 dhcp 데몬을 재시작하고 새로운 wlan0설정이 되었는지 확인한다.
sudo systemctl restart dhcpcd
#Configuring the DHCP server (dnsmasq)
DHCP 서비스는 dnsmasq로부터 제공된다.
결과적으로 설정파일은 많은 정보가 필요하지는 않고 쉬운 편이다.
설정 파일을 이름을 재설정 하고, 새로운 것을 하나 만든다.
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf
Type or copy the following information into the dnsmasq configuration file and save it: dnsmasq 설정파일에서 다음과 같은 타입과 정보들을 저장한다.
interface=wlan0 # Use the require wireless interface - usually wlan0 dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
wlan0을 따라, 192.168.4.2에서 192.168.4.20 사이의 IP주소들을 제공할 것이고 24시간동안 제공할 것이다. 만약 DHCP 서비스를 다른 네트워크 장비들에게 제공하고 싶다면, 섹션을 추가하고 주소의 범위와 함께 인터페이스 설정을 만들어주면 된다. dnsmasq의 많은 옵션이 있고, 더 자세한 사항은 dnsmasq 문서를 참고하면 된다.
hostapd의 설정을 한다. hostapd 설정 파일을 편집하는 것이 필요한데, 해당 파일의 위치는 /etc/hostad/hostapd.conf에 존재하며 무선 네트워크 파라미터들을 추가한다. 인스톨 후 새로운 빈 파일을 생성한다.
sudo nano /etc/hostapd/hostapd.conf
설정 파일의 정보를 추가한다. 이 설정은 7 채널을 사용하였으며 네트워크 이름과 패스워드는 임의로 설정해주면 된다. 이름과 패스워드를 노트해둔다.
interface=wlan0 driver=nl80211 ssid=NameOfNetwork hw_mode=g channel=7 wmm_enabled=0 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=AardvarkBadgerHedgehog wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
우리는 설정파일을 찾아 설정해주고 시스템에 알려줄 필요가 있다.
sudo nano /etc/default/hostapd
Find the line with #DAEMON_CONF, and replace it with this:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
서비스를 재시작 해준다.
sudo systemctl start hostapd sudo systemctl start dnsmasq
추가적으로 라우팅과 마스크레이드 설정을 한다.
Edit
/etc/sysctl.conf
and uncomment this line:net.ipv4.ip_forward=1
Add a masquerade for outbound traffic on eth0:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Save the iptables rule.
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Edit
/etc/rc.local
and add this just above "exit 0" to install these rules on boot.iptables-restore < /etc/iptables.ipv4.nat
Reboot
이 부분에서 Reboot 후 무선장치에 SSID가 검색이 된다고 나와 있지만 전혀 나타나지 않았다.
sudo hostapd /etc/hostapd/hostapd.conf
sudo hostapd /etc/hostapd/hostapd.conf
하면 AP모드가 작동하지 않고 ERROR가 발생하게 되었다.
- 만약 AP모드가 작동한다면 여기서부터는 생략해주어도 된다.
에러는
Line2 : invalid/unknown driver 'nl80211'
라이브러리가 필요하다고 하니까 이것도 설치를 한다.
sudo apt-get install libssl-dev
nl80211 이라는 것을 아예 못찾는 것 같으니까 다운로드부터 받도록 한다.
git clone git://w1.fi/srv/git/hostap.git cd hostap/hostapd
Or you can get a stable release (0.6.8 or later recommended)
by downloading the tarball from http://w1.fi/hostapd/ as follows:http://w1.fi/hostapd/ 이 링크에 들어가면 2018.02.21. 기준으로
가장 최근버젼인 2.6 버젼을 다운로드 받도록 한다.wget http://w1.fi/releases/hostapd-x.y.z.tar.gz tar xzvf hostapd-x.y.z.tar.gz cd hostapd-x.y.z/hostapd
여기서 x.y.z.는 버젼이다. 나는 ~ hostapd-2.6.tar.gz 라고 해주었다. 상황에 따라 맞게 타이핑 쳐주자.
cp defconfig .config
nano .config
.config 파일로 들어가서 찾아준다.
/#CONFIG_DRIVER_NL80211=y
/#부분을 없앤다. 최근버젼인 2.6버젼에는 애초에 #이 없었다.
/는 깃허브에 올릴려고 추가적으로 붙인 것이니 원래 없는 부분... 신경쓰지 말자!!Next, compile hostapd:
make
컴파일을 해준다. 여기서 분명 안되는 것 처럼 나온 게 아니라 설정이 꼬여서 그랬는지 이게 뜨긴하는데 신경안씀.
../src/drivers/driver_nl080211.c:17:31: fatal error~~
에러여기서 이제
sudo apt-get hostapd hostapd/hostapd.conf
sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf
완료되었다.
무선장치를 통하여 해당 SSID가 잘 검색이 되면서 작동하는지 확인한다.
이 부분에서 ReBoot 후 무선장치에 SSID가 검색이 된다고 나와있지만 나타나지 않음을 확인했다.
StackOverflow 검색을 하며 해결을 하였다.
$ sudo hostapd /etc/hostapd/hostapd.conf
------------------------
여기서 이제
$sudo apt-get hostapd hostapd/hostapd.conf 를 해보도록하자.
$sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf 도 같은 거라고 생각하면 될 것 같다.
드디어!! 성공!!
그럼 이제 사설ip로 휴대폰이나 놋북에서 잘 받아지는지 확인을 해봄.
사설ip 를 192.168.4.2 ~ 20까지 주었는데 매우 잘된다! 아래는 SSH로 접속하는 방법입니다. putty로 해봄.
이 부분은 라즈베리파이를 브릿지 모드로 사용하고 싶으면 하면 되고 아니면 할 필요없습니다~~브릿지모드를 사용하게 된다면 라즈베리파이에서 사설ip를 퍼트려주는 것이 아니라 공인ip를 퍼트려 주게 되는 것이 확인이 됨.
라즈베리파이를 사설망으로 사용하여야 해서 이 부분의 과정은 거치지 않았음.
----------------------------------------------------------------------------------------------------------------------------------------------------
If SSH is enabled on the Raspberry Pi access point, it should be possible to connect to it from another Linux box (or a system with SSH connectivity present) as follows, assuming the ssh pi@192.168.4.1
By this point, the Raspberry Pi is acting as an access point, and other devices can associate with it. Associated devices can access the Raspberry Pi access point via its IP address for operations such as Using the Raspberry Pi as an access point to share an internet connection..
One common use of the Raspberry Pi as an access point is to provide wireless connections to a wired Ethernet connection, so that anyone logged into the access point can access the internet, providing of course that the wired Ethernet on the Pi can connect to the internet via some sort of router To do this, a 'bridge' needs to put in place between the wireless device and the Ethernet device on the access point Raspberry Pi. This bridge will pass all traffic between the two interfaces. Install the following packages to enable the access point setup and bridging.
sudo apt-get install hostapd bridge-utils
Since the configuration files are not ready yet, turn the new software off as follows:
sudo systemctl stop hostapd
Bridging creates a higher-level construct over the two ports being bridged. It is the bridge that is the network device, so we need to stop the
eth0
andwlan0
ports being allocated IP addresses by the DHCP client on the Raspberry Pi.sudo nano /etc/dhcpcd.conf
Add
denyinterfaces wlan0
anddenyinterfaces eth0
to the end of the file (but above any other addedinterface
lines) and save the file.Add a new bridge, which in this case is called
br0
.sudo brctl addbr br0
Connect the network ports. In this case, connect
eth0
to the bridgebr0
.sudo brctl addif br0 eth0
Now the interfaces file needs to be edited to adjust the various devices to work with bridging.
sudo nano /etc/network/interfaces
make the following edits.Add the bridging information at the end of the file.
# Bridge setup auto br0 iface br0 inet manual bridge_ports eth0 wlan0
The access point setup is almost the same as that shown in the previous section. Follow the instructions above to set up the
hostapd.conf
file, but addbridge=br0
below theinterface=wlan0
line, and remove or comment out the driver line.interface=wlan0 bridge=br0 #driver=nl80211 ... Now reboot the Raspberry Pi. There should now be a functioning bridge between the wireless LAN and the Ethernet connection on the Raspberry Pi, and any device associated with the Raspberry Pi access point will act as if it is connected to the access point's wired Ethernet.
The
ifconfig
command will show the bridge, which will have been allocated an IP address via the wired Ethernet's DHCP server. Thewlan0
andeth0
no longer have IP addresses, as they are now controlled by the bridge. It is possible to use a static IP address for the bridge if required, but generally, if the Raspberry Pi access point is connected to a ADSL router, the DHCP address will be fine.반응형'Programming > Project' 카테고리의 다른 글
주요정보통신기반시설 가이드 - 취약점 진단 (0) 2020.11.09 대기열 프로젝트 (0) 2019.04.02 PHP를 이용한 공유기 페이지 작성. (0) 2018.08.22 Jmeter 이용한 라즈베리파이 HTTP 통신 부하테스트 (0) 2018.07.04