mtp mount in gentoo

Gentoo 머신에 안드로이드 폰을 연결해서 사용할 일이 있었다. 그냥 될 줄 알고 케이블을 연결했는데 인식이 안되는 것이었다. 역시… 뭔가를 해주어야 했다.

Gentoo wiki 에서는 mtp mount 하는 방법을 세가지 소개하고 있다. 바로 mtpfs, go-mtpfs, kde 이다. 이중 나는 mtpfs 와 go-mtpfs 를 사용했다.

결론적으로 mtpfs 는 원활한 동작이 되지 않았다. Mount 까지는 성공한 듯 싶었으나, 실제 마운트된 디렉토리에서 파일들에 접근할 수가 없었다. go-mtpfs 의 경우 완벽하게 동작했다.

먼저 go 를 설지하자.

$ sudo emerge dev-lang/go

그리고 mtpfs 를 위한 추가 작업을 진행해주자.

pchero@localhost ~ $ mkdir go
pchero@localhost ~ $ export GOPATH=/home/pchero/go
pchero@localhost ~ $ go get github.com/hanwen/go-mtpfs

그리고 그룹을 추가해주고…

$ sudo gpasswd -a pchero plugdev

마운트할 디렉토리를 생성하고 휴대폰에 케이블을 연결한 뒤, 마운트를 해주자.

$ mkdir ~/Android$ ~/go/bin/go-mtfs ~/Android

언마운트를 할 때는 아래와 같이..

$ fusermount -u ~/Android/

출처: https://wiki.gentoo.org/wiki/MTP

How to make wifi ap in gentoo

집에서 사용하는 무선랜이 벽과 벽을 통과하면서 정작 내방에서는 거의 잡히지 않게 되었다.

그동안 유선으로만 쓰고 있었는데.. 이번에 새롭게 태블릿과 휴대폰을 구입하면서 너무나 불편하게 되었다.
그래서 젠투에 Wifi 공유기 설정을 하게 되었다.

AP 지원 모드 확인
먼저 현재 사용중인 무선랜 카드가 AP 모드를 지원하는지를 확인해야 한다.

$ sudo emerge iw
$ iw list
Wiphy phy0
	max # scan SSIDs: 4
	max scan IEs length: 2257 bytes
	RTS threshold: 2347
	Coverage class: 0 (up to 0m)
	Device supports RSN-IBSS.
	Supported Ciphers:
		* WEP40 (00-0f-ac:1)
		* WEP104 (00-0f-ac:5)
		* TKIP (00-0f-ac:2)
		* CCMP (00-0f-ac:4)
		* CMAC (00-0f-ac:6)
	Available Antennas: TX 0 RX 0
	Supported interface modes:
		 * IBSS
		 * managed
		 * AP
		 * AP/VLAN
		 * monitor
		 * mesh point
		 * P2P-client
		 * P2P-GO

위와 같이 iw list 명령어로 확인했을 때, Supported interface modes: 항목에 AP 항목이 표시가 되어야한다. 꼭 확인하도록 하자.

필요 패키지
다음의 패키지들을 설치해주자.

$ sudo emerge hostapd
$ sudo emerge dhcp

dhcp 설정

생성된(곧 생성할..) 무선 AP에 Client가 접속했을 때, 자동으로 사용가능한 IP 를 할당해주어야 한다. 그러기 위해서는 dhcp 설정이 필요하다. 이 예제에서는 임의로 10.10.0.0/24 대역의 IP 주소를 사용하기로 한다.

dhcp 설정을 위해서 다음의 내용을 /etc/dhcp/dhcpd.conf 파일에 입력한다.

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

hostapd 설정

hostapd 는 실제로 wifi ap를 생성해주는 유틸이다. /etc/hostapd/hostapd.conf 파일에 아래의 내용을 입력하도록 하자.

interface=wlan0
driver=nl80211
ssid=pchero_gentoo
hw_mode=g
channel=1
macaddr_acl=0
auth_algs=3

wpa=3
wpa_passphrase=yourpassword
wpa_psk_radius=0
wpa_key_mgmt=WPA-PSK WPA-EAP
wpa_pairwise=CCMP
wpa_ptk_rekey=600

간혹 설정 내용이 잘 안 맞아서 안되는 인증이 경우가 있다. 이런 경우, 어느 부분에서 문제가 생기는지 알기 어려울 수 있다. 때문에 처음에는 가급적 암호화 없는 Open 으로 설정한 뒤, 정상작동하는 것을 확인하고 하나씩 수정하는 것을 권한다. 아래 내용은 암호화를 하지 않은 Open 방식 설정 예제이다.

interface=wlan0
driver=nl80211
ssid=pchero_gentoo
hw_mode=g
channel=11

Ip masquerade

wifi ap 생성 후, 패킷을 포워딩해주어야 하기 때문에 masquerade 설정을 해야한다. 아래 명령은 root 로 su 한 다음에 진행해야 한다.

$ sudo su -
$ echo "1" > /proc/sys/net/ipv4/ip_forward
$ iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

NetworkManager

고생했던 부분이다….. 여기까지 진행하면서 문제가 없었는데, 이상하게 hostapd 를 시작하면 이상한 오류를 내면서 죽는 현상이 나타났다. 아래는 그 오류 내용이다.

pchero@localhost ~ $ sudo hostapd -dd /etc/hostapd/hostapd.conf
random: Trying to read entropy from /dev/random
Configuration file: /etc/hostapd/hostapd.conf
ctrl_interface_group=10 (from group name 'wheel')
nl80211: Could not add multicast membership for vendor events: -2 (No such file or directory)
rfkill: initial event: idx=0 type=1 op=0 soft=0 hard=0
nl80211: Supported cipher 00-0f-ac:1
nl80211: Supported cipher 00-0f-ac:5
nl80211: Supported cipher 00-0f-ac:2
nl80211: Supported cipher 00-0f-ac:4
nl80211: Supported cipher 00-0f-ac:6
nl80211: Using driver-based off-channel TX
nl80211: interface wlan0 in phy phy0
nl80211: Set mode ifindex 6 iftype 3 (AP)
nl80211: Setup AP(wlan0) - device_ap_sme=0 use_monitor=0
nl80211: Subscribe to mgmt frames with AP handle 0x1c6d390
nl80211: Register frame type=0xb0 nl_handle=0x1c6d390 match=
nl80211: Register frame type=0x0 nl_handle=0x1c6d390 match=
nl80211: Register frame type=0x20 nl_handle=0x1c6d390 match=
nl80211: Register frame type=0xa0 nl_handle=0x1c6d390 match=
nl80211: Register frame type=0xc0 nl_handle=0x1c6d390 match=
nl80211: Register frame type=0xd0 nl_handle=0x1c6d390 match=
nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress)
nl80211: Register frame match - hexdump(len=0): [NULL]
nl80211: Could not configure driver mode
nl80211: Remove monitor interface: refcount=0
nl80211: Remove beacon (ifindex=6)
netlink: Operstate: ifindex=6 linkmode=0 (kernel-control), operstate=6 (IF_OPER_UP)
nl80211: Set mode ifindex 6 iftype 2 (STATION)
nl80211: Teardown AP(wlan0) - device_ap_sme=0 use_monitor=0
nl80211 driver initialization failed.
hostapd_interface_deinit_free(0x1c6c990)
hostapd_interface_deinit_free: num_bss=1 conf->num_bss=1
hostapd_interface_deinit(0x1c6c990)
hostapd_bss_deinit: deinit bss wlan0
hostapd_cleanup(hapd=0x1c70370 (wlan0))
hostapd_free_hapd_data: Interface wlan0 wasn't started
hostapd_interface_deinit_free: driver=(nil) drv_priv=(nil) -> hapd_deinit
hostapd_interface_free(0x1c6c990)
hostapd_interface_free: free hapd 0x1c70370
hostapd_cleanup_iface(0x1c6c990)
hostapd_cleanup_iface_partial(0x1c6c990)
hostapd_cleanup_iface: free iface=0x1c6c990

결론은 NetworkManager 때문이었다. hostapd 와 NetworkManager 는 같이 실행시킬 수 없다. 즉, hostapd 를 실행시키기 위해서는 NetworkManager 를 종료 시켜야 한다.

sudo /etc/init.d/NetworkManager stop

Set wlan0

이제 wlan0 의 IP 를 설정해주자. 기본적으로 dhcpd.conf 의 설정 내용과 맞춰야 하므로 10.10.0.1 로 설정하도록 하자.

ifconfig wlan0 10.10.0.1 netmask 255.255.255.0

Start hostapd

다 끝났다. dhcp 와 hostapd 를 시작하도록 하자. dhcp 시작시, wlan0 에 대해서만 dhcp 서비스를 하도록 명시해 주어야 한다. 주의하자.
만약 interface를 명시하지 않을 경우, eth0 까지도 dhcp 서비스를 하려고 한다. 그렇게 되면 eth0에 설정되어 있는 IP 정보가 날아가게 되고, 결론적으로는 AP 로써 정상작동하지 않게 된다.

# dhcp
$ sudo dhcpd -cf /etc/dhcp/dhcpd.conf wlan0 start

# hostapd
$ sudo hostapd -dd /etc/hostapd/hostapd.conf

Miscellaneous

매번 ap 를 구동하기 위해 위의 명령어를 입력할 수는 없다. 간단히 스크립트를 만들도록 하자.

#!/bin/bash

# stop Network Manager
#service NetworkManager stop
/etc/init.d/NetworkManager stop

# Set wlan0 IP
ifconfig wlan0 10.10.0.1 netmask 255.255.255.0

# Ip forwarding
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# dhcp
dhcpd -cf /etc/dhcp/dhcpd.conf wlan0 start

# hostapd
hostapd -B /etc/hostapd/hostapd.conf

참고
http://exain.wordpress.com/2011/03/31/making-a-wifi-hotspot-access-point-using-linux-wifi-lan-cardusb-adapter
http://www.sentabi.com/how-to-fix-hostapd-nl80211driver-initialization

 

Manual printer installing in linux

리눅스 사용시 간혹 수동으로 printer 설치를 해야할 경우가 있다. 이럴 경우, 다음의 순서대로 진행하면 된다.

파폭 창을 열고 localhost:631 에 접속한다.

Administration > Printers > Add Printer

이후, 설치하고자 하는 프린터의 이름과 프린터 드라이버를 지정해주면 끝!

 

Show wireshark interface lists in Ubuntu

ubuntu 에서 wireshark 설치시, 실제로 패킷 캡처를 하기 위해서 interface 리스트 목록을 확인할 때, interface 목록이 안나타나는 경우가 있다.
이는 wireshark 를 실행하는 유저의 권한 때문에 발생하는 문제이다.

간단하게 터미널에 $ sudo wireshark 를 입력하면 되지만 뭔가 깔끔하지 못하다…
이럴 경우, 터미널에 다음의 명령어를 입력하면 깔끔하게 wirewhark 를 실행할 수 있다.

$ sudo apt-get install wireshark
$ sudo dpkg-reconfigure wireshark-common 
$ sudo usermod -a -G wireshark $USER
$ sudo rebot

출처 : http://ask.wireshark.org/questions/7523/ubuntu-machine-no-interfaces-listed