프로젝트 진행 중 프로그래밍을 통해 통해 무선 랜카드의 모드를 managed 모드에서 AP 모드로 바꿔야하는 일이 생겼다. 그래서 Command Line에서 무선 랜카드의 모드를 AP 모드로 바꾸는 방법을 찾아보았고 다음과 같은 방법으로 해결할 수 있었다.

 

 먼저 WiFi AP 모드를 설정하기 위해서는 먼저 가지고 있는 무선 랜카드가 AP 모드를 지원해야한다. AP 모드 지원 여부를 확인하는 방법은 아래와 같이 Command Line에서 iw list 명령을 실행한 다음 Supported interface modes에서 AP가 있는지 확인하면 된다.

 

※ 참고로 내가 사용하는 무선 랜카드는 ipTime의 A3000U이다.

 

 

 무선 랜카드가 AP 모드를 지원하는 것을 확인하였으면 먼저 hostapd를 설치한다. hostapd는 네트워크 인터페이스 카드를 AP 또는 인증 서버 역활을 할 수 있게하는 데몬이다.

sudo apt install hostapd

 

그리고 /etc/hostapd/hostapd.conf 파일을 아래와 같이 작성한다.

interface=wlx88366cfb576c
driver=nl80211
ssid=Catch Catch
hw_mode=g
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=1234567890
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

 위의 작성한 부분에서 interface=wlx88366cfb576c 부분은 자신의 무선 랜카드의 인터페이스 이름을 적어줘야 한다. 무선 랜카드의 인터페이스 이름을 확인하는 방법은 아래와 같이 ifconfig 명령어로 확인할 수 있다.

 

 

 그리고 ssid=Catch Catch 부분은 다른 사람들에게 보여줄 ssid를 쓰면되고 wpa_passphrase=1234567890 부분은 내 AP에 접속할 때 필요한 비밀번호로 원하는 비밀번호로 변경하면 된다.

 

 이제 /etc/default/hostapd 파일에서 아래와 같이 DAEMON_CONF="/etc/hostapd/hostapd.conf"를 추가해 hostapd 설정 파일의 위치를 /etc/hostapd/hostapd.conf로 지정해준다.

 

 

 이제 hostapd에서 해야할 작업은 끝났다. 다음으로는 내 AP에 접속하는 사용자들에게 IP를 동적으로 할당해주기 위한 DHCP 서버를 설정해야한다.

 

 먼저 isc-dhcp-server를 설치한다.

sudo apt install isc-dhcp-server

 그리고 /etc/default/isc-dhcp-server 파일을 열어 마지막 줄에 INTERFACES="wlx88366cfb576c"와 같이 DHCP 요청을 처리할 인터페이스를 추가한다.

 

 

 그리고 /etc/dhcp/dhcpd.conf 파일을 열어 아래 보이는 부분들을 주석처리한다.

 

 

 그리고 마지막 줄에 아래 내용을 추가한다. 간단하게 내용을 살펴보면 내 AP에 접속한 기기들에게 10.10.0.2 ~ 10.10.0.16 사이에 있는 IP를 할당해주고 라우터(내 AP) IP는 10.10.0.1이다.

subnet 10.10.0.0 netmask 255.255.255.0 {
        range 10.10.0.2 10.10.0.16;
        option domain-name-servers 8.8.8.8;
        option routers 10.10.0.1;
}

 그리고 /etc/network/interfaces 파일을 열어 아래 부분을 추가해준다. wlx88366cfb576c는 AP가 될 인터페이스 이름을 입력하면 된다.

auto wlx88366cfb576c
iface wlx88366cfb576c inet static
address 10.10.0.1
netmask 255.255.255.0

 이제 아래 명령어로 isc-dhcp-server와 hostapd를 실행시킨다.

sudo service isc-dhcp-server start
sudo service hostapd start

 그리고 재부팅 후 iwconfig로 무선 랜카드의 상태를 보면 Mode가 Master로 변한 것을 확인할 수 있고 다른 장치에서 와이파이 목록을 확인해보면 내가 만든 AP가 보이는 것을 확인할 수 있다. 그리고 연결하면 IP가 10.10.0.2 ~ 10.10.0.16 사이에서 할당받는 것을 확인할 수 있다.

 

※ sudo service hostapd start 명령어 실행 시 Failed to start hostapd.service: Unit hostapd.service is masked. 오류가 발생할 경우 Command Line에서 아래 명령어를 입력한다.

sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd

 마지막으로 AP에 접속한 기기들이 인터넷을 할 수 있도록 IP forwarding과 IP masquerading 해줘야한다. 먼저 /etc/sysctl.conf/ 파일을 열어 # net.ipv4.ip_forward=1 이 부분을 찾아 net.ipv4.ip_forward=1로 변경해 IP forwarding을 해준다. 

 

 그리고 iptables-persistent를 설치한 다음

sudo apt install iptables-persistent

 sudo iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -o ens33 -j MASQUERADE 명령어를 입력해 IP masquerading을 해준다. 이때 ens33은 인터넷이 가능한 인터페이스 이름이다. 그리고 sudo netfilter-persistent save 명령어로 추가한 정책을 저장한다.

 

 이제 재부팅 후 다른 디바이스 장치에서 내가 만든 AP에 접속하면 인터넷이 되는 것을 확인할 수 있다.

 

 

참고사이트

 

https://medium.com/@arnab.k/ubuntu-how-to-setup-a-wi-fi-hotspot-access-point-mode-192cbb2eeb90

https://askubuntu.com/questions/119393/how-to-save-rules-of-the-iptables

https://github.com/raspberrypi/documentation/issues/1018

 Ubuntu 18.04 버전에서 이번에 새로 구매한 ipTIME A3000U를 사용하려고 하는데 드라이버가 자동으로 설치되지 않아 설치하는 방법을 찾아보았고 터미널에서 아래와 같이 입력하여 드라이버를 설치할 수 있었다.

 

sudo apt-get update

sudo apt-get install build-essential dkms git

sudo git clone https://github.com/cilynx/rtl88x2BU_WiFi_linux_v5.3.1_27678.20180430_COEX20180427-5959.git

cd rtl88x2BU_WiFi_linux_v5.3.1_27678.20180430_COEX20180427-5959

VER=$(sed -n 's/\PACKAGE_VERSION="\(.*\)"/\1/p' dkms.conf)

sudo rsync -rvhP ./ /usr/src/rtl88x2bu-${VER}

sudo dkms add -m rtl88x2bu -v ${VER}

sudo dkms build -m rtl88x2bu -v ${VER}

sudo dkms install -m rtl88x2bu -v ${VER}

sudo modprobe 88x2bu

 

 다 입력하였으면 이제 A3000U를 연결한 다음 터미널에서 ifconfig를 입력하면 아래와 같이 A3000U에 대한 인터페이스를 확인할 수 있다. 

 

 드라이버 설치에 관한 자세한 내용은 https://github.com/cilynx/rtl88x2BU_WiFi_linux_v5.3.1_27678.20180430_COEX20180427-5959의 README.md에서 확인할 수 있다.

 

 

참고사이트

 

1. http://blog.naver.com/PostView.nhn?blogId=namhong2001&logNo=221548649952&parentCategoryNo=&categoryNo=56&viewDate=&isShowPopularPosts=true&from=search

2. https://askubuntu.com/questions/1079377/how-do-i-install-drivers-for-realtek-rtl8812bu

3. https://github.com/cilynx/rtl88x2BU_WiFi_linux_v5.3.1_27678.20180430_COEX20180427-5959

무선 랜카드가 리눅스에서 지원하는 인터페이스 모드를 확인하고자 할 때 iw list 명령어로 확인할 수 있다.

 

 

그러면 아래와 같이 Supported interface modes를 확인할 수 있고 여기서 지원되는 모드를 확인할 수 있다.

 

 프로그램을 개발하다가 터미널에서 프로세스를 포그라운드로 실행시킨 다음 해당 프로세스가 진행 중일 때 다른 명령어를 입력할 수 있도록 만들 필요가 생겼다.

 

 떠오른 방법은 새로운 터미널에 프로세스를 실행시켜 현재 터미널에서는 계속 다른 명령어를 입력할 수 있도록 하는 방법이었다.

 

 방법을 찾아보니 아래와 같은 명령어를 사용하면 현재 터미널은 유지되면서 새로운 터미널에서 원하는 프로세스(명령어)를 실행할 수 있다. 그리고 해당 프로세스가 끝나면 새로운 터미널은 자동으로 종료된다.

 

gnome-terminal --command "command"

gnome-terminal -e "command"

 

추가로 위의 명령어를 입력하면 아래와 같이  gnome-terminal의 이후 버전에서는 제거될 수도 있다고 나온다.

 

 

이를 해결 하려면 아래와 같이 --command, -e 대신 --를 사용하면 된다. 여기서 중요한 점은 command를 쓸 때 띄어쓰기가 포함되더라도 "command"나 'command'와 같이 command 양 끝에 큰 따옴표나 작은 따옴표를 붙이면 안된다는 점이다.

 

gnome-terminal -- command

 

 

다음 사이트를 참고하여 Ubuntu 18.04에서 MySQL 8.0을 설치하였다.

 

https://www.fosstechnix.com/how-to-install-mysql-8-in-ubuntu/

 

How to Install MySQL 8.0 on Ubuntu 18.04 / 16.04 - FOSS TechNix

In this article, We are going to demonstrate installation of latest MySQL 8.0 database server on Ubuntu 18.04 Bionic Beaver step by step using command line.

www.fosstechnix.com

 

MySQL 설치 순서는 다음과 같다.

 

1. MySQL APT Repository 추가

sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.13-1_all.deb

 

Repository 버전은 아래 MySQL 사이트 하단에 보이는 버전을 추가하였다.

 

https://dev.mysql.com/downloads/repo/apt/

 

 

2. MySQL APT Repository 패키지 다운로드

sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb

 

위의 명령어를 입력하면 아래와 같은 창이 뜨는데 OK를 선택하면 된다.

 

 

3. MySQL Repository 업데이트

sudo apt-get update

 

4. MySQL 8.0 Server 설치

sudo apt-get install mysql-server

 

위의 명령어를 입력하면 아래와 같이 창이 뜨는데 root 계정에서 사용할 비밀번호를 입력해주면 된다.

 

한 번 더 입력해준다.

그리고 아래와 같은 창이 뜰텐데 Use Strong Password Encrypthon을 선택한다.

 

 

5. mysql_secure_installation 설정

mysql_secure_installation

 

보안과 관련된 설정을 하기 위해 위의 명령어를 입력하면 방금 전에 설정한 root 계정의 비밀번호를 입력하라고 나온다. 

 

root 계정의 비밀번호를 입력하고 나면  아래와 같이 몇 가지 보안과 관련된 설정을 하게 되는데 상황에 맞게 설정하면 된다.

 

참고로 나는 아래와 같이 설정하였다.


Securing the MySQL server deployment.

Enter password for user root: 

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: N
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

 

6. root 계정으로 MySQL에 로그인

mysql -u root -p

 

이로써 MySQL 설치가 완료되었다. 추가로 MySQL 서비스와 관련된 명령어는 아래와 같다.

 

MySQL 서비스 시작

sudo systemctl start mysql.service

MySQL 서비스 중지

sudo systemctl stop mysql.service

MySQL 서비스 재시작

sudo systemctl restart mysql.service

MySQL 서비스 상태 검사

sudo systemctl status mysql.service

 

+ Recent posts