맨날 검색하다가 작성.


압축

$ tar -zcf [.tar.gz] [...]


압축 해제

$ tar -zxf [.tar.gz]


옵션

-f: use archive file or device ARCHIVE

-c: create a new archive

-x: extract files from an archive

-z: filter the archive through gzip


-p: extract information about file permissions (default for superuser)

-t: list the contents of an archive

-v: verbosely list files processed

워낙 잘못된 방법이 소개된 글이 많아 고생을 하여 작성.

Raspberry PI Zero W, Jessie 기준이다.


TX, RX 핀은 구글에 검색하면 이미지가 많이 나오니 핀 배열을 참고하자.


검색을 해보면 텍스트 파일을 수정하거나 데몬을 끄고 켜는 등의 작업이 많은데 다 필요없다.


$ sudo raspi-config


Interfacing Options

-> Serial

-> Would you like a login shell to be accessible over serial? <No>

-> Would you like the serial port hardware to be enabled? <Yes>


이렇게만 해주면 boot 설정 변경 등을 알아서 해주며 재부팅이 필요할 경우 재부팅까지 묻는다.


이 후 /dev/ttyS0 파일스트림을 사용하면 된다. /dev/ttyAMA0 이 아님!


블루투스 데몬이나 시리얼 서비스 등등을 바꿔야한다는 글들이 많지만 다 필요없으니 참고.



Python 에서 시리얼 통신

아래 방법 중 하나로 serial 라이브러리 설치


sudo python -m pip install pyserai
sudo apt install python-serial (Python3 의 경우엔 python3-serial)



import serial
ser = serial.Serial('/dev/ttyS0', 9600, timeout=3)

ser.readline().strip().decode('utf-8')
ser.write(b'TEST\n')
ser.write('TEST\n'.encode('utf-8')


serial 변수 생성 이후 open 하고 싶다면,


ser = serial.Serial(timeout=3)
ser.port = '/dev/ttyS0'
while True:
	try:
		ser.open()
		if ser.is_open: break
		time.sleep(1)
	except: pass



참고

class serial.Serial:
	__init__(port=None, baudrate=9600, bytesize=EIGHTBITS, 
		parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=None, 
		xonxoff=False, rtscts=False, write_timeout=None, dsrdtr=False, 
		inter_byte_timeout=None, exclusive=None)


서버에서 

push "redirect-gateway def1 bypass-dhcp"

push "dhcp-option DNS 10.0.2.220"

이런류의 설정을 넣어두면, OpenVPN 으로 연결시 모든 트래픽이 VPN 을 통하게 된다.


이를 client 설정 파일에서 override 할 수 있는데, 여러 방법이 있지만 설정파일을 이용하는 방법을 기술.

다른 방법은 아래 참고 URL 로 들어가보자.


위 서버 설정에서의 첫번째 줄, push ~~ def1 ~~ 어쩌구 설정을 썼다면 client 설정 파일에 아래 라인들을 포함하면 된다.

route 0.0.0.0 192.0.0.0 net_gateway
route 64.0.0.0 192.0.0.0 net_gateway
route 128.0.0.0 192.0.0.0 net_gateway
route 192.0.0.0 192.0.0.0 net_gateway


만약 서버에서 def1 옵션을 사용하지 않았을 경우 아래 와 같은 방법으로.(뭐가 다른진 잘 모르겠다)

route 0.0.0.0 128.0.0.0 net_gateway
route 128.0.0.0 128.0.0.0 net_gateway



+

위 방법까지만 하면 VPN 대역만 라우팅될텐데, 나같이 내부망에 VPN 서버 파두고 쓰는 경우엔 추가로 라우팅 테이블을 수정해야 한다.

내가 사용하려는 내부망은 10.0.0.0/8 대역을 사용하고, DNS 설정도 필요하니 아래와 같이 설정을 추가

route 10.0.0.0 255.0.0.0
dhcp-option DNS 10.0.2.220


DNS 설정의 경우 VPN 클라이언트 옵션에서 "수동으로 설정한 네트워크 설정 변경"을 허용해주어야 한다.

이건 클라이언트마다 다르니 알아서 찾아서 켜주도록 하자.



참고

https://community.openvpn.net/openvpn/wiki/IgnoreRedirectGateway

https://serverfault.com/a/631048

+ Recent posts